# Associate Ticket to contact

**URL:** <https://community.hubspot.com/t/associate-ticket-to-contact/30002>\
**Category:** APIs & Integrations\
**Tags:** sdk\
**Created:** [January 11, 2021, 5:07pm UTC](https://community.hubspot.com/t/associate-ticket-to-contact/30002 "2021-01-11T17:07:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![TYona](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tyona/32/1529_2.png) [@TYona](https://community.hubspot.com/u/TYona)\
**Post date:** [January 11, 2021, 5:07pm UTC](https://community.hubspot.com/t/associate-ticket-to-contact/30002/1 "2021-01-11T17:07:28Z")

</div>

Hi

I am trying to associate between a ticket to a contact using the hubspot api - node.js but having trouble would apreciate for an example on how to do it.

Thanks!

---

<div class="post-metadata">

**Author:** ![quentin\_lamamy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/quentin_lamamy/32/20212_2.png) [@quentin\_lamamy](https://community.hubspot.com/u/quentin_lamamy)\
**Post date:** [January 12, 2021, 7:51am UTC](https://community.hubspot.com/t/associate-ticket-to-contact/30002/2 "2021-01-12T07:51:09Z")

</div>

Hi @TYona

- Can you post your code (inside a code bloc, the \</\> icon in the formatting toolbar) so that i can help you.  
- What’s is your issue ? An error messsage as api response ? If yes which one

---

<div class="post-metadata">

**Author:** ![TYona](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tyona/32/1529_2.png) [@TYona](https://community.hubspot.com/u/TYona)\
**Post date:** [January 12, 2021, 9:05am UTC](https://community.hubspot.com/t/associate-ticket-to-contact/30002/3 "2021-01-12T09:05:06Z")

</div>

Thanks [@quentin\_lamamy](https://community.hubspot.com/t5/user/viewprofilepage/user-id/148828) !

Below you may find the code and the error

the error is:

**UnhandledPromiseRejectionWarning: Error: Required parameter ticketId was null or undefined when calling create.**

**at AssociationsApi.**

```lia-code-sample
const hubspot = require('@hubspot/api-client')
const hubspotClient = new hubspot.Client({apiKey: 'MYAPIKEY'})

const contactObj = {
 properties: {
 firstname: 'T',
 lastname: 'Test',
 email: 'ty@example.com',
 company: 'Texample'
 },
}
const ticketObj = {
 properties: {
 "hs_pipeline": "0",
 "hs_pipeline_stage": "1",
 "hs_ticket_priority": "HIGH",
 "hubspot_owner_id": "5555555",
 "subject": "test association"
 }
};
// create ticket
const createTicketResponse = hubspotClient.crm.tickets.basicApi.create(ticketObj)
// create contact
const createContactResponse = hubspotClient.crm.contacts.basicApi.create(contactObj)
function addTicket(){
 return hubspotClient.crm.tickets.associationsApi.create(createTicketResponse.body, "tickets", createContactResponse.body, "", undefined, undefined)

}

addTicket()
 .then(console.log('done'))
 .catch(console.log('error'))

```

---

<div class="post-metadata">

**Author:** ![TShma](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tshma/32/16907_2.png) [@TShma](https://community.hubspot.com/u/TShma)\
**Post date:** [February 9, 2023, 10:30am UTC](https://community.hubspot.com/t/associate-ticket-to-contact/30002/4 "2023-02-09T10:30:17Z")

</div>

This is an old thread and I’m sure it was solved, yet if someone arrives here with the same issue, you should have supplied the ticketId and the contactId, respectively, wherever you’ve send the body of the response.

---

<div class="post-metadata">

**Author:** ![quentin\_lamamy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/quentin_lamamy/32/20212_2.png) [@quentin\_lamamy](https://community.hubspot.com/u/quentin_lamamy)\
**Post date:** [January 12, 2021, 9:12am UTC](https://community.hubspot.com/t/associate-ticket-to-contact/30002/5 "2021-01-12T09:12:53Z")

</div>

Hi, I don’t have the documentation of the node sdk , you should check first the parameter of the method. If the expected first parameter of the method is the ticket id you should check if createTicketResponse.body contain the id, please check doc, dump the value and post here the value of this variable

---

<div class="post-metadata">

**Author:** ![TYona](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tyona/32/1529_2.png) [@TYona](https://community.hubspot.com/u/TYona)\
**Post date:** [January 13, 2021, 7:56am UTC](https://community.hubspot.com/t/associate-ticket-to-contact/30002/6 "2021-01-13T07:56:39Z")

</div>

Hi,

Thanks again!

After checking it seems that the id is undefined.

I used this documentation, still no luck with assocation of a contact to a ticket.

I’d appreciate an example of it using the sdk from someone in the community 🙂

Thanks!

---

<div class="post-metadata">

**Author:** ![quentin\_lamamy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/quentin_lamamy/32/20212_2.png) [@quentin\_lamamy](https://community.hubspot.com/u/quentin_lamamy)\
**Post date:** [January 13, 2021, 2:46pm UTC](https://community.hubspot.com/t/associate-ticket-to-contact/30002/7 "2021-01-13T14:46:48Z")

</div>

Hi,

Can you give me the link of the documentation you are following and post the dump of createTicketResponse

---

<div class="post-metadata">

**Author:** ![TYona](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tyona/32/1529_2.png) [@TYona](https://community.hubspot.com/u/TYona)\
**Post date:** [January 13, 2021, 3:44pm UTC](https://community.hubspot.com/t/associate-ticket-to-contact/30002/8 "2021-01-13T15:44:01Z")

</div>

Actually I managed! The problem was with js rather then the api itself.

Thanks Quentin!

---

<div class="post-metadata">

**Author:** ![quentin\_lamamy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/quentin_lamamy/32/20212_2.png) [@quentin\_lamamy](https://community.hubspot.com/u/quentin_lamamy)\
**Post date:** [January 13, 2021, 3:53pm UTC](https://community.hubspot.com/t/associate-ticket-to-contact/30002/9 "2021-01-13T15:53:28Z")

</div>

If your issue is solved don’t forget to flag your post as solved.
