We are utilizing the Hubspot API to create new tickets from the help button within our web app. The ticket creation is working as expected but we need help associating the ticket with the Hubspot Company and Contact objects. A few questions:
1. I'm attempting to configure Ticket Associations in Hubspot > Settings > Data Management > Objects > Tickets > Associations. What is the correct "Object Association"? Is it "Tickets to companies" and "Tickets to contacts"?
2. From there, I see that I can view API details and retrieve the Association ID. Would I simply apply those values into the code I have below?
// HubSpot ticket creation with associations (currently commented out)
try {
// const associations: Array<{ to: { id: string }; types: Array<{ associationCategory: string; associationTypeId: number }> }> = [];
// TODO: Enable associations after configuring contact/company to ticket associations in HubSpot
// if (contactId) {
// associations.push({
// to: { id: contactId },
// types: [{ associationCategory: 'HUBSPOT_DEFINED', associationTypeId: 1 }], // Contact to ticket
// });
// }
// if (companyId) {
// associations.push({
// to: { id: companyId },
// types: [{ associationCategory: 'HUBSPOT_DEFINED', associationTypeId: 25 }], // Company to ticket
// });
// }
const response = await fetch(`${HUBSPOT_BASE_URL}/crm/v3/objects/tickets`, {
method: 'POST',
headers: {
Authorization: `Bearer ${HUBSPOT_API_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
properties: {
subject: `${feedbackData.type}: ${feedbackData.feedback}`,
content: ticketContent,
hs_pipeline_stage: '1',
},
// associations, // TODO: Enable after HubSpot configuration
}),
});
1) For your needs, yes it's "Tickets to companies" and "Tickets to contacts".
2) In your code, the associationTypeId are not correct: for Ticket -> Contact, it's 16, and for Ticket -> Company, it's 26. If you add the associations after creating the ticket, it's more readable to use crm.associations.batchApi.create().
Sylvain Tirreau
FREELANCE HUBSPOT DEVELOPER SPECIALIZING IN ADVANCED HUBSPOT CUSTOMIZATION.
I am not a HubSpot member. Just a HubSpot community member.
1) For your needs, yes it's "Tickets to companies" and "Tickets to contacts".
2) In your code, the associationTypeId are not correct: for Ticket -> Contact, it's 16, and for Ticket -> Company, it's 26. If you add the associations after creating the ticket, it's more readable to use crm.associations.batchApi.create().
Sylvain Tirreau
FREELANCE HUBSPOT DEVELOPER SPECIALIZING IN ADVANCED HUBSPOT CUSTOMIZATION.
I am not a HubSpot member. Just a HubSpot community member.