Batch updating Deals throwing Json error (PHP)

Hi

Trying to use Guzzle with PHP to batch update Deals.

Payload example:

[{"id":12345678,"properties":{"dealname":"001122334455-1, Bob Smith, 0099887766"}},{"id":4657890,"properties":{"dealname":"00334455667-1, John Jones, 00665544332"}}]

PHP code we’re using:

 // API endpoint
 $apiEndpoint = "https://api.hubapi.com/crm/v3/objects/deals/batch/update";

 // Create a Guzzle client
 $client = new Client();

 // HubSpot API key and deal and contact IDs
 $apiKey = 'XXXX';
 $data = $deal_properties;

 // Make a POST request to associate the deal with the contact
 $response = $client->post($apiEndpoint, [
 'headers' => [
 'Authorization' => "Bearer {$apiKey}",
 'Content-Type' => 'application/json',
 ],
 'json' => $data
 ]);

Error received:

{"status":"error","message":"Invalid input JSON on line 1, column 1: Cannot construct instance of com.hubspot.apiutils.core.models.batch.BatchInput$Json (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('[{\"id\":12345678,\"properties\":{\"dealname\":\"001122334455-1, Bob Smith, 0099887766\"}},{\"id\":4657890,\"properties\":{\"dealname\":\"00334455667-1, John Jones, 00665544332\"}}

Any clues? Am I missing something simple?

Thanks

Hey, @MBridgeman :waving_hand:

I have a few questions:

  • Have you used something like JSONLint? To make sure there aren’t any sneaky white spaces or other formatting issues?
  • Have you tried logging the exact payload being sent to the API just before the request?
  • Have you tried using the batch endpoint but only sending a single deal? To simplify things?
  • Have you tried sending a simplified request using Postman?

Thanks for the additional information! — Jaycee

Thank you @Jaycee_Lewis! This got me pointed in the right direction. What helped the most for me was to compare the json in the request body in my request with the json found in the cURL sample on the documentation website. This helped me find where I was creating my request incorrectly.

Heck yes :raising_hands: Thanks for taking the time to let us know! — Jaycee