APIs & Integrations

JClouston
Member

API 201 success but values are empty?

I am making the following POST request to create a contact.

 

curl --request POST \
--url 'https://api.hubapi.com/crm/v3/objects/contacts?hapikey=0e3cdaba-da61-46b3-8783-19782cbbc9f9' \
--header 'content-type: application/json' \
--data '{
"properties": {
"company": "Productbox",
"email": "josh@productbox.com.au",
"firstname": "Josh",
"lastname": "Clouston",
"phone": "(877) 929-0687",
"website": "www.productbox.com.au"
}
}'

 

The logs show a 201 success message but there are no values captured.

 

Values not stored.png

 

As a result, there is a contact created with no values attached.

 

empty contact.png

 

Is anyone able please help troubleshoot this? I've exhausted my options.

 

Kind regards,

Josh

2 Replies 2
webdew
Guide | Diamond Partner
Guide | Diamond Partner

API 201 success but values are empty?

Hi @JClouston ,

Please try with below code:
˂?php
$arr = array(
'properties' => array(
array(
'property' => 'email',
'value' => 'josh@productbox.com.au'
),
array(
'property' => 'firstname',
'value' => 'Josh'
),
array(
'property' => 'lastname',
'value' => 'Clouston'
),
array(
'property' => 'phone',
'value' => '8779290687'
)
)
);
$post_json = json_encode($arr);
$hapikey = "demo";
$endpoint = 'https://api.hubapi.com/contacts/v1/contact?hapikey=' . $hapikey;
$ch = @curl_init();
@curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $post_json);
@curl_setopt($ch, CURLOPT_URL, $endpoint);
@curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = @curl_exec($ch);
$status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_errors = curl_error($ch);
@curl_close($ch);
echo "curl Errors: " . $curl_errors;
echo "\nStatus code: " . $status_code;
echo "\nResponse: " . $response;
?>


Hope this helps!


If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards.

0 Upvotes
miljkovicmisa
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

API 201 success but values are empty?

Hello @JClouston , when I work with API's I use a tool for testing called Postman, now, there are lots of other tools out there but I definatelly recommend this one, there is a free tier with an app that you can install, and it is great for debugging/testing API's.

So I would go about it this way, get the app and do some testing over there. You can also export from Postman the code in any language you want once your API call is okay.
More info about Postman here in this link.

 

If my answer was helpful please mark it as a solution.