How to build a proper HTTP API call for Matomo

791 views Asked by At

I am new to using APIs but have been reading up on it. My task is to import data from an API into a CSV file. I have created one import string which works (from an example). Despite reading the documentation page and the one working example I have not yet gotten the actual report that i need to work.

Here is the string that did work:

myURL = "https://admin.metrics.mysite.com/?module=API" _
& "&method=API.get&idSite=9&period=day&date=last30&format=tsv&translateColumnNames=1" _
& "&token_auth=" & myToken

What i need is a monthly report of all files that were downloaded.

Here is my last attempt (many variations already tried):

Dim myToken As String
myToken = "secrettokenhere"
myURL = "https://admin.metrics.mysite.com/?module=API" _
    & "&method=API.getDownloads" _
    & "&idSite=9" _
    & "&period=day" _
    & "&date=2018-11-05" _
    & "&segement=''" _
    & "&expanded=''" _
    & "&idSubtable=''" _
    & "&flat=''" _
    & "&format=tsv" _
    & "&filter_limit=10" _
    & "&token_auth=" & myToken

When I run this, the error message that i get returned is this:

Error: The method 'getDownloads' does not exist or is not available in the module '\Piwik\Plugins\API\API'.

I'm stuck on the most basic of things... am I using the correct get method? Am I missing parameters? What am I doing wrong?

Any pointers appreciated!

1

There are 1 answers

4
lw1.at On BEST ANSWER

As you can see in the API reference, the method is not called API.getDownloads, but instead Actions.getDownloads.

More detail now that I understand your issue better:

The API endpont you are using (API.get) gives you a count of the downloads per day, which I don't think is what you want.

The easiest way to get the right endpoint (apart from reading the API reference) is opening the report you need in the Matomo UI. If you want a list of all downloads, this would be the Behaviour -> Downloads report. Afterwards you can click on the export icon below the table and it will show you the correct API url.

In your case it would now be ?module=API&method=Actions.getDownloads

If you don't want a directory, but a flat list you can add &flat=1: ?module=API&method=Actions.getDownloads&flat=1.

This should return what you want (maybe also add &filter_limit=-1 to get back unlimited results).