APIs & Integrations

LSeall
Mitglied

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

lösung

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 Upvotes
2 Akzeptierte Lösungen
EDash
Lösung
Teilnehmer/-in

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

lösung

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.

Lösung in ursprünglichem Beitrag anzeigen

LSeall
Lösung
Mitglied

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

lösung

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

Lösung in ursprünglichem Beitrag anzeigen

5 Antworten
EDash
Teilnehmer/-in

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

lösung

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 Upvotes
EDash
Lösung
Teilnehmer/-in

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

lösung

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
Mitglied

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

lösung

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 Upvotes
LSeall
Lösung
Mitglied

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

lösung

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
Mitwirkender/Mitwirkende | Platinum Partner
Mitwirkender/Mitwirkende | Platinum Partner

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

lösung

@LSeall 

 

Hi.

 

Input parameter format might be wrong.

How about this?

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

 

Thanks.