Tutorials

Getting started with Postman

Relevant products

Introduction

Postman is a REST client that allows us to make requests to APIs inside of a user interface. This can be helpful when you are working with a new endpoint. To get started with Postman, you first need to apply for a Twitter Developer account. After your account gets approved, you’ll need to create an app

For this example, you’ll be using the Tweets and Users preview for Twitter Developer Labs. You’ll need to first enroll in Labs and attach the app you created to this preview. You’ll also need to create a bearer token using the credentials you just created.

Working with Postman

First, you’ll need to download Postman. You can download the Postman collection for Labs to help you get up and running a bit faster. Once you have your collection downloaded, you can modify the Tweets and Users example which is in a folder called Tweets and Users v2. Select the example called GET Single user by username.

You will need to adjust the path variables to include the username you’re looking for. Where it says Path Variables and change the value to include a Twitter handle you want to see the payload of. This example uses the handle TwitterDev. 

This should look like this:

Before you can press the blue send button you’ll need to adjust your authentication settings. If you click on the tab that says Authorization. Under type, you’ll need to select Bearer Token. You can add the bearer token you’ve created into the box next to the word Token.

The full address you’ll have typed in is:

https://api.twitter.com/labs/2/users/by/username/:username

After you’ve added in your bearer token, submit your request by pressing the blue button that says send.

Now you should see something that looks like the following payload:

      {
    "data": {
        "id": "2244994945",
        "name": "Twitter Dev",
        "username": "TwitterDev"
    }
}


    

You can add an expansion to your request which allows you to request additional referenced objects and their fields in a single response. Under where it says Query Params you will want to check the box next to the word expansions and type in pinned_tweet_id under the word value in the folder called Params.

At this point the address you should have typed in should look like this:

https://api.twitter.com/labs/2/users/by/username/:username?expansions=pinned_tweet_id

Now you can press the button that says send to get back a payload that should look similar to the following:

      {
    "data": {
        "id": "2244994945",
        "name": "Twitter Dev",
        "pinned_tweet_id": "1214281000932593667",
        "username": "TwitterDev"
    },
    "includes": {
        "tweets": [
            {
                "id": "1214281000932593667",
                "text": "Hello… is it me you’re searching for? 🔎\n\nSearch the conversation as it unfolds with this new addition to Labs. We're making it easier than ever to find the Tweets you care about. https://t.co/HmuuUC6PKZ https://t.co/QgEXeL9XzX"
            }
        ]
    }
}

    

Learning more about a Tweet

You’ve now made your first few requests. Congratulations! 

To make your next request, you’ll use GET Tweets to learn more about the most recent Tweet from TwitterDev. To set up, you’ll need to click on the sample request entitled GET Tweets from the folder you were using before.

You’ll first need to modify the URL as you did earlier by checking the box under where it says Path Variables in the folder called Params. In your last example, you saw that the most recent Tweet ID was 1175170649968349184 by looking at the key-value pair from your JSON "pinned_tweet_id": "1214281000932593667". 

The fields parameter provides a way to specify which additional fields of data return with an API response using the Labs v2 endpoints. We select the box entitled tweet.fields and type in the following under the word value:

attachments,author_id,created_at,entities,geo,id,in_reply_to_user_id,lang,possibly_sensitive,public_metrics,referenced_tweets,source,text,withheld

You’ll also need to update authentication settings, as you did in the previous request, using the same bearer token you created earlier in this process.

After you’ve made your changes you’re ready to press the blue send button. After you do so, you should see the following payload:

      {
    "data": {
        "attachments": {
            "media_keys": [
                "16_1214280974223237120"
            ]
        },
        "author_id": "2244994945",
        "created_at": "2020-01-06T20:22:05.000Z",
        "entities": {
            "urls": [
                {
                    "start": 179,
                    "end": 202,
                    "url": "https://t.co/HmuuUC6PKZ",
                    "expanded_url": "https://twittercommunity.com/t/new-recent-search-endpoint-available-in-labs/133076",
                    "display_url": "twittercommunity.com/t/new-recent-s…"
                },
                {
                    "start": 203,
                    "end": 226,
                    "url": "https://t.co/QgEXeL9XzX",
                    "expanded_url": "https://twitter.com/TwitterDev/status/1214281000932593667/photo/1",
                    "display_url": "pic.twitter.com/QgEXeL9XzX"
                }
            ]
        },
        "id": "1214281000932593667",
        "lang": "en",
        "possibly_sensitive": false,
        "public_metrics": {
            "retweet_count": 60,
            "reply_count": 39,
            "like_count": 149,
            "quote_count": 13
        },
        "source": "Twitter Web App",
        "text": "Hello… is it me you’re searching for? 🔎\n\nSearch the conversation as it unfolds with this new addition to Labs. We're making it easier than ever to find the Tweets you care about. https://t.co/HmuuUC6PKZ https://t.co/QgEXeL9XzX"
    }

    

What's next

If you click on the button in Postman that says code, you can turn the request we just created into the language of your choosing such as Python, Node or Ruby to help you get started. Postman has great documentation that might be helpful. You can also check our sample code on GitHub. Be sure to also check out our documentation on Labs to learn more.

Ready to build your solution?

Apply for developer access to get started