APIs & Integrations

LSeall
Membre

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

Résolue

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 Votes
2 Solutions acceptées
EDash
Solution
Participant

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

Résolue

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.

Voir la solution dans l'envoi d'origine

LSeall
Solution
Membre

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

Résolue

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

Voir la solution dans l'envoi d'origine

5 Réponses
EDash
Participant

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

Résolue

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 Votes
EDash
Solution
Participant

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

Résolue

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
Membre

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

Résolue

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 Votes
LSeall
Solution
Membre

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

Résolue

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
Contributeur | Partenaire solutions Platinum
Contributeur | Partenaire solutions Platinum

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

Résolue

@LSeall 

 

Hi.

 

Input parameter format might be wrong.

How about this?

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

 

Thanks.