Reputation: 13
Error as follows:
/home/runner/CrowdedMajesticRouter/index.js:3
let apiKey,cJhlPVSd5-wzJ0iOv;
^
SyntaxError: Unexpected token '-'
let apiKey,
cJhlPVSd5-wzJ0iOv;
let search = (term, location) => {
return fetch(`https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=${term}&location=${location}`, {
headers: {
Authorization: `Bearer ${apiKey}`
}
}).then(response => {
return response.json();
}).then(jsonResponse => {
if (jsonResponse.businesses) {
console.log(jsonResponse.businesses)
}
});
}
search('Mexican', 'Los Angeles')
If the code is corrected as follows:
let apiKey = cJhlPVSd5-wzJ0iOv;
let search = (term, location) => {
return fetch(`https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=${term}&location=${location}`, {
headers: {
Authorization: `Bearer ${apiKey}`
}
}).then(response => {
return response.json();
}).then(jsonResponse => {
if (jsonResponse.businesses) {
console.log(jsonResponse.businesses)
}
});
}
search('Mexican', 'Los Angeles')
then the error is:
ReferenceError: cJhlPVSd5 is not defined
at /home/runner/CrowdedMajesticRouter/index.js:3:14
at Script.runInContext (vm.js:131:20)
at Object.<anonymous> (/run_dir/interp.js:156:20)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js
Per yelp: /businesses/search This endpoint returns up to 1000 businesses based on the provided search criteria. It has some basic information about the business. To get detailed information and reviews, please use the Business ID returned here and refer to /businesses/{id} and /businesses/{id}/reviews endpoints.
Note: at this time, the API does not return businesses without any reviews.
Upvotes: 1
Views: 3333
Reputation: 458
From the code you posted we can see you didn't declare your variable.
let apiKey
somekey;
It should be
let apiKey, somekey;
or
let apiKey;
let somekey;
That's why you're getting the ReferenceError
;
@Edit Now I see
let apiKey,
cJhlPVSd5-wzJ0iOv;
It should be
let apiKey = 'cJhlPVSd5-wzJ0iOv';
No idea why you're trying separate it by comma.
Upvotes: 1