Nov 18, 2022 5:58 AM
Trying to create a contact with php, using the example code from the hubspot docs but getting the following error -
string(269) "{"status":"error","message":"Invalid input JSON on line 1, column 15: Cannot deserialize value of type `java.util.LinkedHashMap<java.lang.string,java.lang.string>` from Array value (token `JsonToken.START_ARRAY`)","correlationId":"f8d785e4-68c0-4860-b1e6-4ff977c053c1"}"</java.lang.string,java.lang.string>
Here is my code:
$arr = array(
'properties' => array(
array(
'property' => 'email',
'value' => 'apitest@hubspot.com'
)
)
);
$post_json = json_encode($arr);
$accesstoken = "*********************************";
$headers = [
'Content-Type: application/json',
'Authorization: Bearer ' . $accesstoken,
];
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_json);
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);
var_dump($contacts);
Any ideas?
Gelöst! Gehe zu Lösung.
Nov 20, 2022 11:45 PM
I understand this better now ... skimura was on the right track.
If you look at the v3 documentation, you'll see the JSON is different than it was in v1.
You need to modify the code used to generate $arr. It no longer has property & value.
Nov 21, 2022 4:17 AM
Thanks for this. Changing the array structure sorted it. This is what I used in case it helps others.
$arr = array(
'properties' => array(
'company' => 'Biglytics',
'email' => 'bcooper@biglytics.net',
'firstname' => 'Bryan',
'lastname' => 'Cooper',
'phone' => '(877) 929-0687',
'website' => 'biglytics.net'
)
);
$post_json = json_encode($arr);
Nov 20, 2022 8:14 PM
I am having the same problem. My code is nearly identical. I did try with more values in the array though.
(company, email, firstname, lastname, phone, message)
This is code that I'm attempting to migrate from the old API to the newer API (v3) with a private app.
The status code which is returned is: 400
The response is: {"status":"error","message":"Invalid input JSON on line 1, column 15:
Cannot deserialize value of type `java.util.LinkedHashMap<java.lang.String,java.lang.String>`
from Array value (token `JsonToken.START_ARRAY`)",
"correlationId":"32d18bc4-8bdd-41ca-b296-189f768835df"}
I've tried different things, and read through the documentation. I still cannot get this to work. Any guidance is really appreciated!
Nov 20, 2022 11:45 PM
I understand this better now ... skimura was on the right track.
If you look at the v3 documentation, you'll see the JSON is different than it was in v1.
You need to modify the code used to generate $arr. It no longer has property & value.
Nov 21, 2022 4:17 AM
Thanks for this. Changing the array structure sorted it. This is what I used in case it helps others.
$arr = array(
'properties' => array(
'company' => 'Biglytics',
'email' => 'bcooper@biglytics.net',
'firstname' => 'Bryan',
'lastname' => 'Cooper',
'phone' => '(877) 929-0687',
'website' => 'biglytics.net'
)
);
$post_json = json_encode($arr);
Nov 19, 2022 7:04 AM
Hi.
Input parameter format might be wrong.
How about this?
$arr = array(
'properties' => array(
'email' => 'apitest@hubspot.com'
)
);
Thanks.