Getting started with the batch compliance endpoints

Working with the batch compliance endpoints generally involves 5 steps:

  1. Creating a compliance job
  2. Preparing the list of Tweet IDs or user IDs
  3. Uploading the list of Tweet IDs or user IDs
  4. Checking the status of the compliance job
  5. Downloading the results


In this section, we will learn how to go through each of these steps using the command line. If you would like to see sample code in different programming languages, please visit our Twitter API v2 sample code GitHub repository.


To complete this guide, you will need to have a set of keys and tokens to authenticate your request. You can generate these keys and tokens by following these steps:

  • Sign up for a developer account and receive approval.
  • Create a Project and an associated developer App in the developer portal.
  • Navigate to your App's “Keys and tokens” page to generate the required credentials. Make sure to save all credentials in a secure location.


Step one: Create a compliance job

First, you will have to create a compliance job and specify whether you will be uploading Tweet IDs or user IDs (using the type parameter). Optionally, you can also give your job a name (using the name parameter). 

To authorize this request, you will need to use OAuth 2.0 App-Only. To do so, make sure to replace the $APP_ACCESS_TOKEN below with your App Access Token that you can generate in your Twitter App on the developer portal.


      curl --request POST '' \
--header 'Authorization: Bearer $APP_ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{"type": "tweets"}'


If your API call is successful, you will get a response similar to the following:


   "data": {
       "download_expires_at": "2021-08-18T19:42:55.000Z",
       "status": "created",
       "upload_url": "",
       "created_at": "2021-08-11T19:42:55.000Z",
       "resumable": false,
       "id": "1425543269983784962",
       "type": "tweets",
       "download_url": "",
       "upload_expires_at": "2021-08-11T19:57:55.000Z"

Take note of the value from the upload_url, download_url, and id fields; you will need those in the following steps.


Step two: Prepare a list of Tweet IDs or user IDs

Create a text file with Tweet IDs or user IDs, where each line contains a Tweet ID or user ID. The contents of the text file can look something like this:





. . .

. . .

Note: The file above can either contain Tweet IDs or User IDs and can not be a mix of both.

You can upload your file directly to this URL via a PUT request. Note that the URL is already signed with an authentication token, which means you will not authenticate by passing your App Access Token again. Make sure to pass a Content-Type header to signal you are uploading a text file and replace the $FILE_LOCATION below with the path to your file.

      curl -X PUT  \
 -H "Content-Type: text/plain" \
 --data-binary @$FILE_LOCATION \

A status code 200 will indicate that the upload was successful.


Step three (optional): Check your job status

Large uploads may take some time to process. You can request a status update from the content compliance job endpoint by specifying the job ID you received in the first step.

Again, make sure to replace the $APP_ACCESS_TOKEN below with your App Access Token, and replace the $ID with your job ID from the first step.

      curl --request GET '$ID' \
--header 'Authorization: Bearer $APP_ACCESS_TOKEN'

The response will include information about the job.

   "data": {
       "upload_expires_at": "2021-08-05T01:50:11.000Z",
       "type": "tweets",
       "resumable": false,
       "download_url": "",
       "id": "1423095206576984067",
       "status": "expired",
       "created_at": "2021-08-05T01:35:11.000Z",
       "upload_url": "",
       "download_expires_at": "2021-08-12T01:35:11.000Z"

A complete status means the results are ready for you to download. Note: The other values of statuses can be created, complete, in_progress, failed and expired


Step four: Download the results

As you receive a job completion status, you can download the compliance results from the URL indicated in the download_url field (also generated in the first step). This URL is already signed with an authentication token, which means you will not need authenticate by passing your App Access Token again.

      curl --request GET \

The result will contain a set of JSON objects (one object per line). Each object will contain a Tweet or user ID, the Tweet or user’s creation date (useful to locate Tweets organized by date), required action, the reason for the compliance action, and its date:


Your code can parse each JSON line to locate the Tweet or user ID and delete the Tweets and users with those IDs from your dataset to stay in compliance. If there is no corresponding JSON object for an ID you uploaded, you can assume that ID is in compliance.

Note: Not all compliance events will include the redacted_atfield.