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
}),
});