How to get a Yelp Fusion API access token with a POST request

jackLyons API's Tags: ,
3
Yelp Fusion API access token background image

Just recently I watched an awesome video by Wes Bos where he built a cool typeahead app using some USA city data. It was part of his JavaScript 30 program, which is a watch and learn video series. I wanted to extend his code further by linking up the city data with some “Things to do” and “Top Restaurants” information. That lead me to look up Yelp and find out about their latest API release, Yelp FUSION.

Yelp FUSION is a pretty sweet API. You can unlock data from over 50 million businesses around the world! The only catch is that you need to obtain an access token. This isn’t really a big deal, however when looking into the “Getting Started” docs, I didn’t quite find the proper instructions or a demo to follow along.

In this post I will guide you, step by step, towards getting your API access token. I’ll also show you a cool website called RapidAPI where you can test your endpoints and view the returned data. You can view my current source code on GitHub here. It’s a work in progress, but soon enough I’ll have a fully functional version deployed so you can play around with it properly.

How to get a Yelp Fusion API access token with a POST request

Things you will need:

  1. POSTMAN – platform to make your API development faster & easier.
  2. JSON VIEWER (Chrome) – A great tool for viewing JSON code in your browser (google for other browsers).
  3. YELP FUSION Docs – The official Yelp FUSION docs in case you get stuck or want to learn more.
  4. Register your app – Simply follow the prompts to register your app and get a Client ID / Secret

Step 1: Register your app and get your Client ID / Secret Key

Most API’s require you to register your application. This isn’t a big deal, especially if you are building something small for fun on a non-commercial basis. To register, simply go to the registration page on the Yelp FUSION website. Once registered, you will get a Client Secret and Client ID.

Please keep the client id and secret to yourself since they are credentials for your call to Yelp’s API.

Step 2: Configure POSTMAN

Now this is where I got a little lost at first; the doc’s don’t really go into enough detail to make this step possible. I want this tutorial to be beginner friendly, so I will do my best to explain the next few steps carefully. Firstly, you are given an endpoint to use, but there are few other bits that need to go along with it. You also need to do a POST request, which can be tricky if you’re a front end developer who never touches backend server code. You need three things along with the following endpoint:

 

2. grant_type : client_credentials is the value required.
3. client_id : The client id for you app with Yelp.
4. client_secret : The client secret for you app with Yelp.

 

You will need to open up POSTMAN to begin the next step.

 

Step 3: Create POST REQUEST

POSTMAN is really easy to use, especially for this demonstration. If you have any trouble please see the screenshot image below. Here are the steps to take to obtain your access token.

  1.  You will need to select POST from the dropdown menu next to the URL field.
  2. Enter the ENDPOINT into the URL field.
  3. Click BODY and select x-wwwform-url-encoded. For more information on what this means exactly, please refer to this Stack Overflow post.
  4. In POSTMAN you need to provide the client ID, grant type and secret values as key/value pairs. Below the URL field you will see the key / value input fields. Add them in there and click Send.

 

See the screenshot below to get a better idea of what I mean.

POSTMAN instruction on how to access the Yelp FUSION API

Step 4: Test a Yelp API endpoint

Another simple tool that I love using to test API calls is called RadpidAPIIt’s a no fuss solution for anyone who want’s to quickly check out the returned data from an endpoint. Of course, you can also use POSTMAN, which I will also detail below. But I find the RapidAPI tool to be, well… rapid. You can install the Rapid API config into your app to make things easier, too.

Sign up for free and play around with different endpoints by clicking getBusinsses, entering some basic info like a city and then clicking TEST FUNCTION. See the screenshot below for details:

Yelp FUSION with RapidAPI

 

Using POSTMAN, your get request will look like this:


https://api.yelp.com/v3/businesses/search?term=restaurant&location=boulder&Authorization=Bearer [YOUR ACCESS TOKEN]

Throw in some search terms, for example, restaurants in Boulder, CO.

One important thing to note is that when adding the Authorization TOKEN (your access token), you will need a SPACE between the word “Bearer” and your access token. See the screenshot below to see what it would look like:

Screenshot of POSTMAN using the Yelp FUSION API

 

The returned results should be in valid JSON, like so:


"businesses": [
    {
      "id": "mountain-sun-pub-and-brewery-boulder",
      "name": "Mountain Sun Pub & Brewery",
      "image_url": "https://s3-media1.fl.yelpcdn.com/bphoto/41ZBtK1LODDsZ2eiqz3hyQ/o.jpg",
      "is_closed": false,
      "url": "https://www.yelp.com/biz/mountain-sun-pub-and-brewery-boulder?adjust_creative=gHvFWA1xRpDFQyFoKrwyWQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=gHvFWA1xRpDFQyFoKrwyWQ",
      "review_count": 977,
      "categories": [
        {
          "alias": "pubs",
          "title": "Pubs"
        },
        {
          "alias": "burgers",
          "title": "Burgers"
        },
        {
          "alias": "breweries",
          "title": "Breweries"
        }
      ],
      "rating": 4.5,
      "coordinates": {
        "latitude": 40.01916,
        "longitude": -105.2753
      },
      "transactions": [],
      "price": "$$",
      "location": {
        "address1": "1535 Pearl St",
        "address2": "",
        "address3": "",
        "city": "Boulder",
        "zip_code": "80302",
        "country": "US",
        "state": "CO",
        "display_address": [
          "1535 Pearl St",
          "Boulder, CO 80302"
        ]
      },
      "phone": "+13035460886",
      "display_phone": "(303) 546-0886",
      "distance": 2690.53082215
    } // ... and so on

Now you have access to the Yelp FUSION API 🙂

From here on in, anything is possible. Click here to view the Yelp doc’s for Business endpoints.

You can view my current source code on GitHub here. It’s a work in progress, but soon enough I’ll have a fully functional version deployed so you can play around with it. If you have any extra questions or comments, please don’t hesitate: leave them in the comments box below. If you know someone who might benefit from this post, please share it 🙂


The Web Developers Bootcamp.

A n00b friendly guide to becoming a pro!

If you’re feeling a bit overwhelmed and a little lost with all these crazy hard Free Code Camp exercises then this course is for you!

While I am oh so grateful for the opportunity to learn through Free Code Camp, I still find that learning to code alone and without proper guidance extremely exhausting. Which is why I’ve started to substitute my education with an incredible online resource called the Web Developers Bootcamp courtesy of Udemy.

This course has helped me brush off the cobwebs, unlearn my self-taught bad habits and gain a solid understanding of the true fundamentals of web development. It has helped me see why it is important to understand these JavaScript problems and how they apply to the real world.

This bootcamp will teach you how built beautiful sites with Bootstrap, add in functionality with JavaScript and write back end code with Node.js all in a series of short, sharp, no BS video modules. I seriously could not recommend it any higher. Check it out and let me know what you think 🙂

The Web Developers Bootcamp
The Web Developer Bootcamp.
The only course you need to learn web development – HTML, CSS, JS, Node, and More!

  • Joey Slomowitz

    Dude! thank you so much for this

    • You’re welcome, I’m glad it helped. What are you working on?

  • fabian django

    I do like this post. Explanations are clear and very detailed.

Sign up to receive up-to-date web tips, tricks and code hacks!