City, State, Zip not added on create contact API

contacts

#1

City, State, Zip not added on create contact API. The code I am using is below, am I doing something wrong?

$email = 'thomas@cummings.com';
$firstname = "Thomas";
$lastname = "Test";
$address = "123 Test Ave";
$city = "Abq";
$state = "NM";
$zip = "87112";
$phone = "505-203-0822";




create_contact($email, $firstname, $lastname, $address, $city, $state, $zip, $phone, $HubAPIkey);



/****************** Function ***************************************/


function create_contact($email, $firstname, $lastname, $address, $city, $state, $zip, $phone, $HubAPIkey){

$cURL = "https://api.hubapi.com/contacts/v1/contact/?hapikey=$HubAPIkey";

	
	$post_hub = array(
				   	'properties' => array(    
				   		array( 'property' => 'email', 'value' => $email),
				   		array( 'property' => 'firstname', 'value' => $firstname),
				   		array( 'property' => 'lastname', 'value' => $lastname),
				   		array( 'property' => 'phone', 'value' => $phone),
				   		array( 'property' => 'address', 'value' => $address),
				   		array( 'property' => 'city', 'value' => $city),
				   		array( 'property' => 'state', 'value' => $state),
				   		array( 'property' => 'zip', 'value' => $zip)
				   ));


$data_string = json_encode($post_hub);                                                                               
	
	$ch = curl_init();                                                                  
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 
	curl_setopt($ch, CURLOPT_URL, trim($cURL));                                                                                                                                       
	curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	
	//execute post
	$response = curl_exec($ch);
	$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //gets back the code for failure or success
	$curl_errors = curl_error($ch);
	
	//close connection
	curl_close($ch);
	
	// echo out info from curl
	echo "<br>Status code: " . $status_code;
	echo "<br><br>curl Errors: " . $curl_errors;
    echo "<br><br><br>Response: " . $response;
} // end function associate deal

#2

@tcummings What is the response you are getting from HubSpot when you make the POST call?


#3

I get a 200 and the contact is created, but the add, city, state, and zip are not populated


#4

@tcummings if you log the full response you should be able to see the JSON formatted data you are sending over to HubSpot. I was hoping to see what data was actually being sent over and how it was formatted in the end result within the network request. Do you mind pasting that here?


#5

Status code: 200

curl Errors:

