This guide walks you through creating and deleting Posts using the X API.
PrerequisitesBefore you begin, you’ll need:
- A developer account with an approved App
- User Access Tokens (OAuth 1.0a or OAuth 2.0 PKCE)
Create a Post
Prepare your request
The POST /2/tweets endpoint requires a JSON body with at least text or media:{
"text": "Hello from the X API!"
}
Send the request
curl -X POST "https://api.x.com/2/tweets" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"text": "Hello from the X API!"}'
Review the response
A successful response includes the new Post’s id and text:{
"data": {
"id": "1445880548472328192",
"text": "Hello from the X API!"
}
}
Advanced examples
curl -X POST "https://api.x.com/2/tweets" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"text": "This is a reply!",
"reply": {
"in_reply_to_tweet_id": "1234567890"
}
}'
curl -X POST "https://api.x.com/2/tweets" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"text": "Check this out!",
"quote_tweet_id": "1234567890"
}'
First, upload media using the Media Upload endpoint, then reference the media_id:curl -X POST "https://api.x.com/2/tweets" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"text": "Photo of the day!",
"media": {
"media_ids": ["1234567890123456789"]
}
}'
curl -X POST "https://api.x.com/2/tweets" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"text": "What is your favorite color?",
"poll": {
"options": ["Red", "Blue", "Green", "Yellow"],
"duration_minutes": 1440
}
}'
Delete a Post
Get the Post ID
You need the ID of the Post you want to delete. This is returned when you create a Post.
Send a DELETE request
curl -X DELETE "https://api.x.com/2/tweets/1445880548472328192" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN"
Confirm deletion
{
"data": {
"deleted": true
}
}
You can only delete Posts that you authored.
Next steps