Getting programatic access to stats in WP plugin

Hi,

I’m trying to collate data from different reports into a nice view by , for which I’d like to be able to read data from the reports either using a REST, Matomo, or PHP API.

Calls to the REST API don’t seem to return anything but HTML. Taking a query to the Matomo API and changing the format to JSON or CSV still returns HTML data:

//wp-content/plugins/matomo/app/index.php?date=2023-02-03&module=Actions&format=json&action=getPageUrls&idSite=1&period=day&segment=&widget=&showtitle=1&random=4630

And the REST API seems to return a 500 on almost all queries (“Your session has expired due to inactivity. Please log in to continue.” – but I’m logged into WP as an admin, and I can see the WP cookies are being sent)

Is what I’m trying to do possible, and if so, what am I doing wrong?!

Thanks,
Dan

Hi @DanW Matomo for WordPress doesn’t support our HTTP API but instead supports the WordPress REST API. View the reference and more information on our developer site. You can use it to automatically create goals, fetch reports, add annotations, and more.

Hi Varun,

Thanks – I understand that Matomo for WordPress doesn’t support the HTTP API. My query is about why I’m getting 500 errors on the REST API.

Do you have any examples of working calls to the REST API? The example given on the page linked gives me an error:
{"code":"matomo_error","message":"Please specify a value for 'apiAction'.","data":null}

And calls to other routes listed there result in 500 errors, e.g.
/index.php?rest_route=/matomo/v1/live/last_visits_details
returns
{"code":"matomo_no_access_exception","message":"You must be logged in to access this functionality.","data":null}

Thanks,
Dan