Posting and reading on the X API
The endpoints you’ll use most, and how pagination works.
Post a tweet
await fetch("https://api.x.com/2/tweets", {
method: "POST",
headers: {
"Authorization": `Bearer ${userAccessToken}`,
"Content-Type": "application/json"
},
body: JSON.stringify({ text: "Posted from my own client" })
});
Read a timeline
| Method | Endpoint | Returns |
|---|---|---|
| GET | /2/users/:id/tweets | A user’s posts |
| GET | /2/users/:id/mentions | Mentions of a user |
| POST | /2/tweets | Create a post |
Pagination
List endpoints return a meta.next_token. Pass it back as pagination_token to get the next page, and stop when it is absent.
Frequently asked questions
Which endpoint creates a post?
POST https://api.x.com/2/tweets with a JSON body containing a text field.
How does pagination work?
List endpoints return a meta.next_token. Pass it back as pagination_token to fetch the next page, and stop when it is absent.