Hi,
We are migrating to a private app.
Hi, I’m trying to add a new user directly to a list using php. If I just try to create a contact within hubspot
I have a problem, the contact will be not created.
this is my code:
$arr = array(
‘properties’ => array(
array(
‘property’ => ‘email’,
‘value’ => $email
),
array(
‘property’ => ‘firstname’,
‘value’ => $vorname
),
array(
‘property’ => ‘lastname’,
‘value’ => $nachname
),
array(
‘property’ => ‘newsletter’,
‘value’ => $newsletter
)
)
);
$post_json = json_encode($arr);
$bkey = “pat-na1-xxxxxx”;
$headers = [
‘Content-Type: application/json’,
'Authorization: Bearer ’ . $bkey,
];
$curl = curl_init();
@curl_setopt($curl, CURLOPT_POSTFIELDS, $post_json);
@curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
@curl_setopt($curl, CURLOPT_URL, ‘https://api.hubapi.com/crm/v3/objects/contacts’);
@curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$contacts = curl_exec($curl);
curl_close($curl);
Can you help me, please? Thanks
@DvonLemberg
Hi.
How about try this?
..
$arr = array(
'properties' => array(
'email' => $email,
'firstname' => $vorname,
'lastname' => $nachname,
'newsletter' => $newsletter,
)
);
...
Please check api reference.
Thanks.
I try
$arr = array(
‘properties’ => array(
‘email’ => $email,
‘firstname’ => $vorname,
‘lastname’ => $nachname
)
);
I don’t know what is wrong with my code. This is very frustrating. Can anyone recommend something?
@DvonLemberg
This format is for legacy APIs.
$arr = array(
'properties' => array(
array(
'property' => 'email',
'value' => 'XXX'
),
),
...
);
https://legacydocs.hubspot.com/docs/methods/contacts/create_contact
Your code uses hubspot API v3. (‘https://api.hubapi.com/crm/**v3**/objects/contacts’)
v3 APIs format is like this.
$arr = array(
'properties' => array(
'email' => 'XXX'
...
)
);
Please check v3 APIs reference.
Hi,
thank you for the replay. I use v3 APIs and formats like this.
$arr = array(
'properties' => array(
'email' => 'XXX'
...
)
);
but the contact will be not created
@DvonLemberg
Can you post the response code and response message?
Thanks.
In my case this works.
$arr = [
'properties' => [
'email' => 'XXXX',
'firstname' => 'test',
'lastname' => 'test',
]
];
$post_json = json_encode($arr);
$bkey = "XXXX";
$headers = [
'Content-Type: application/json',
'Authorization: Bearer ' . $bkey
];
$curl = curl_init();
@curl_setopt($curl, CURLOPT_POSTFIELDS, $post_json);
@curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
@curl_setopt($curl, CURLOPT_URL, 'https://api.hubapi.com/crm/v3/objects/contacts');
@curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status_code == 200) {
$response_json = json_decode($response, true);
print_r($response_json);
} else {
print_r(json_decode($response, true));
echo "Request failed with status code: " . $status_code;
}
Hi, response code:
curl Errors: Status code: Response: {“status”:“error”,“message”:“Contact already exists. Existing ID: 35401”,“correlationId”:“ce92ca80-99e4-473d-96dd-aa6f93d4b5f8”,“category”:“CONFLICT”}“0 results”
@DvonLemberg
>Contact already exists
Is the contact already exists?
Please try another ‘email’.
Or delete exists contact.
The contact doesn’t exists. I try another email:
curl Errors: Status code: Response: {“status”:“error”,“message”:“Contact already exists. Existing ID: 35401”,“correlationId”:“2132dbc9-ef03-4d6f-bd5e-15e01ee9f0b2”,“category”:“CONFLICT”}“0 results”
@DvonLemberg
It may just be that you don’t see it in your contact list.
Since the ID is known, can’t it be displayed directly from the URL?
URL like this.
https://app.hubspot.com/contacts/{YOU_PORTAL}/contact/35401
Thank you, the issue is solved 
I check the link and I use the correct api.
“To create new contacts, make a POST request to /crm/v3/objects/contacts”
When creating a new contact, you should include at least one of the following properties in your request: email, firstname, or lastname."
I use
$arr = array(
‘properties’ => array(
‘email’ => $email,
‘firstname’ => $vorname,
‘lastname’ => $nachname
)
);
The contact is not created.
I am not able to find the error