Get list count from ActiveList in HubL


Hi, I've created a custom module that should know how many contacts are in a specific Active List.
I've searched everywhere but I cannot find how to access a list there. something like this pseudocode:
{% set MyList = hubspot_list(<listid>, queryparams) %}
{% set ListCount = rowcount(MyList) %}

Can anyone help me out with this?

I know this is not the place for HubL questions; however Hubspot support told me this question is out of their league and sent me here... :face_with_raised_eyebrow:


Hi @hansw, interesting -- I'll have a chat with Support. Do you have the ticket #? I think they probably meant for you to go to this forum: We plan on moving this forum under the same umbrella ( at some point, so there's definitely confusion all around.

As for your issue, I don't think there's a way to see if the list is an active list, but you could use the request_contact.list_membership object that exists in the Developer Information. See more info in this thread: "is containing" does not seem to work when looking at list memberships

I suppose you could also manually set an active list array of all of your active lists. Something like this:

{% set active_lists = [2, 18, 27, 28] %}

then loop through all of those lists, but obviously manually doing that would be a huge pain. Another option would be to use the lists endpoint here: to paginate through all of your lists, and put them into an array only if listType is equal to DYNAMIC, but this would have to be done on the back end since most of our endpoints don't support CORS/AJAX requests.


@Connor_Barley thanks for your reply. The ticket is #2175785. My issue is a bit more straightforward.
My Custom Module helps web visitors subscribe to a training.
It reads available training dates from a HubDB table. When a user selects a date, it show a subscription form. Based on the form, the training date is added to a Contact Property and the Contacts is added to an active list based on "training date is known".
Because each training has a max no of participants, I now wanted to have the Custom Module not only select the training dates from the HubDB table, but also check the number of subscribers we already have. I wanted to count Contacts in that active list. So the list ID would be known to me.
Another option could be, however, to count the number of Contact where the training date equals the selected training date. Is that something that could be achieved using HubL code?

Hope this clarifies a bit.


Hi @hansw thanks for providing your ticket # and the extra details. I don't see a way that this would be possible only with HubL. We do not store list size to be available for use on the front end. That said, since you're using HubDB, this could make a solution more tangible, though it would be somewhat complicated. Here's what I'd propose:

  1. You subscribe to a change in the training date property with Webhooks.
  2. You make a call to the Get Contact List by ID endpoint, which will return the size of the list.
  3. You create a new field in your HubDB table to hold the size of the list.
  4. You make a call to update a HubDB table with the size of your list from step 2.

This way, you'll have information surfaced in your table that we don't surface on the front-end. This is definitely a complex solution, and I understand it may not be feasible, but I don't see a way we would be able to calculate and store this value without a solution like this.