Re: Invalid input JSON - Cannot deserialize value of type `java.util.LinkedHashMap`

LSeall
メンバー

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?

0 いいね!
2件の承認済みベストアンサー
EDash
解決策
参加者

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.

元の投稿で解決策を見る

LSeall
解決策
メンバー

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);

元の投稿で解決策を見る

5件の返信 5
EDash
参加者

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!

 

 

 

0 いいね!
EDash
解決策
参加者

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.

johnbonds
メンバー

I believe that the v3 documentation is wrong. It states that updating a contact requires a properties object, not a properties array.

 

johnbonds_1-1693427706607.png

 

 

0 いいね!
LSeall
解決策
メンバー

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);

skimura
トップ投稿者 | Platinum Partner
トップ投稿者 | Platinum Partner

@LSeall 

 

Hi.

 

Input parameter format might be wrong.

How about this?

$arr = array(
  'properties' => array(
      'email' => 'apitest@hubspot.com'
   )
);

 

Thanks.