I would like to get the total number of active contacts that have a specific tag or a number of specific tags.
The only way I think I can do this is with the API using the contact_list call.
Since the ActiveCampaign API call for contact_list will only return 20 at a time, and I have a few thousand contacts that meet this specific criteria, it takes me more than 100 calls to the API just to get that one number.
Also, it takes over 4 minutes to process this loop.
You can get these numbers easier from a list than a tag. I would add the contacts to a list via automation etc, and then use the list_list or list_view endpoints to retrieve these totals.
Just so I understand, you’re suggesting that I create an automation that copies contacts that are active and have the specific tag that I’m looking for over to a new list.
Then I use that list to get the number via the list_list or list_view endpoints?
How are you making your requests? In python, I use the requests library combined with the concurrent.futures library to make the calls asynchronously - definitely speeds up crawling through all of those pages! But I think for what you are trying to accomplish, you do not need to paginate. Here’s how I would do what you need:
Use the contacts endpoint in v3 and filter on the tag you want to know the number of contacts for. The response contains a ‘meta’ key that includes information about the data contained in the response. There is another key nested in ‘meta’ called ‘totals’ that tells you the number of total results possible calling the endpoint with parameters you passed - if you pass the specific tag id in the parameter, meta → total should tell you how many contacts you have with that tag.
Also, I would respectfully disagree with another commenter who suggested building an automation to create a list for each tag. As your tags grow, so will your lists and I can tell you from first hand experience that managing more than 5 lists creates tons of headaches (not to mention having both tags and lists for effectively the same purpose is redundant).
@eduardobeta - see my post above about getting the number of contacts by tag. You can do the same thing with lists - pass the list id parameter into your request URL and use meta → totals to get the number of contacts. You can also pass a status parameter into your request URL if you only wanted to get actives, unsubs, etc. (e.g. base_url?listid=1234&status=1 would get you active contacts for list 1234)