Getting started with the full-archive search endpoint

This quick start guide will help you make your first request to the full-archive search endpoint with a set of specified fields using Postman.

If you would like to see sample code in different languages, please visit our Twitter API v2 sample code GitHub repository. 
 

Prerequisites

The full-archive search endpoint is currently available as part of the Academic Research product track only. In order to use this endpoint, you must apply for access to the Academic Research product track

Once you are approved to use the Academic Research product track, you will see your academic project in the developer portal. From the projects and apps section, click on ‘Add App’ to connect your app to the academic project.

This image shows what an Academic Research Project looks like within the developer portal before you add an App

Then, you can either choose an existing App and connnect it to your project, or create a new App. 

This screenshot shows the screen where you can either choose a new App or an existing one:

This image shows the page where you can select to either add an existing or a new App to your Academic Research Project.

If you select to create a new App, next you will be asked to add an App name. The below screenshot shows you what this page will look like:

This image shows the page where you can add a name to your newly created App.

Once you've added an App name, you will receive you API Keys and Bearer Token. You should store these in your password manager, as you will be using these to make requests to the Twitter API endpoints. 

This image shows the page where you receive your API Keys and Bearer Token after you've created a new App.


Now that you have a set of API Keys and a Bearer Token set up in your Academic Research Project, you are ready to make your first request to the full-archive search endpoint. 

Steps to build a full-archive search request

Step one: Start with a tool or library

There are several different tools, code examples, and libraries that you can use to make a request to this endpoint, but we are going to use the Postman tool here to simplify the process.

To load Twitter API v2 Postman collection into your environment, please click on the following button:


Once you have the Twitter API v2 collection loaded in Postman, navigate to the Search Tweets > Full-archive search request.

Step two: Authenticate your request

To properly make a request to the Twitter API, you need to verify that you have permission to do so. To do this with the full-archive search endpoint, you must authenticate your request with an OAuth 2.0 Bearer Token.

First, from within the Full-archive search request in Postman, navigate to the “Authentication” tab. In the "Type" dropdown, select "Bearer Token", and then copy and paste your Bearer Token from your password manager into the "Token" field.
 

Step three: Create a search query

Each full-archive search query requires a single search query. For this example, we are going to use a query that matches on Tweets posted by the @TwitterDev account. For this query we use the from operator and set it to TwitterDev (case insensitive):

from:TwitterDev

In Postman, navigate to the "Params" tab and enter this ID, or a string of Tweet IDs separated by a comma, into the "Value" column of the ids parameter.
 

Key Value Description
query from:TwitterDev Search query to submit to the full-archive search endpoint


Step four: Identify and specify which fields you would like to retrieve

If you click the "Send" button after step three, you will receive the default Tweet object fields in your response: id and text.

If you would like to receive additional fields beyond id and text, you will have to specify those fields in your request with the field and/or expansion parameters.

For this exercise, we will request a four different sets of fields from different objects:

  1. The default Tweet object fields
  2. The additional tweet.created_at field in the primary user objects
  3. The associated authors’ user object’s default fields for the returned Tweets
  4. The additional user.description field in the associated user objects
     

In Postman, navigate to the "Params" tab and add the following key:value pair to the "Query Params" table:

Key Value Returned fields
tweet.fields created_at tweets.created_at
expansions author_id includes.users.id, includes.users.name, includes.users.username
user.fields description includes.users.description


You should now see the following URL next to the "Send" button:

      https://api.twitter.com/2/tweets/search/all?query=from:TwitterDev&tweet.fields=created_at&expansions=author_id&user.fields=created_at
    

Please note

By default, only 10 most recent Tweets will be returned. If you want more than 10 Tweets per request, you can use the max_results parameter and set it to a maximum of 500 Tweets per request. Similarly,  by default Tweets from the last 30 days will be returned. If you want to get Tweets that are older than 30 days, you can use the start_time and end_time parameters in your API call.


Step five: Make your request and review your response

Once you have everything set up, hit the "Send" button and you will receive a response similar to the following:

      {
   "data": [
       {
           "author_id": "2244994945",
           "created_at": "2020-06-11T16:05:06.000Z",
           "id": "1271111223220809728",
           "text": "Tune in tonight and watch as @jessicagarson takes us through running your favorite Python package in R. 🍿\n\nLearn how to use two powerful programming languages for data science together, and see a live example that uses the recent search endpoint from Twitter’s Developer Labs. https://t.co/v178oUZNuj"
       },
       {
           "author_id": "2244994945",
           "created_at": "2020-06-10T19:25:24.000Z",
           "id": "1270799243071062016",
           "text": "As we work towards building the new Twitter API, we’ve extended the deprecation timeline for several Labs v1 endpoints. Learn more 📖 https://t.co/rRWaJYJgKk"
       },
       {
           "author_id": "2244994945",
           "created_at": "2020-06-09T18:08:47.000Z",
           "id": "1270417572001976322",
           "text": "Annotations help you learn more about a Tweet — they can even help you find topics of interest. 🔬\n\nIn this tutorial, @suhemparack shows us how find Tweets related to COVID-19 using annotations + the filtered stream endpoint.\n\nLearn how you can, too. ⤵️\nhttps://t.co/qwVOgw0zSV"
       }
   ],
   "includes": {
       "users": [
           {
               "description": "The voice of Twitter's #DevRel team, and your official source for updates, news, & events about Twitter's API. \n\n#BlackLivesMatter",
               "id": "2244994945",
               "name": "Twitter Dev",
               "username": "TwitterDev"
           }
       ]
   },
   "meta": {
       "newest_id": "1271111223220809728",
       "oldest_id": "1270417572001976322",
       "result_count": 3
   }
}
    


In this example, we used a very simple query. If you would like to see more detailed guides, please visit the resources listed below.