Getting started with the batch compliance endpoints
Working with the batch compliance endpoints generally involves 5 steps:- Creating a compliance job
- Preparing the list of Post IDs or user IDs
- Uploading the list of Post IDs or user IDs
- Checking the status of the compliance job
- Downloading the results
Prerequisites
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 Post 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 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 X App on the developer portal.curl --request POST 'https://api.x.com/2/compliance/jobs' \ --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:
Step two: Prepare a list of Post IDs or user IDs
Create a text file with Post IDs or user IDs, where each line contains a Post ID or user ID. The contents of the text file can look something like this: 1417856744319971329 1415457498803232770 1415348607813832708 1413515358766452738 … …Note: The file above can either contain Post 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.
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 ID with your job ID from the first step.curl --request GET 'https://api.x.com/2/compliance/jobs/$ID' \ --header 'Authorization: Bearer $APP_ACCESS_TOKEN'
The response will include information about the job.