Unexpected error response

I have been working on an upload program in PHP /Codeigniter 4 and while testing a sequential program to add contacts and create an asociation with a ticket, I encountered the following error;

HubSpot\Client\Crm\Tickets\ApiException #400

[400] Client error: `PUT https://api.hubapi.com/crm/v3/objects/tickets/1332077223/associations/ticket/679951/ticket_to_contact` resulted in a `400 Bad Request` response: {"status":"error","message":"Error validating request.","correlationId":"56c70d80-2d3c-4776-b2af-693f9c00d7cc","errors": (truncated...) 

This occurred on the second iteration through the loop, and in an unchanged chunk of code that had been working all afternoon, until suddenly it did not.
Any thoughts on why this occurred? I cannot get more information from the program becasue unfortunately it crashed on this error.
Also, any thoughts on how to trap these sorts of things and log them without crashing the program?

Any help appreciated,

Dan Davis

Hi, @DDavis3 :waving_hand: Thanks for reaching out. Hey, @Micole @tominal, do you have any troubleshooting tips you can share with @DDavis3?

Best,

Jaycee

My program is

  • -creating a Ticket from data in a local database (successful);
  • -creating an association to an existing Deal based upon the return values from creating the ticket (also successful),
  • -storing the returned Deal ID from the API in my database (successful), creating a Contact (successful),
  • -storing the returned Contact ID in my database (successful)
  • -creating an association to the previously created Ticket for the created Contact and this is where it is failing.

Some additional information from the stack trace:

coming from “VENDORPATH/hubspot/api-client/codegen/Crm/Tickets/Api/AssociationsApi.php at line 453”

446 $request = $this->createRequest($ticket_id, $to_object_type, $to_object_id, $association_type);
447 
448 try {
449 $options = $this->createHttpClientOption();
450 try {
451 $response = $this->client->send($request, $options);
452 } catch (RequestException $e) {
453 throw new ApiException(
454 "[{$e->getCode()}] {$e->getMessage()}",
455 (int) $e->getCode(),
456 $e->getResponse() ? $e->getResponse()->getHeaders() : null,
457 $e->getResponse() ? (string) $e->getResponse()->getBody() : null
458 );
459 }

This is coming from "VENDORPATH/hubspot/api-client/codegen/Crm/Tickets/Api/AssociationsApi.php : 426 — HubSpot\Client\Crm\Tickets\Api\AssociationsApi->createWithHttpInfo ( arguments ) "

419 *
420 * @throws \HubSpot\Client\Crm\Tickets\ApiException on non-2xx response
421 * @throws \InvalidArgumentException
422 * @return \HubSpot\Client\Crm\Tickets\Model\SimplePublicObjectWithAssociations|\HubSpot\Client\Crm\Tickets\Model\Error
423 */
424 public function create($ticket_id, $to_object_type, $to_object_id, $association_type)
425 {
426 list($response) = $this->createWithHttpInfo($ticket_id, $to_object_type, $to_object_id, $association_type);
427 return $response;
428 }
429 
430 /**
431 * Operation createWithHttpInfo
432 *
433 * Associate a ticket with another object

Which is in turn being called from "APPPATH/Controllers/LoadController.php : 324 — HubSpot\Client\Crm\Tickets\Api\AssociationsApi->create ( arguments ) "

317 {
318 if($association['hs_ticket_id'] != '')
319 {
320 if($association['hs_contact_id'] != '')
321 {
322 try 
323 {
324 $apiResponse = json_decode($client->crm()->tickets()->associationsApi()->create($association['hs_ticket_id'], 'ticket', $association['hs_contact_id'], 'ticket_to_contact'), TRUE);
325 $msg .= "Ticket to Contact Association ".$association['hs_ticket_id']." and " .$association['hs_contact_id']. " has been Added";
326 
327 }
328 catch (\HubSpot\Client\Crm\Contacts\ApiException $e) 
329 {
330 // $msg .= "Exception when calling basic_api->create: ". $e->getMessage();
331 $msg .= "Ticket to Contact Association ". $hs_object_id. " Exception when calling basic_api->update: ". $e->getResponseBody();

The last bit being my code, I got my format from the API docs so I am not sure if there is a problem with the format at all.

We decided to go in another direction for this; so no longer an issue.

Thanks for taking a look at it anyway,

Dan Davis