Response: {“vid”:4315251,“canonical-vid”:4315251,“merged-vids”:[],“portal-id”:3268782,“is-contact”:true,“profile-token”:“AO_T-mPXFeN-_dimV5eCwyA0fOGAkbSffnHE3Uggl8l6enAmOLEhrqOnd38NADn-iDiFRSgK5-fJDZyzVA9_Ub1IAQDqIlCWvx7x5h_MkMOXHH-_6gp1aXl-8qn33PNkiKMhH2R7sAoH”,“profile-url”:“https://app.hubspot.com/contacts/3268782/lists/public/contact/_AO_T-mPXFeN-_dimV5eCwyA0fOGAkbSffnHE3Uggl8l6enAmOLEhrqOnd38NADn-iDiFRSgK5-fJDZyzVA9_Ub1IAQDqIlCWvx7x5h_MkMOXHH-_6gp1aXl-8qn33PNkiKMhH2R7sAoH/",“properties”:{“zip”:{“value”:“87112”,“versions”:[{“value”:“87112”,“source-type”:“API”,“source-id”:null,“source-label”:null,“timestamp”:1498506922423,“selected”:false}]},“firstname”:{“value”:“Thomas”,“versions”:[{“value”:“Thomas”,“source-type”:“API”,“source-id”:null,“source-label”:null,“timestamp”:1498506922423,“selected”:false}]},“address”:{“value”:"123 Test Ave”,“versions”:[{“value”:“123 Test Ave”,“source-type”:“API”,“source-id”:null,“source-label”:null,“timestamp”:1498506922423,“selected”:false}]},“city”:{“value”:“Abq”,“versions”:[{“value”:“Abq”,“source-type”:“API”,“source-id”:null,“source-label”:null,“timestamp”:1498506922423,“selected”:false}]},“phone”:{“value”:“505-203-0822”,“versions”:[{“value”:“505-203-0822”,“source-type”:“API”,“source-id”:null,“source-label”:null,“timestamp”:1498506922423,“selected”:false}]},“createdate”:{“value”:“1498506922424”,“versions”:[{“value”:“1498506922424”,“source-type”:“API”,“source-id”:“Contacts”,“source-label”:null,“timestamp”:1498506922424,“selected”:false}]},“state”:{“value”:“NM”,“versions”:[{“value”:“NM”,“source-type”:“API”,“source-id”:null,“source-label”:null,“timestamp”:1498506922423,“selected”:false}]},“email”:{“value”:“thomas@cummings.com”,“versions”:[{“value”:“thomas@cummings.com”,“source-type”:“API”,“source-id”:null,“source-label”:null,“timestamp”:1498506922423,“selected”:false}]},“lastname”:{“value”:“Test”,“versions”:[{“value”:“Test”,“source-type”:“API”,“source-id”:null,“source-label”:null,“timestamp”:1498506922423,“selected”:false}]}},“form-submissions”:[],“list-memberships”:[],“identity-profiles”:[{“vid”:4315251,“is-deleted”:false,“is-contact”:false,“pointer-vid”:0,“previous-vid”:0,“linked-vids”:[],“saved-at-timestamp”:0,“deleted-changed-timestamp”:0,“identities”:[{“type”:“EMAIL”,“value”:“thomas@cummings.com”,“timestamp”:1498506922424,“source”:“UNSPECIFIED”},{“type”:“LEAD_GUID”,“value”:“8e4b1669-2790-4d04-a00f-e7a771e2ffe9”,“timestamp”:1498506922429,“source”:“UNSPECIFIED”}]}],“merge-audits”:[]}

Thomas Cummings
Web Applications Developer
505. 881.3321office
505.203.0822 mobile
[/uploads/default/original/2X/c/ccac08b6aaa87fdd0bf2bfbb97f153343d14f779.png]
FaithComesByHearing.comhttp://www.faithcomesbyhearing.com/


#6

@tcummings Can you message me an example contact? I don’t see any issues with the response.


#7

@tcummings Are you overwriting it in your code somewhere? Are you making two API calls in a row?

It looks like you set it and then wipe it out within the same minute.


#8

No, I only call the method once and I am not unsetting any vars:

<?php


                // Create HubSpot Contact
                // Auth: Thomas Cummings
                // Date: June 26, 2017

                // Returns a 200 response on success
                // Returns a 409 Conflict if there is an existing contact with the email address included in the request

                // API key and connection string
                $HubAPIkey = "XXXXXXXXXXX";

                $email = 'thomas@cummings.com';
                $firstname = "Thomas";
                $lastname = "Test";
                $address = "123 Test Ave";
                $city = "Abq";
                $state = "NM";
                $zip = "87112";
                $phone = "505-203-0822";




                create_contact($email, $firstname, $lastname, $address, $city, $state, $zip, $phone, $HubAPIkey);



/****************** Function ***************************************/


function create_contact($email, $firstname, $lastname, $address, $city, $state, $zip, $phone, $HubAPIkey){

                $cURL = "https://api.hubapi.com/contacts/v1/contact/?hapikey=$HubAPIkey";


                                $post_hub = array(
                                                                                                'properties' => array(
                                                                                                                array( 'property' => 'email', 'value' => $email),
                                                                                                                array( 'property' => 'firstname', 'value' => $firstname),
                                                                                                                array( 'property' => 'lastname', 'value' => $lastname),
                                                                                                                array( 'property' => 'phone', 'value' => $phone),
                                                                                                                array( 'property' => 'address', 'value' => $address),
                                                                                                                array( 'property' => 'city', 'value' => $city),
                                                                                                                array( 'property' => 'state', 'value' => $state),
                                                                                                                array( 'property' => 'zip', 'value' => $zip)
                                                                                   ));


                $data_string = json_encode($post_hub);

                                $ch = curl_init();
                                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
                                curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
                                curl_setopt($ch, CURLOPT_URL, trim($cURL));
                                curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

                                //execute post
                                $response = curl_exec($ch);
                                $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //gets back the code for failure or success
                                $curl_errors = curl_error($ch);

                                //close connection
                                curl_close($ch);

                                // echo out info from curl
                                echo "<br>Status code: " . $status_code;
                                echo "<br><br>curl Errors: " . $curl_errors;
        echo "<br><br><br>Response: " . $response;
} // end function associate deal


?>

Thomas Cummings
Web Applications Developer
505. 881.3321office
505.203.0822 mobile
[/uploads/default/original/2X/c/ccac08b6aaa87fdd0bf2bfbb97f153343d14f779.png]
FaithComesByHearing.comhttp://www.faithcomesbyhearing.com/


#9

@tcummings I agree it doesn’t appear that you are calling it twice within the code snippet that you shared above. I am a little lost as to where the second API call is coming from then. Someone is making a call to the Contacts API at the same time that is overwriting those values for your calls. You don’t have any additional services that are running after a contact gets updated/created?


#10

I had same trouble. I fixed! Thanks for responses! :wink: