I have been trying to make a GET request to the National Park Service API with axios and have tried several ways to set my API key in the request header to no avail. Any assistance will be greatly appreciated.
I have tried:
axios.defaults.headers.common['Authorization'] = "MY-API-KEY";
axios.get('https://developer.nps.gov/api/v0/parks?parkCode=yell')
.then((resp) => {
console.dir(resp);
});
and
let config = {'Authorization': 'MY-API-KEY'};
axios.get('https://developer.nps.gov/api/v0/parks?parkCode=yell', config)
.then((resp) => {
console.dir(resp);
});
and both return a 401. It works when I send the GET request in Postman, where I enter Authorization in the key field, and my API key in the value field.
Thank you.
OPTIONS https://developer.nps.gov/api/v0/parks?parkCode=yell 401 (OK)
– Rancourt