PHP API to get visitor counts

Hi all, I am writing a PHP script that I want to be able to get Visitor count information from a self hosted version of Matomo, is such a thing possible?

For this all I want to know is quantity, not sure I’m going to care about many details at this point.

I’ve checked out the API and can’t find a getVisitors call, is there such a thing?


Would this API answers your needs:


API description:

Thanks Phillippe,

I believe it would. A couple of follow up questions:

  • Would it be better to use a key instead of being anonymous?
  • If I wanted to get the results for a week, would I need to submit the request for 7 times? or is there a way to ask it for a week’s worth of information in one request broken up by date?


Being anonymous means your Matomo is accessible anonymously, I suggest you don’t do that for security purposes (and the use of a key is not a problem, as the API would be used through your PHP, then the key would not be publicly visible).

The API provide several option:

  • period — the period you request the statistics for. Can be any of: day , week , month , year or range . All reports are returned for the dates based on the website’s time zone.
    • day returns data for a given day.
    • week returns data for the week that contains the specified ‘date’
    • month returns data for the month that contains the specified ‘date’
    • year returns data for the year that contains the specified ‘date’
    • range returns data for the specified ‘date’ range.For example to request a report for the range Jan 1st to Feb 15th you would write &period=range&date=2011-01-01,2011-02-15

In this case you’ll get the cumulated nb_uniq_visitors / nb_users / … for the selected period.
If you need the detail for each day:

I tried to copy your example and I came up with the following url:

<matomo url>/?module=API&method=VisitsSummary.get&idSite=4&period=day&date=today,yesterdayformat=json&token_auth=<token>

this is producing the following error:

"Date format must be: YYYY-MM-DD, or 'today' or 'yesterday' or any keyword supported by the strtotime function (see for more information): today, yesterday"

Not sure what the issue is, or how to fix it. I’ve also tried adding a space between today and yesterday no change.

And amperstand (&) is missing between yesterday and format

Sorry I meant I was using the following:


Still getting the same error.

It seems you cannot append 2 date keywords…
Then you have to “calculate” the dates of yesterday and today into YYYY-MM-DD :wink:

OK, I wonder if there is also a limit to how many days you can do at one time…
/?module=API&method=VisitsSummary.get&idSite=4&period=day&date=2022-08-25,2022-08-24,2022-08-23,2022-08-22,2022-08-21,2022-08-20,2022-08-19,2022-08-18 also has the same error.

Yeah, it seems you can put only 2 dates…
Or you can also use API:,2022-08-24&method=API.get&filter_limit=100&format_metrics=1&expanded=1&token_auth=anonymous&force_api_session=1,2022-08-24&method=API.get&filter_limit=100&format_metrics=1&expanded=1&token_auth=anonymous&force_api_session=1

Thanks mate this API really helpful for my website as well