Skip to main content
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

1

Prepare your request

The POST /2/tweets endpoint requires a JSON body with at least text or media:
{
  "text": "Hello from the X API!"
}
2

Send the request

cURL
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!"}'
3

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
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
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
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
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

1

Get the Post ID

You need the ID of the Post you want to delete. This is returned when you create a Post.
2

Send a DELETE request

cURL
curl -X DELETE "https://api.x.com/2/tweets/1445880548472328192" \
  -H "Authorization: Bearer $USER_ACCESS_TOKEN"
3

Confirm deletion

{
  "data": {
    "deleted": true
  }
}
You can only delete Posts that you authored.

Next steps