APIs & Integrations

avomd
Member

Ticket association configuration

SOLVE

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

 

0 Upvotes
1 Accepted solution
sylvain_tirreau
Solution
Top Contributor

Ticket association configuration

SOLVE

Hello,

 

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 avatar

Sylvain Tirreau

FREELANCE HUBSPOT DEVELOPER SPECIALIZING IN ADVANCED HUBSPOT CUSTOMIZATION.

I am not a HubSpot member. Just a HubSpot community member.

FRANCE - European Union

HubSpot CommunityLinkedInMap
hubspot-addict.comOpen in new tab

View solution in original post

0 Upvotes
2 Replies 2
sylvain_tirreau
Solution
Top Contributor

Ticket association configuration

SOLVE

Hello,

 

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 avatar

Sylvain Tirreau

FREELANCE HUBSPOT DEVELOPER SPECIALIZING IN ADVANCED HUBSPOT CUSTOMIZATION.

I am not a HubSpot member. Just a HubSpot community member.

FRANCE - European Union

HubSpot CommunityLinkedInMap
hubspot-addict.comOpen in new tab
0 Upvotes
BérangèreL
Community Manager
Community Manager

Ticket association configuration

SOLVE

Hi @avomd and welcome, we are so glad to have you here!

Thanks for asking the HubSpot Community!

For reference, here is the documentation for this: "Tickets - Associations".

I'd love to put you in touch with our Top Experts: Hi @sylvain_tirreau, @Anton and @zach_threadint do you have suggestions to help @avomd, please?

Have a lovely day and thanks so much in advance!
Bérangère





loop


Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.

Learn More




0 Upvotes