APIs & Integrations

ax0nic
Member

Associating a ticket with a contact - NodeJS

SOLVE

Hello, 

I have a simple endpoint that receives form data from our website, then creates a contact if needed, creates a ticket, then tries to assign the contact to the ticket.... but I am getting an errror. Can anyone point me in the right direction please?

 

reference: https://developers.hubspot.com/docs/api/crm/tickets

 

code:

try {
  const ticketId = createTicketResponse.id
  const toObjectType = 'contact'
  const toObjectId = contactId
  const associationType = 'contact_to_ticket'
  associateTicketResponse =
    await hubspotClient.crm.tickets.associationsApi.create(
      ticketId,
      toObjectType,
      toObjectId,
      associationType
    )
} catch (e) {
  console.log(e)
  res.status(e.status || 400).json(e.body)
}

 

and my error:



ApiException [Error]: HTTP-Code: 500
Message: An error occurred.
Body: {"status":"error","message":"internal error","correlationId":"64cf4990-2916-46e6-80ab-70d47e5b5126"}
Headers: {"access-control-allow-credentials":"false","alt-svc":"h3=\":443\"; ma=86400, h3-29=\":443\"; ma=86400","cf-cache-status":"DYNAMIC","cf-ray":"771883805ab7e6fe-DFW","connection":"close","content-length":"100","content-type":"application/json;charset=utf-8","date":"Tue, 29 Nov 2022 04:13:57 GMT","nel":"{\"success_fraction\":0.01,\"report_to\":\"cf-nel\",\"max_age\":604800}","report-to":"{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=%2FFHGVRdi4G9OVV9vnhVKCt3hT9iEnDLcZ0DLPRc8beqIJkIALNY24xqDRbbiF4%2FfJ4%2FoLhqhAwTJSJhXwCbyba7zMxkvUz5WW4dlR9Y8KkuGSKYKTRY5w1nqPHIZDtiS\"}],\"group\":\"cf-nel\",\"max_age\":604800}","server":"cloudflare","strict-transport-security":"max-age=31536000; includeSubDomains; preload","vary":"origin, Accept-Encoding","x-hubspot-correlation-id":"64cf4990-2916-46e6-80ab-70d47e5b5126","x-hubspot-ratelimit-daily":"250000","x-hubspot-ratelimit-daily-remaining":"249921","x-hubspot-ratelimit-interval-milliseconds":"10000","x-hubspot-ratelimit-max":"100","x-hubspot-ratelimit-remaining":"97","x-hubspot-ratelimit-secondly":"10","x-hubspot-ratelimit-secondly-remaining":"9","x-trace":"2B7E4C2907E15A8E8025F8DD7A49AF8EB9BC93A824000000000000000000"}
at AssociationsApiResponseProcessor.<anonymous> (/Users/ax0n/Code/asio-earth/node_modules/@hubspot/api-client/lib/codegen/crm/tickets/apis/AssociationsApi.js:163:23)
at Generator.next (<anonymous>)
at fulfilled (/Users/ax0n/Code/asio-earth/node_modules/@hubspot/api-client/lib/codegen/crm/tickets/apis/AssociationsApi.js:5:58)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 500,
body: {
status: 'error',
message: 'internal error',
correlationId: '64cf4990-2916-46e6-80ab-70d47e5b5126'
},
headers: {
'access-control-allow-credentials': 'false',
'alt-svc': 'h3=":443"; ma=86400, h3-29=":443"; ma=86400',
'cf-cache-status': 'DYNAMIC',
'cf-ray': '771883805ab7e6fe-DFW',
connection: 'close',
'content-length': '100',
'content-type': 'application/json;charset=utf-8',
date: 'Tue, 29 Nov 2022 04:13:57 GMT',
nel: '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}',
'report-to': '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=%2FFHGVRdi4G9OVV9vnhVKCt3hT9iEnDLcZ0DLPRc8beqIJkIALNY24xqDRbbiF4%2FfJ4%2FoLhqhAwTJSJhXwCbyba7zMxkvUz5WW4dlR9Y8KkuGSKYKTRY5w1nqPHIZDtiS"}],"group":"cf-nel","max_age":604800}',
server: 'cloudflare',
'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
vary: 'origin, Accept-Encoding',
'x-hubspot-correlation-id': '64cf4990-2916-46e6-80ab-70d47e5b5126',
'x-hubspot-ratelimit-daily': '250000',
'x-hubspot-ratelimit-daily-remaining': '249921',
'x-hubspot-ratelimit-interval-milliseconds': '10000',
'x-hubspot-ratelimit-max': '100',
'x-hubspot-ratelimit-remaining': '97',
'x-hubspot-ratelimit-secondly': '10',
'x-hubspot-ratelimit-secondly-remaining': '9',
'x-trace': '2B7E4C2907E15A8E8025F8DD7A49AF8EB9BC93A824000000000000000000'
}
}

 

0 Upvotes
1 Accepted solution
weiliang_lee
Solution
Top Contributor | Diamond Partner
Top Contributor | Diamond Partner

Associating a ticket with a contact - NodeJS

SOLVE

Hi there,

 

Seems like there is something wrong with their API client. I tried it on their endpoint explorer and it didn't work as well.

 

Try this in Postman, it will work:

{{baseUrl}}/crm/v3/objects/contacts/:contactId/associations/:toObjectType/:toObjectId/:associationType

 

In order for you to invoke the url, use this function:

const apiResponseAssociations = await hubspotClient.apiRequest({
      method: 'PUT',
      path: 'crm/v3/objects/contacts/:contactId/associations/:toObjectType/:toObjectId/:associationType'
})

 

I'm using the Contact endpoint to associate a Ticket, but it will work bi-directionally. 

 

Cheers

WL

View solution in original post

0 Upvotes
3 Replies 3
weiliang_lee
Solution
Top Contributor | Diamond Partner
Top Contributor | Diamond Partner

Associating a ticket with a contact - NodeJS

SOLVE

Hi there,

 

Seems like there is something wrong with their API client. I tried it on their endpoint explorer and it didn't work as well.

 

Try this in Postman, it will work:

{{baseUrl}}/crm/v3/objects/contacts/:contactId/associations/:toObjectType/:toObjectId/:associationType

 

In order for you to invoke the url, use this function:

const apiResponseAssociations = await hubspotClient.apiRequest({
      method: 'PUT',
      path: 'crm/v3/objects/contacts/:contactId/associations/:toObjectType/:toObjectId/:associationType'
})

 

I'm using the Contact endpoint to associate a Ticket, but it will work bi-directionally. 

 

Cheers

WL

0 Upvotes
ax0nic
Member

Associating a ticket with a contact - NodeJS

SOLVE

Thank you @weiliang_lee - I was able to get this to work, but I had to make a slight change to the request 'PATH' object... here for reference...

 

apiResponseAssociations = await hubspotClient.apiRequest({
method: 'PUT',
path: `/crm/v3/objects/contacts/${contactId}/associations/ticket/${ticketId}/contact_to_ticket`
})

Specifically the leading `/` and then just updating the pieces that need to be dynamic with a template string.

 

💪

weiliang_lee
Top Contributor | Diamond Partner
Top Contributor | Diamond Partner

Associating a ticket with a contact - NodeJS

SOLVE

Ahh thanks for the correction! Great to hear that it is working for you now!

0 Upvotes