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?
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.