crm_associations "results" seems to be empty

Hello,

I try to get associated line items from deal I did this :

{% set line_items = crm_associations(deal.hs_object_id, "HUBSPOT_DEFINED", 19, "limit=50", "name,quantity", false) %}

{{ line_items.total }}

line_items.total work, it return the number of line items associated to my deal

Where I don’t understande is when I do this :

{% set line_items = crm_associations(deal.hs_object_id, "HUBSPOT_DEFINED", 19, "limit=50", "name,quantity", false) %}

{{ line_items.total }}

{% for item in line_items.results %}
 <p>Product name : {{ item.name }} x {{ item.quantity }} Qty</p>
{% endfor %}

I got an error “Unable to validate template at this time. Please try again.”

I tried to show {{ line_items.results }} but same error.

It’s like I can loop trough results but can’t get data

Any idea or help ? It made me crazy haha

Hey there!
So here is what I’m seeing on your call:

{% set line_items = crm_associations(deal.hs_object_id, "HUBSPOT_DEFINED", 19, "limit=50", "name,quantity", false) %}

This returns associated line item IDs, not full line item objects. So when you try to access item.name or item.quantity, it fails because item is just an ID, not the full object.

That’s why line_items.total works (because that’s metadata), but item.name or item.quantity throws an error — the results array only contains IDs like this:

{
 "results": [123456, 234567, 345678]
}

What you’ll have to do to get the full data for each line item (like name, quantity, etc.), you have to loop through the IDs and make an additional call to crm_object() to fetch each line item’s details.

Here’s how to do that in your HubL:

{% set line_items = crm_associations(deal.hs_object_id, "HUBSPOT_DEFINED", 19, "limit=50", "", false) %}

{{ line_items.total }}

{% for item_id in line_items.results %}
 {% set line_item = crm_object("line_item", item_id, "name,quantity") %}
 <p>Product name: {{ line_item.name }} x {{ line_item.quantity }} Qty</p>
{% endfor %}

Let me know if this gives you a solution or not!

Hello @DilionSmith ,

Thank’s a lot for your help. I admit that the documentation is not really clear for me about the crm_associations. We can pass properties but cannot access it directly, find this little bit strange.. BUT your solution work !

Regards,

Glad my reply helped solved your problem!

Yeah sometimes documentation can be a little lacking for HubL and other departments of HubSpot.