Reputation: 77
I am still learning to work with different APIs, and have been working with JavaScript and the Yelp API. I have tried using Ajax, as well as the code I have posted here, but I continue to get the error of:
"code": "TOKEN_MISSING", "description": "An access token must be supplied in order to use this endpoint."
I will continue to search through other posts, but if anyone could point out to me what I am doing incorrectly and how to fix it, I would really appreciate it?
var URL = 'https://api.yelp.com/v3/businesses/search?location=40515&term&categories=vet&limit=10';
var API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxx';
var req = new Request(url, {
method: 'GET',
headers: new Headers({
'Authorization: Bearer', API_KEY,
'Content-Type': 'application/json'
})
mode: 'no-cors'
});
fetch (req)
.then((response) => {
if(response.ok){
return response.json();
}else{ssss
throw new Error();
}
})
.then((jsonData) => {
console.log(jsonData);
})
.catch((err) => {
console.log('ERROR: ', err.message);
});
Upvotes: 2
Views: 1197
Reputation: 1792
I think an answer I posted before to a similar question with a full code sample may lead you in the right direction:
https://stackoverflow.com/a/51461033/9525657
Have a look, it’s an easy and simple process of pulling from the service :)
Upvotes: 3
Reputation: 6482
I think you just need to fix up:
'Authorization: Bearer', API_KEY,
to be something like:
'Authorization': `Bearer ${API_KEY}`,
or:
'Authorization': 'Bearer ' + API_KEY,
And if this line isn't just redacted for posting here:
var API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxx';
then you would need to actually get an API key from yelp as 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
would not be a valid key
Upvotes: 3