Matomo APIs

API is a nice word in order to say that you can create custom applications and that you can automate processes.

APIs are working with two things:

  • an HTTP request: as it names stand for it, it corresponds to what you are requesting. For example, get me the total count of visits of yesterday for website abc.com.
  • credentials associated to this HTTP request: in fact so as all HTTP requests you are authorized or not to get an access to this data. In general most APIs will ask you for a token which is somehow like a login and password combined. If the token value corresponds to the user who has an access to the information system then the request is performed successfully, if not then it is a forbidden access.

Matomo APIs are very very powerful and easy to use. Compared to many other solutions in Matomo, almost everything can be used thanks to the API, to give you a couple of example you can use it for:

  • extracting data (ok everyone expect that from an API).
  • create segments, annotations, add/edit users, creating websites (in fact every features).
  • import data within Matomo (whatever data including data in the past).

There are two main APIs in Matomo:

  • Reporting API (which surprisingly does not only reporting).
  • Tracking API (so to say to import data within Matomo).

The documentation of https://matomo.org does a very good job in order to introduce you to the API, but it will make more sense if we apply a direct example here. We will use one example of the Reporting API and one for the tracking API.

In order to help you, you have in Matomo within the back-end a feature named API (Admin --> Platform --> API). This menu helps you get exactly the structure you need in order to call the API, so for the sake of the example we are showing here, please go this menu page.

Reporting API example

In this example we are going to export in a specific format the last visits of one of our website and we are going to see how this request is structured.

Ok now let's another example of the reporting API about how to control one feature, for example the segment feature.

Tracking API example

Ok let's see how to import data within Matomo:

Last modified: Thursday, 30 July 2020, 12:00 PM