Get number of logged users using custom variables

I have a custom variable, that I fill with the user name when it is logged in on my website. I would like to make an API call to know the number of accounts that have logged in in a date range. How could I do that? Is Piwik the right tool for that or should I implement it directly in my database? For now, I have only been able to get the number of visits of logged users, and the number of visits per user for the top 1000 users with the most visits, the others are grouped.

You can do this using the CustomVariables API and request the report over a date range. You will get number of logins per user. Make sure you also increase the archiving limits, in case you have more than 50 or 100 different logins. See How to - Analytics Platform - Matomo

I have not been able to get the number of different account which have logged in during a given date range, but thanks, I played with the limits in order to get the full list. So here is the API call:
So, to know the number of different users, I simply compute the size of the “subtable” array.