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