How to check what lists a contact is part of by contact ID?
I'm trying to show specific content if a user is part of a list in HubSpot.
Psuedo:
If contact_id is part_of_this_list then do this
The contact ID at the moment is being obtained from the query string. I'm trying to check if the user is part of said list, but it's not working.
Approach:
{% set id_querystring = request.query_dict.id %}
{% set registration_list_id = "6136" %} <!-- id of the list I'm checking -->
{% if id_querystring in registration_list_id %}
contact is part of list
{% else %}
contact is not part of list
{% endif %}
How to check what lists a contact is part of by contact ID?
Hi Kevin,
I've tried something equivelant to that already:
{% set id_querystring = request.query_dict.id %}
{% set registration_list_id = "6136" %} <!-- id of the list I'm checking -->
{% set list_memberships = request_contact.list_memberships %}
{% if id_querystring in registration_list_id %}
contact is part of list
{% elif id_querystring in list_memberships %}
contact has valid query string and is part of list
{% else %}
contact is not part of list or no valid query string
{% endif %}
Aug 3, 202010:26 AM - edited Aug 3, 202010:28 AM
Recognized Expert | Partner
How to check what lists a contact is part of by contact ID?
So I a little got too confused and jumped back to your original post:
{% set registration_list_id = 6136 %} <!-- id of the list I'm checking -->
{% set list_memberships = request_contact.list_memberships %}
{% if registration_list_id in list_memberships %}
Content to show if the user IS a memeber of the list
{% else %}
Content to show if the the user IS NOT a memeber of the list
{% endif %}
Am I missing anything?
You can test this like so:
{% set registration_list_id = 6136 %} <!-- id of the list I'm checking -->
{% set list_memberships = [6136,1234,987645,4567,7654,23,7654] %}
{% if registration_list_id in list_memberships %}
Content to show if the user IS a memeber of the list
{% else %}
Content to show if the the user IS NOT a memeber of the list
{% endif %}
How to check what lists a contact is part of by contact ID?
Let me just clarify:
I'm creating a gated page which is accessible if they've registered for the event (filled out a form).
I can currently registered (complete the form) and it works: so this if statement is working:
{% if registration_list_id in list_memberships %}
The above works because on form submission, HubSpot creates a cookie and using that, it's able to find out what lists a member is part of.
Now, let's assume that the user completes the form (registers for the event), but, clears there cookies or returns to the site when the cookie has expired. To counter this, emails will be sent out to contacts where there contact IDs will be in the URL (i.e. /home?id=contact_id.
I've then created a list which anyone who has filled out the registeration form into a list (which is that list with the ID of 6136.
Now, what I'm looking to do is:
Get query string from URL
Check what lists this user is part of
Check if the user is part of the registration list (with the ID of 6136)
If yes, for now, just print the message "contact has valid query string and is part of list"
Aug 3, 202010:53 AM - edited Aug 3, 202010:54 AM
Recognized Expert | Partner
How to check what lists a contact is part of by contact ID?
I think I see. So we just add an OR operator to the IF statement
{% set id_querystring = request.query_dict.id %}
{% set registration_list_id = 6136 %} <!-- id of the list I'm checking -->
{% set list_memberships = request_contact.list_memberships %}
{% if id_querystring == registration_list_id or registration_list_id in list_memberships %}
Content to show if the user IS a memeber of the list
{% else %}
Content to show if the the user IS NOT a memeber of the list
{% endif %}
this should cover both the use case and the edge case
crm_bject would be the tool you needed, but I'm pretty sure that can't be done on public pages, and can only be done on a login page or password protected page. See CRM_object ref here.