Problem authenticating with POST Request

Hello everyone,

we are currently facing a problem with authentication of out POST Requests. We cannot seem to authenticate via the token_auth parameter. We always get a “not authenticated” reply (html code of the matomo login screen).
We tried every possible authentication method.

Can someone hep us with this? We couldn’t find a solution anywhere for this. This is for a larger request we have to send via POST.

Thanks in advance for your help.

Hi,

For me the following does work:

curl --data "module=API&method=UsersManager.getUsers&token_auth=THETOKEN" -v http://dev.matomo/index.php

How are you making POST requests?

We are making the requests serverside with standard server-side POST and GET Requests.

With curl it would look something like this:

curl -d "module=API&method=API.getBulkRequest&format=json&token_auth=TOKEN&urls[0]=URLOFREQUEST" -H "Content-Type : application/json; charset=UTF-8, Content-Length: 'content length param' " -X POST "url of matomo"

But it doesn’t work with any type of POST request (url does not really matter). According to documentation, this should work as well as simple GET Requests.

In that case I’d recommend you to try it out with curl to see if it works in theory.

Matomo doesn’t differentiate between POST and GET parameters as far as I know.

Just in case anyone else, like me, ends up here from searching for solutions to this problem: Set your Content-Type to application/x-www-form-urlencoded. This is default for curl but not when using fetch() in the browser for example, which is why all the curl examples work but your code doesn’t :slight_smile: