NodeJS Client Ticket Associations (DoSearch)

Hey,

What is the correct way of, returning tickets using doSearch and bringing back associations?

For example, I want to Search for all Tickets and bring back the Association being Companies

I currently have this but, it is not working

 const tickets = await this.hubspotClient.crm.tickets.searchApi.doSearch({
 after: after, filterGroups: [
 {
 filters: [
 {
 propertyName: "hs_lastmodifieddate",
 operator: "GTE",
 value: date
 }
 ],
 }
 ], limit: 100, properties: ticketProperties, sorts: undefined, query: "&associations=companies"
 });

I have tried a few values in the query section but nothing is working.

Hi @JSixsmith :waving_hand:

As per HubSpot’s CRM Search API doc, it’s only possible to return records of the object-type specified in the request path. For example, if the request path is /crm/v3/objects/TICKETS/search, only Tickets can be returned in the response (i.e. not associated records of other object-types, like Companies).

You can however use the CRM Search API to “search for records that are associated with other specific records by using the pseudo-property associations.{objectType}”. Unfortunately, this doesn’t really align with your use case. I see 2 options to achieve your desired result (efficiency will depend on the data volumes you’re working with):

Option 1

More efficient with lower data volumes

  1. List Tickets (GET /crm/v3/objects/tickets?associations=company&limit=100)
    • Go through all records on all pages of results, identifying Ticket records that meet your search criteria and locating the associated Company IDs along the way
Option 2

More efficient with higher data volumes

  1. CRM Search Tickets (POST /crm/v3/objects/TICKET/search), as per your required search criteria, then …
  2. Batch Read Associations (POST /crm/v4/associations/TICKET/COMPANY/batch/read)
    • Using the Ticket IDs responded from your previous search in your request body

I hope that proves useful. Please let me know if you have any follow-up questions.