Unable to create a contact
Spudley opened this issue · 1 comments
Hi.
I am trying to use the PHP Hubspot library to create companies and contacts. Creating a company works well. However I have been unable to create a contact.
Every call I have made to the create a contact has failed, returning the following message:
Client error: `POST https://api.hubapi.com/contacts/v1/contact?hapikey=***` resulted in a `400 Bad Request` response:
{"status":"error","message":"property cannot be missing or null","correlationId":"1fec847f-abfb-4583-97a9-302921c4af8d"}
I have been unable to establish what field it is complaining about; I have tried passing it the properties described in the documentation, and every combination from there that I could think of.
Here is a var_dump of of an array that is throwing the error:
array (size=1)
'properties' =>
array (size=10)
0 =>
array (size=2)
'name' => string 'company' (length=7)
'value' => string 'Chief' (length=5)
1 =>
array (size=2)
'name' => string 'firstname' (length=9)
'value' => string 'Bobby' (length=5)
2 =>
array (size=2)
'name' => string 'lastname' (length=8)
'value' => string 'Tables' (length=6)
3 =>
array (size=2)
'name' => string 'email' (length=5)
'value' => string 'bobby.tables@example.com' (length=24)
4 =>
array (size=2)
'name' => string 'phone' (length=5)
'value' => string '07777777777' (length=11)
5 =>
array (size=2)
'name' => string 'website' (length=7)
'value' => string 'example.com' (length=11)
6 =>
array (size=2)
'name' => string 'address' (length=7)
'value' => string 'xyz' (length=3)
7 =>
array (size=2)
'name' => string 'city' (length=4)
'value' => string 'abc' (length=3)
8 =>
array (size=2)
'name' => string 'state' (length=5)
'value' => string 'foo' (length=3)
9 =>
array (size=2)
'name' => string 'zip' (length=3)
'value' => string '123' (length=3)
Can you help explain what I'm doing wrong here?
Thank you.
Don't worry -- I solved it!
The contacts API is a V1 API call, so need properties in array format {"property":"firstname","value":"Smith"}
rather than {"name":"firstname","value":"Smith"}
which is how V2 API expects them. The companies API is V2 and contacts is V1, hence my confusion.