# Associating a ticket with a contact - NodeJS

**URL:** <https://community.hubspot.com/t/associating-a-ticket-with-a-contact-nodejs/70128>\
**Category:** APIs & Integrations\
**Tags:** contacts\
**Created:** [November 29, 2022, 4:22am UTC](https://community.hubspot.com/t/associating-a-ticket-with-a-contact-nodejs/70128 "2022-11-29T04:22:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ax0nic](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@ax0nic](https://community.hubspot.com/u/ax0nic)\
**Post date:** [November 29, 2022, 4:22am UTC](https://community.hubspot.com/t/associating-a-ticket-with-a-contact-nodejs/70128/1 "2022-11-29T04:22:33Z")

</div>

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: [Accounts Dashboard | HubSpot](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: 500Message: 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'}}`

---

<div class="post-metadata">

**Author:** ![weiliang\_lee](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/weiliang_lee/32/81774_2.png) [@weiliang\_lee](https://community.hubspot.com/u/weiliang_lee)\
**Post date:** [November 29, 2022, 10:07am UTC](https://community.hubspot.com/t/associating-a-ticket-with-a-contact-nodejs/70128/2 "2022-11-29T10:07:06Z")

</div>

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:

```lia-code-sample
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

---

<div class="post-metadata">

**Author:** ![ax0nic](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@ax0nic](https://community.hubspot.com/u/ax0nic)\
**Post date:** [November 29, 2022, 3:08pm UTC](https://community.hubspot.com/t/associating-a-ticket-with-a-contact-nodejs/70128/3 "2022-11-29T15:08:49Z")

</div>

Thank you [@weiliang\_lee](https://community.hubspot.com/t5/user/viewprofilepage/user-id/155264) - 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.

💪

---

<div class="post-metadata">

**Author:** ![weiliang\_lee](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/weiliang_lee/32/81774_2.png) [@weiliang\_lee](https://community.hubspot.com/u/weiliang_lee)\
**Post date:** [November 30, 2022, 3:56am UTC](https://community.hubspot.com/t/associating-a-ticket-with-a-contact-nodejs/70128/4 "2022-11-30T03:56:13Z")

</div>

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