Last edited: 3. Apr 2025   

For this blog post, I set up two Custom Objects in HubSpot: Car and AutomotiveService. Car object is linked to Contacts, while AutomotiveService is associated with Cars.

I also created two test Contacts and assigned above Custom Objects to them. Both are named John 🙂

Now, let’s say that for every John I want to display a list of Cars and its related Automotive Services on a webpage. To make this happen, I created a standard HTML+HubL template.

simple hubl templateSimple template

 

Using HubL functions: crm_objects and crm_associations

To pull this data, we can use two HubL functions: crm_objects and crm_associations.

  1. First, we fetch Contacts
  2. Then, for each Contact, we find their associated Car
  3. Finally, we fetch the Car’s related Automotive Services

 

Let's add fetching contacts to our template using crm_objects function:

<h1>
List of Johns cars
</h1>


 

In preview it looks like this:

Screenshot 2025-04-02 at 16.43.13Preview of the template

 

We have a list of Contacts. Now, for every person we have to fetch associated Cars. 

The crm_associations function does that, and its structure looks like this:

crm_associations(objectId, associationCategory, associationId, query, property, formatting)

First three parameters are mandatory:

  • objectId – This is the Contact ID, which we get from the crm_objects function
  • associationCategory – Mostly we will use two of them: HUBSPOT_DEFINED (used for default HubSpot associations like Contact-Company, Company-Deal, etc.) or USER_DEFINED (for Custom Object relationships)
  • associationId - This is the tricky part - finding the right ID for a custom association isn’t straightforward

 

Finding Association ID value

HubSpot’s documentation provides a list of default association IDs: HubSpot Associations Docs

association IDs exampleAssociation IDs in HubSpot


But what if you need the ID for a custom association? HubSpot doesn’t show this anywhere. Fortunately, we can find it using the CRM API.

Step 1: Create a Private App
First, create a Private App in HubSpot with access to Contacts and Custom Object schemas.

private-app-settingsPrivate Apps in Settings

 

creating private appPrivate App configuration

 

Make sure it has the proper scope:

private app scopesPrivate App scopes

 

Step 2: Use the Associations API
Once the app is set up, go to the Associations API and use the List request 

Step 3: Retrieve the Association ID
Now, enter the correct values. We are trying to get the association between Contact and Car, so we have to put a proper parameters. In my case it looks like this:

example request parametersExample request parameters

ObjectId 24211927251  is one of my Contacts, which is associated to Car Custom Object. We focus on getting only the association ID, so we can use any Contact ID. It only needs to have a connection to the Car object.

After executing a test request, we get the response with association ID.

executing requestExecuting the request

 

association responseResponse with association ID

Key typeId is the one we are looking for.

Having the ID, we can add the first association to our template. We will add fetching Contact - Car association by adding crm_association function with ID = 34.

<h1>
List of Johns cars
</h1>


 

After adding that, we can see the cars on the list:

johns carsUpdated list of cars

Now, we can recreate the same steps for fetching association ID between Cars and AutomotiveServices Custom Objects. Let's change the params and make the test request.

cars services connection paramsParameters for fetching relation between Cars and AutomotiveServices

response 2Response from the test request

Our typeId is 54 for this one.

We already have all necessary information now, let's finish the code in the template:

<h1>
List of Johns cars
</h1>


 

It gives us the following result:

finished listFinished list of Contacts with Cars and AutomotiveServices

With this technique you can always get the right IDs for your custom associations to use in your template.

Take care!

Authors
  Mariusz Wróbel
Share

Comments