Ravenous part 4 Error

Whenever I run the project I get this error in the browser.

./src/util/Yelp.js
SyntaxError: C:\Users\hdemirci\ravenous2\src\util\Yelp.js: Unexpected token (8:22)

6 | return fetch(https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=${term}&location=${location}&sort_by=${sort_by},
7 | headers:{

8 | Authorization:Bearer ${apiKey}
| ^
9 | }).then((response) => {
10 | return response.json();}
11 | ).then((jsonResponse){

<—Here is my code from the editor. —>

const apiKey=“API_KEY_HERE”;

const Yelp={

search(term, location, sortBy){

return fetch(`https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=${term}&location=${location}&sort_by=${sort_by}`, 

headers:{

    Authorization:`Bearer ${apiKey}`

}).then((response) => {

    return response.json();}

    ).then((jsonResponse){

        if (jsonResponse.Businesses){

            return jsonResponse.businesses.map((business)=>{

                return {

                id:business.id,

                imageSrc:business.image_url,

                name:business.name,

                address:business.location.address1,                 

                city:business.location.city,

                state:business.location.state,

                zipCode:business.location.zip_code,

                category:business.categories[0].title,

                rating:business.rating,

                reviewCount:business.review_count

             } });

        }

    })

}

};

export default Yelp;

Blockquote

One problem is that the variable used in your search function is called sortBy and not sort_by. Therefore the beginning of the fetch-call should look something like the line below:

 return fetch( `https://corsanywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=${term}&location=${location}&sort_by=${sortBy}`,

Another issue is that the second parameter of the fetch function needs to be wrapped in an object. Inside of that object there is a headers-key containing another object. The object/parameter should look like this (you omitted the outer curly-braces):

    {
    headers:{
        Authorization: `Bearer ${apiKey}`
      }
    }

Also when you are referencing jsonResponse.Businesses, businesses needs to be non-capitalized so change it to jsonResponse.businesses. You can always console.log the jsonResponse to see what you are dealing with as well but hopefully these things will help… Also, for future reference, remove the api-key before posting code in the forums and consider editing the post to delete it.

Thanks for your response it helped.

1 Like