Postman Activity

Introduction

This will be a quick activity to teach you how to use Postman to make and send POST and GET requests. We're going to use Twitter's API for this example.

Getting Ready

  1. You'll need Postman installed. If you haven't downloaded it already, go ahead and go to the previous page (here) and download it!
  2. You'll need a Twitter account. If you don't have a Twitter account, head to Twitter and make one.
  3. Twitter requires you add your mobile phone to your account before using the API. Click here for steps on how to do that.

Part 1- Set Up Oauth with Twitter

For security reasons, Twitter requires us to use OAuth in order to access it's API. This is like a secure way to "log in" for their API. To get that set up, we'll need to let Twitter know we intend to make an app.

  1. Go to this link which is the Twitter Application Management page, and "Create New App" Alt Text
  2. Fill out the details required and go ahead an accept the Terms and Services. You can leave the 'callback url' empty.

Alt Text

  1. Go to the "Keys and Access Tokens" Tab. You should already have a Consumer Key (API Key) and Consumer Secret (API Secret) already generated. Alt Text
  2. While still on that page, you need to create your own Access Token. You can find a button towards the bottom of the page that will let you generate a token. Alt Text
  3. Don't share these keys! They're called secrets for reason!

Part 2- OAuth in PostMan

  1. Now open up Postman, and go the authorization tab. Select OAuth 1.0 (That's what Twitter uses). Alt Text
  2. Fill in the 4 details from Step 5 into their respective spots. Alt Text
  3. Make sure you check the "Add Params to the Header" box. If you accidentally ran the request before checking this, you must clear your url parameters. You can do this by clicking the "Params" button and then clicking the X symbols.
  4. You have successfully set up OAuth on Postman to make requests to the Twitter API! Just click the orange "update request" box:

Part 3- Make the API Call

  1. First we'll make a GET request to see some tweets. This is the documentation page if you're curious.
  2. Copy the "Resource URL" that the documentation says to use into postman:

    https://api.twitter.com/1.1/statuses/user_timeline.json
    
  3. Now we need to add a paramater. For this request we should enter the "screen name" of the user we want to look up. Click the Params button in the url bar and add the screen_name paramater. You can enter the name of anybody on twitter (enter BoilerCamp if you can't think of anybody!). Alt Text

  4. Make sure your request type is GET
  5. Send it! You should see some data below with that person's tweets!

Part 4- Send us some tweets!

The @BoilerCamp twitter is pretty lonely all by itself. We'd definitely get super popular if a bunch of people used their PostMan skills to send us some tweets!

Here's how:

  1. We'll make a POST request this time since we're sending data. This is the documentation page if you're curious.
  2. Copy the "Resource URL" that the documentation says to use into postman:

    https://api.twitter.com/1.1/statuses/update.json
    
    1. Now we need to add the tweet itself. For this request we should enter a param called status. Click the Body tab and add the status paramater. Make sure to add this as form data! Otherwise some characters will cause an error. You can type in whatever you want. Tweet @BoilerCamp if you want to be extra cool(add that to the message)! Alt Text
  3. Make sure your request type is POST
  4. Send it! You should see some data below that's (hopefully) not an error message.

Part 5- Experiment!

Twitter has a very nice API with a LOT of different routes to try out. Seriously, just look at all these! If you're finished early, try testing some of these out. Just pick a route from the list on the left, add the resource URL listed on the page, and add any required paramaters. See what happens!

If you want a recap, you can listen to a Scottish guy explain all of this here.