Getting started with the manage Posts endpoints
This quick start guide will help you make your first request to the manage Posts endpoints using Postman.
Please visit our X API v2 sample code GitHub repository if you want to see sample code in different languages.
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.
Steps to building manage Posts requests
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 X API v2 Postman collection into your environment, please click on the following button:
Once you have the X API v2 collection loaded in Postman, navigate to the “Manage Posts” folder, and select “Create a Post”.
Step two: Authenticate your request
To properly make a request to the X API, you need to verify that you have permission to do so. To do this with the manage Posts endpoints, you must authenticate your request using either OAuth 1.0a User Context or OAuth 2.0 Authorization Code with PKCE.
In this example, we are going to use OAuth 1.0a User Context.
You must add your keys and tokens (and specifically your API Key, API Secret Key, OAuth 1.0a user Access Token, and OAuth 1.0a user Access Token Secret) to Postman. You can do this by selecting the environment named “X API v2” (in the top-right corner of Postman), and adding your keys and tokens to the "initial value" and "current value" fields (by clicking the eye icon next to the environment dropdown).
If you've done this correctly, these variables will automatically be pulled into the request's authorization tab.
Step three: Specify the text of the Post
When creating a new Post with this endpoint, text or media for the Post are the required body parameters.
In Postman, navigate to the “Body” tab and enter the text of the Post as the value for the text
parameter. Additionally, if you wish to add parameters for items such as polls, replying to a Post ID, or adding reply settings you can also do so here. You can learn more about what’s available in our API reference guide.
Key | Value | Parameter type |
text |
Hello world! | body |
Step four: Identify and specify which fields you would like to retrieve
Once you have everything set up, hit the "Send" button, and you will receive a similar response to the following example response:
{
"data": {
"id": "1445880548472328192",
"text": "Hello world!"
}
}
If the returned response object contains an id
and the text
of your Post, you have successfully created a Post.
Step five: Delete your Post
To delete a Post, select the “Delete a Post” request also found in the “Manage Posts” folder of the X API v2 collection loaded in Postman. This endpoint requires the ID of the Post you wish to delete. Then, in the “Params” tab, enter the ID of the Post you wish to delete as the value for the id
column.
On successful delete request, you will receive a response similar to the following example:
{
"data": {
"deleted" : true
}
}