Please Help me to solve myproblem



I am trying to build it in Php. So far my code based only on what I learn through self-studying.
Please correct me if my code will work and please give me for the code that I am stacked.

When someone registers the webhook will trigger:

Inside the webhook, I put Oath code:
//The username and password must match what you enter in your HubSpot workflow webhook
$webhookUsername = “my_username”;
$webhookPassword = “**************”;

$hubspotApiKey = “myhapikey”;

if ($_SERVER[‘PHP_AUTH_USER’] != $webhookUsername || $_SERVER[‘PHP_AUTH_PW’] != $webhookPassword || $_SERVER[‘REQUEST_METHOD’] != ‘POST’){
Getting the details of registered:

$array = json_decode($json, true);

$contactId = $array[‘vid’];
//set the company id if it exists
if($array[‘properties’][‘email’][‘value’] != null){
$emailId = $array[‘properties’][‘email’][‘value’];
$emailId = null;
Getting the contact email which I will use for update

$url_owners = “$hubspotApiKey”;
Stacked: Because it gives only my owner details and not all the owners.

  1. Getting all owners and update all the owner’s details in our database.
  2. Running the function where our “own rules” of assigning leads of each owner.

$taskPostDataArray = array(
“properties” => array(

$taskPostDataJson = json_encode($taskPostDataArray);

$url = “$emailId/?hapikey=$hubspotApiKey”;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $taskPostDataJson);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type: application/json’));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
Stacked: trying to update the contact properties hubspot_owner_id to assign the lead to the proper agent.

Please correct my codes and answer some stacked process.


Hi @Paul_Rivera,

Are you using the hapikey from your Marketing/CRM portal? It sounds like you may have been using the hapikey from your developer portal. Using the correct API key should allow you pull the owners and update contacts successfully.


I found it!
btw, I want to get the current registered data before the webhook triggered.
Is this the correct code for it?

I want to know also where can I see the fetch data while doing some testing or troubleshooting.


Hi @Paul_Rivera,

I’m not proficient in PHP, so I’m not the best resource for troubleshooting your code directly. I’d be happy to help with any HubSpot API issues/questions, but for troubleshooting code you’d be better served elsewhere. I can say that $HTTP_RAW_POST_DATA has been deprecated as of PHP 5.6.0, so you should try php://input instead: