I am trying to create a new session with axios following this documentation: https://www.traccar.org/api-reference/#tag/Session/paths/~1session/post

This is my code, I have really tried everything without results

const sessionurl = 'http://31.220.52.187:8082/api/session';


const params = new URLSearchParams();
params.append('email', 'admin');
params.append('password', 'admin');

const config = {
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
}


axios
  .post(
    sessionurl,
    {
      withCredentials: true,
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded',
        'Access-Control-Allow-Origin': '*',
      },
    },
    {
      params   
    },
    

  )
  .then(function (response) {
    console.log('Authenticated');
  })
  .catch(function (error) {
    console.log('Error on Authentication');
  });
1

There are 1 best solutions below

0
On

It should be something like this:

const params = new URLSearchParams();
params.append('email', 'admin');
params.append('password', 'admin');
axios.post(sessionUrl, params);

You might need to also add a header.