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.”
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:
It doesn’t appear in the properties UI. Why not?
It’s not mentioned in the HubL reference page.
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?
This page explains that ‘vid’ stands for visitor ID, which is helpful information:
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. 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, 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.