7

Trying to hit YouTrack's API via axios but I am receiving an unauthorized error, while same params via curl work.

curl:

curl -X GET \
'https://<my youtrack url>/api/issues' \
-H 'Authorization: Bearer perm:<my token>' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json'

axios:

const config = {
    headers: {
        'Content-Type': 'application/json',
        Authorization: 'Bearer perm:<my token>'
    },
    responseType: 'json',
};

axios.get('https://<my youtrack url>/api/issues', {}, config)
    .then((response) => {
        console.log(response.data);
    })
    .catch(e => {
        console.log('Error: ', e.response.data)
    });

The curl correctly returns JSON of my available issues, whereas my axios call returns an error

{error: "Unauthorized", error_description: ""}

Thanks

Arthur
  • 2,622
  • 4
  • 28
  • 46

1 Answers1

7

Send the config as the second parameter, as GET requests don't need the body

axios.get('https://<my youtrack url>/api/issues', config)
    .then((response) => {
        console.log(response.data);
    })
    .catch(e => {
        console.log('Error: ', e.response.data)
    });
Dalvtor
  • 3,160
  • 3
  • 21
  • 36
  • I had a similar problem. The code snippet from auth0 used `axios.request`; i changed this to an `axios.post` and it worked as expected. – timebandit Apr 16 '21 at 08:38