APIs & Integrations

TYona
Member

Associate Ticket to contact

SOLVE

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!

1 Accepted solution
TYona
Solution
Member

Associate Ticket to contact

SOLVE

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

Thanks Quentin!

View solution in original post

0 Upvotes
8 Replies 8
quentin_lamamy
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

Associate Ticket to contact

SOLVE

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


0 Upvotes
quentin_lamamy
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

Associate Ticket to contact

SOLVE

Hi,

 

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


0 Upvotes
TYona
Solution
Member

Associate Ticket to contact

SOLVE

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

Thanks Quentin!

0 Upvotes
quentin_lamamy
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

Associate Ticket to contact

SOLVE

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


TYona
Member

Associate Ticket to contact

SOLVE

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!

0 Upvotes
quentin_lamamy
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

Associate Ticket to contact

SOLVE

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


TYona
Member

Associate Ticket to contact

SOLVE

Thanks @quentin_lamamy !

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.

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'))

 

TShma
Contributor

Associate Ticket to contact

SOLVE

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.