+1

Has anyone made a request to XTRF's API with axios? (401 Error)

Juan (Comunica Translations) 3 years ago in API updated by Bartosz Budzyński 3 years ago 1

Hello:

I was wondering if any of you has made a request to the XTRF's API with JS and the AXIOS library.
I don't seem to get the headers configured the right way.

I have tried with postman (X-AUTH-ACCESS-TOKEN header) and the request works just fine.

Would you be so kind to share the code for the Axios GET request, please?



const headers = {
'Access-Control-Allow-Headers': 'x-access-token',
'Authorization': 'XXXXXXXXXXXX' }

const axios = require('axios').default;

axios.get('https://XTRF-server/home-api/browser?viewId=XXX',headers)
.then(resp => { console.log(resp.data); })
.catch(err => { // Handle Error Here console.error(err); });




Thanks in advance.

My best regards.

Hi Juan,

I'm not sure about Axios, but it seems that the header you're sending is "Authorization" when it should be "X-AUTH-ACCESS-TOKEN". 

Best,

Bartosz