# "Invalid id: null" when invoking crm\_associations() function with a variable argument

**URL:** <https://community.hubspot.com/t/invalid-id-null-when-invoking-crm-associations-function-with-a-variable-argument/16584>\
**Category:** CMS Development\
**Created:** [October 7, 2019, 4:14am UTC](https://community.hubspot.com/t/invalid-id-null-when-invoking-crm-associations-function-with-a-variable-argument/16584 "2019-10-07T04:14:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RepreZenTed](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/reprezented/32/56621_2.png) [@RepreZenTed](https://community.hubspot.com/u/RepreZenTed)\
**Post date:** [October 7, 2019, 4:14am UTC](https://community.hubspot.com/t/invalid-id-null-when-invoking-crm-associations-function-with-a-variable-argument/16584/1 "2019-10-07T04:14:04Z")

</div>

I’m trying to get the following code to work, but there seems to be a problem passing **contact\_id** as the first argument to the HUBL **crm\_associations()** function.

```auto
{% set contact_id = contact.hs_object_id %}
{% set deals = crm_associations(contact_id, 4) %} 
 <p>
 There are {{deals.results|length}} deals for {{contact.firstname}} {{contact.lastname}} (id # {{contactID}} ):
 </p>
<ul>
{% for deal in deals.results %}
 <li>{{ deal.dealname }}</li>
{% endfor %}
</ul>

```

In the editor, it shows “invalid id: null” and when I preview an email based on this template, the deals variable is empty or null. If I replace that first argument with a literal contact ID, it works fine. But that won’t work for my purposes; I need it to be dynamic.

How can I pass a variable expression as the function argument?

---

<div class="post-metadata">

**Author:** ![RepreZenTed](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/reprezented/32/56621_2.png) [@RepreZenTed](https://community.hubspot.com/u/RepreZenTed)\
**Post date:** [October 8, 2019, 5:34pm UTC](https://community.hubspot.com/t/invalid-id-null-when-invoking-crm-associations-function-with-a-variable-argument/16584/2 "2019-10-08T17:34:26Z")

</div>

Cross-reference to another issue, apparently related, and Slack discussions:

- [if statements in email templates](https://community.hubspot.com/t5/HubSpot-Ideas/if-statements-in-email-templates/idc-p/295355#M43162)
- [Problem with {% set %} statement](https://hubspotdev.slack.com/archives/C2YH119N2/p1570458844159800) on Slack channel
- [Problem with {% for %} loop](https://hubspotdev.slack.com/archives/C2YH119N2/p1570481033182700) discussed on Slack

I suspect that there’s one general limitation that prevents the use of email contact properties (“personalization tokens”) in

**{% if %},**

**{% for %},**

and

**{% set %}**

statements. If my hunch is correct, the use of the

**contact**

variable is limited to simple placeholders in the “compiled” template; you can’t use contact properties in any dynamic statements.

This is disappointing. I’d really to see this fixed.

In the meantime, it would be helpful if Hubspot could confirm or correct my understanding of this. And \*very\* helpful to update the reference pages that describe

**[set](https://designers.hubspot.com/docs/hubl/hubl-variables-and-macros-syntax), [for](https://designers.hubspot.com/docs/hubl/for-loops),**

and any other statements affected by this design limitation. As of now, AFAIK, the limitation is only documented on the [

**if**

]([If statements - HubSpot docs](https://designers.hubspot.com/docs/hubl/if-statements)) statement page. It would have saved me a lot of time if I had known about this!

---

<div class="post-metadata">

**Author:** ![RepreZenTed](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/reprezented/32/56621_2.png) [@RepreZenTed](https://community.hubspot.com/u/RepreZenTed)\
**Post date:** [October 14, 2019, 6:16pm UTC](https://community.hubspot.com/t/invalid-id-null-when-invoking-crm-associations-function-with-a-variable-argument/16584/3 "2019-10-14T18:16:25Z")

</div>

Through Hubspot Support, I got the suggestion to use

**request\_contact.contact\_vid**

instead of

**contact.hs\_object\_id**

.

This works, but I really don’t understand why, and have asked for some clarification on this. I’ll post back, and hopefully mark this issue as solved, once I can provide a better explanation.

---

<div class="post-metadata">

**Author:** ![RepreZenTed](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/reprezented/32/56621_2.png) [@RepreZenTed](https://community.hubspot.com/u/RepreZenTed)\
**Post date:** [October 20, 2019, 8:47pm UTC](https://community.hubspot.com/t/invalid-id-null-when-invoking-crm-associations-function-with-a-variable-argument/16584/4 "2019-10-20T20:47:14Z")

</div>

Here are my follow-up questions and the answers I received from Ben in Hubspot technical support:

**QUESTIONS**

**1. What is request\_contact? How is it different from contact, and how does it relate to email?**

The “Hubl supported variables” reference page says only that request\_contact is “A dictionary containing data about the requested contact.”

> **[HubL variables - HubSpot docs](https://developers.hubspot.com/docs/cms/reference/hubl/variables)**
>
> HubSpot templates can use a host of predefined variables that can be used to render useful website and email elements. This page is a reference listing of those variables.

What does “requested contact” mean? Is it really “requested contact” or is it “requesting contact”, meaning the current user contact as determined by a form submission (or by a cookie from a previous form submission)? If that’s a correct interpretation, then is it also correct to say that the request\_contact concept is extended (or repurposed) in the email context, to mean the email recipient contact?

Is this explained anywhere…?

**2. What is contact\_vid? How is it different from the hs\_object\_id property of a contact object?**

It’s shown in a code example here, but not explained:

> **[Accounts Dashboard | HubSpot](https://app.hubspot.com/myaccounts?next=developerdocs&redirect=%2Fcms%2Fdata%2Fcrm-objects)**

It doesn’t appear in the properties UI. Why not?

> **[Property Settings](https://app.hubspot.com/property-settings/597611)**

It’s not mentioned in the HubL reference page.

> **[HubL variables - HubSpot docs](https://developers.hubspot.com/docs/cms/reference/hubl/variables)**
>
> HubSpot templates can use a host of predefined variables that can be used to render useful website and email elements. This page is a reference listing of those variables.

The API page on contacts explains that it’s the internal ID of a contact. In that case, would hs\_object\_id return the same value?

> **[Accounts Dashboard | HubSpot](https://app.hubspot.com/myaccounts?next=developerdocs&redirect=%2Fmethods%2Fcontacts%2Fcontacts-overview)**

This page explains that ‘vid’ stands for visitor ID, which is helpful information:  
[https://developers.hubspot.com/docs/methods/contacts/get\_contact](https://developers.hubspot.com/docs/methods/contacts/get_contact)

**3. Why is it that request\_contact.contact\_vid works, but contact.hs\_object\_id doesn’t?**  
It would help to understand, at a deeper level, what is the intended purpose and meaning of ‘contact’ as distinct from ‘request\_contact’. I assume the difference in behavior can be better explained if we understand how these two concepts are different. But I have not found anything that explains this.

**ANSWERS**

Ben writes:

> The reason why the variables are not treated the same way when calling them within a functions argument is likely due in part to the dictionary structure and in part due to the data type.
> 
> For information on what HubL data is available to use, you can reference [this page](https://designers.hubspot.com/docs/hubl/how-to-use-developer-info-on-cms-pages). By using the Developer info page, you can see all of the data that is available to HubL. Searching here, you can see the top-level variables request\_contact and contact. In HubL, these are what we call dictionaries, because they’re variables that contain key/value pairs.
> 
> It looks like the contact dictionary is duplicated inside of the request\_contact dictionary. If you do a search on this page: [HubL variables - HubSpot docs](https://designers.hubspot.com/docs/hubl/hubl-supported-variables), we do have request\_contact documented. A dictionary containing data about the requested contact. We also have contact documented.
> 
> This variable is a dictionary that stores contact personalization properties for a known contact. Properties can be accessed from this dicionary, by adding a period and the property name. For example, contact.firstname would print the first name of a contact. so I think to answer your first question, request\_contact is a dictionary that includes the contact dictionary, but then also includes additional info about the contact.
> 
> For your second question, contact\_vid and hs\_object\_id are going to be the same. VID just refers visitor ID. it’s the ID that we use to identify a contact record. Contacts are a type of CRM object. As for why these two properties are named differently in different places, It is likely just because of the naming convention used in whichever tool is outputting the dictionary.
> 
> Your third question is a little more difficult to answer as it relates to some specific use cases of HubL within Emails as opposed to its use in the CRM. We’ve made some improvements to HubL over the years to include more functionality in email, though this may have lead to some unforeseen issues. This could be related to the fact that contact.hs\_object\_id is a string, whereas request\_contact.contact\_vid is a long. It could also be the crm\_assocations()function is trying to run before it has access to the contact dictionary.

OK, so I still wonder why **contact** and **request\_contact** are two different variables, with different behaviors. I don’t understand the explanation that request\_contact is “a dictionary containing data about the requested contact.” The phrase “requested contact” doesn’t mean anything in the context of an email, and it doesn’t explain how **request\_contact** is different from **contact**.

But I will leave it here for now, since I have a working solution with **request\_contact**.

---

<div class="post-metadata">

**Author:** ![Jenny](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jenny/32/24_2.png) [@Jenny](https://community.hubspot.com/u/Jenny)\
**Post date:** [October 21, 2019, 8:33pm UTC](https://community.hubspot.com/t/invalid-id-null-when-invoking-crm-associations-function-with-a-variable-argument/16584/5 "2019-10-21T20:33:49Z")

</div>

Thanks for sharing @RepreZenTed!
