Authorization HTTP header for yelp fusion api access token

Authorization HTTP header for yelp fusion api access token
0

#1

I am currently working on the nightlife coordinator project and using the yelp fusion api. I have the access token but how do I use it.


#2

I used the following code (using request):

  request.get("https://api.yelp.com/v3/businesses/search?categories=bars&limit=50&location="+location+"&offset="+offset, {
    auth: {
      "bearer": access_token
    }
}

#3

How do you do it without request, like with JQuery or Vanilla Javascript


#4

I assumed you would use it with Node. Using the fetch API:

const access_token = "---------";

let myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer " + access_token);

fetch("https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?categories=bars&limit=50&location=New York", {
  headers: myHeaders 
}).then((res) => {
  return res.json();
}).then((json) => {
  console.log(json);
});

Note that I had to use cors-anywhere to avoid CORS issues.


#5

Thank you so much it has been a problem I have been trying to solve for awhile


#6

Edit: worked a treat. Thanks!