Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
186
rated 0 times [  191] [ 5]  / answers: 1 / hits: 18273  / 8 Years ago, thu, june 30, 2016, 12:00:00

I'm trying to get some datas from an external API (from Mashape) that requires a specific header to set the API key.



Everything is ok using jQuery :





$.ajax({
url: 'https://omgvamp-hearthstone-v1.p.mashape.com/cardbacks',
type: 'GET',
data: {},
dataType: 'json',
success: function(data) { console.dir((data.source)); },
error: function(err) { alert(err); },
beforeSend: function(xhr) {
xhr.setRequestHeader(X-Mashape-Authorization, MY_API_KEY);
}
});





However, when I'm trying to do the same request with axios for a react application, I have a 404 error:





axios.get({
url: 'https://omgvamp-hearthstone-v1.p.mashape.com/cardbacks',
headers: {
X-Mashape-Authorization: MY_API_KEY
}
})





Is there something I'm missing ? Thanks.


More From » api

 Answers
12

Try also to do it like this without setting defaults:



axios.get('https://omgvamp-hearthstone-v1.p.mashape.com/cardbacks', {
headers: { X-Mashape-Key: MY_API_KEY }
})
.then((resp) => {
console.dir(resp);

})
.catch(err => {
console.log(err);
});
}


It should work.



PS I also observed that you use different header keys in question(X-Mashape-Authorization) and answer(X-Mashape-Key). Maybe that is also somehow related to 404 error?


[#61566] Tuesday, June 28, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dayshadelaniej

Total Points: 668
Total Questions: 121
Total Answers: 121

Location: Sao Tome and Principe
Member since Wed, Dec 21, 2022
1 Year ago
;