Hello X Developers!
We’re excited to announce a highly requested feature: the ability to programmatically edit your posts using the X API! This update allows you to update the text of a recent post.
Requirements
As with editing posts on X, the authenticated user must have X Premium to edit original posts.
Read here for more details around editing posts on X.
Key Changes
- Endpoint: Use the existing POST
https://api.x.com/2/posts endpoint.
- New Field: Introduce the
edit_options object in the request body to specify the post you want to edit.
- Requirements: The
previous_post_id must refer to a post posted within the last hour (edit window), and you can only edit posts from your own account.
Example Request
HTTP Request:
- POST
https://api.x.com/2/posts
Request Body (JSON):
{
"text": "example edit",
"edit_options": {
"previous_post_id": "YOUR_RECENT_POST_ID"
}
}
Example with xurl CLI
For quick testing, you can use the xurl command-line tool:
xurl -H 'Content-type: application/json' -d '{"text":"example edit","edit_options":{"previous_post_id":"YOUR_RECENT_POST_ID"}}' -X POST '/2/posts' -tv
This feature builds on our commitment to giving developers more control over content management.
For full details, including error handling, limitations, and best practices, check out the updated API documentation at Create or Edit Post - X.
Thanks,
The X Developer Platform Team
3 Likes