Skip to main content
This guide walks you through making your first Post lookup request using the X API v2.
PrerequisitesBefore you begin, you’ll need:
  • A developer account with an approved App
  • Your App’s Bearer Token (found in the Developer Console under “Keys and tokens”)

1

Find a Post ID

Every Post has a unique ID. You can find it in the Post’s URL:
https://x.com/XDevelopers/status/1228393702244134912
                                └── This is the Post ID
2

Make a request

cURL
curl "https://api.x.com/2/tweets/1228393702244134912" \
  -H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client

client = Client(bearer_token="YOUR_BEARER_TOKEN")

# Get a single Post by ID
response = client.posts.get("1228393702244134912")
print(response.data)
import { Client } from "@xdevplatform/xdk";

const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });

const response = await client.posts.get("1228393702244134912");
console.log(response.data);
3

Review the response

The default response includes the Post’s id, text, and edit_history_tweet_ids:
{
  "data": {
    "id": "1228393702244134912",
    "text": "What did the developer write in their Valentine's card?\n\nwhile(true) {\n    I = Love(You);\n}",
    "edit_history_tweet_ids": ["1228393702244134912"]
  }
}
4

Request additional fields

Use query parameters to get more data:
cURL
curl "https://api.x.com/2/tweets/1228393702244134912?\
tweet.fields=created_at,public_metrics,author_id&\
expansions=author_id&\
user.fields=username,verified" \
  -H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client

client = Client(bearer_token="YOUR_BEARER_TOKEN")

# Get a Post with additional fields and expansions
response = client.posts.get(
    "1228393702244134912",
    tweet_fields=["created_at", "public_metrics", "author_id"],
    expansions=["author_id"],
    user_fields=["username", "verified"]
)

print(response.data)
print(response.includes)  # Contains author user object
import { Client } from "@xdevplatform/xdk";

const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });

const response = await client.posts.get("1228393702244134912", {
  tweetFields: ["created_at", "public_metrics", "author_id"],
  expansions: ["author_id"],
  userFields: ["username", "verified"],
});

console.log(response.data);
console.log(response.includes); // Contains author user object
Response:
{
  "data": {
    "id": "1228393702244134912",
    "text": "What did the developer write in their Valentine's card?...",
    "created_at": "2020-02-14T19:00:55.000Z",
    "author_id": "2244994945",
    "public_metrics": {
      "retweet_count": 156,
      "reply_count": 23,
      "like_count": 892,
      "quote_count": 12
    },
    "edit_history_tweet_ids": ["1228393702244134912"]
  },
  "includes": {
    "users": [
      {
        "id": "2244994945",
        "username": "XDevelopers",
        "verified": true
      }
    ]
  }
}
5

Look up multiple Posts

Retrieve up to 100 Posts in a single request:
cURL
curl "https://api.x.com/2/tweets?\
ids=1228393702244134912,1227640996038684673,1199786642791452673&\
tweet.fields=created_at,author_id" \
  -H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client

client = Client(bearer_token="YOUR_BEARER_TOKEN")

# Get multiple Posts by IDs
response = client.posts.get_posts(
    ids=["1228393702244134912", "1227640996038684673", "1199786642791452673"],
    tweet_fields=["created_at", "author_id"]
)

for post in response.data:
    print(f"{post.id}: {post.text[:50]}...")
import { Client } from "@xdevplatform/xdk";

const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });

const response = await client.posts.getPosts({
  ids: ["1228393702244134912", "1227640996038684673", "1199786642791452673"],
  tweetFields: ["created_at", "author_id"],
});

response.data?.forEach((post) => {
  console.log(`${post.id}: ${post.text?.slice(0, 50)}...`);
});

Next steps

Integration guide

Learn authentication, rate limits, and best practices

Fields and expansions

Master the fields and expansions system

API Reference

See all available parameters

Sample code

Explore more examples