Skip to main content
Access Posts endpoints via client.posts() (PostsClient).

Methods

create

POST /2/tweets Create or Edit Post Creates a new Post for the authenticated user, or edits an existing Post when edit_options are provided. Media in media.media_ids is attached in the order given; get the ids by uploading each image with Upload Media, or a video with Initialize Media Upload. Supports paid partnership disclosure via the paid_partnership field. To share a clip of another Post’s video, set clip to that Post’s id and a range of 5 to 60 seconds.

Parameters

Schemas.CreatePostsRequest
required
Request payload.
Returns: Schemas.CreatePostsResponse

createPostDraft

POST /2/posts/drafts Create Post Draft Saves a Post draft to the authenticated user’s X account without publishing it. Takes the body of Create or Edit Post, of which a draft stores text, media with tagged users, a reply and the AI and paid partnership disclosures. Any other field that is set is a 400 that names it.

Parameters

Schemas.CreatePostDraftRequest
required
Request payload.
Returns: Schemas.CreatePostDraftResponse

delete

DELETE /2/tweets/{id} Delete Post Deletes a specific Post by its ID, if owned by the authenticated user.

Parameters

String
required
id (path parameter).
Returns: Schemas.DeletePostsResponse

deletePostDraft

DELETE /2/posts/drafts/{id} Delete Post Draft Deletes one of the authenticated user’s Post drafts by its ID. The whole draft is deleted, including any part Get Post Drafts does not list, and cannot be restored. An ID that is not one of the user’s drafts also returns deleted: true.

Parameters

String
required
The ID of the draft to delete.
Returns: Schemas.DeletePostDraftResponse

getAnalytics

GET /2/tweets/analytics Get Post Analytics Retrieves analytics data for specified Posts within a defined time range.

Parameters

List<String>
required
ids (query parameter).
String
required
start_time (query parameter).
String
required
end_time (query parameter).
Returns: Schemas.GetPostsAnalyticsResponse

getById

GET /2/tweets/{id} Get Post by ID Retrieves details of a specific Post by its ID.

Parameters

String
required
id (path parameter).
Returns: Schemas.GetPostsByIdResponse

getByIds

GET /2/tweets Get Posts by IDs Retrieves details of multiple Posts by their IDs.

Parameters

List<String>
required
ids (query parameter).
Returns: Schemas.GetPostsByIdsResponse

getCountsAll

GET /2/tweets/counts/all Paginated Get Count of All Posts Retrieves the count of Posts matching a search query from the full archive. At most one of pagination_token, next_token may be provided.

Parameters

String
required
query (query parameter).
Returns: Schemas.GetPostsCountsAllResponse (use getCountsAllPages(...) for automatic Paginator<...> iteration)

getCountsRecent

GET /2/tweets/counts/recent Paginated Get Count of Recent Posts Retrieves the count of Posts from the last 7 days matching a search query. At most one of pagination_token, next_token may be provided.

Parameters

String
required
query (query parameter).
Returns: Schemas.GetPostsCountsRecentResponse (use getCountsRecentPages(...) for automatic Paginator<...> iteration)

getLikingUsers

GET /2/tweets/{id}/liking_users Paginated Get Liking Users Retrieves a list of Users who liked a specific Post by its ID.

Parameters

String
required
id (path parameter).
Returns: Schemas.GetPostsLikingUsersResponse (use getLikingUsersPages(...) for automatic Paginator<...> iteration)

getPostDrafts

GET /2/posts/drafts Paginated Get Post Drafts Returns the authenticated user’s Post drafts, newest first, in the fields of the Create or Edit Post body. thread holds the Posts after the first. A draft with unsupported_content is not listed in full: do not publish it from this list or delete it unless the user asks. Needs the tweet.write scope.

Parameters

Returns: Schemas.GetPostDraftsResponse (use getPostDraftsPages(...) for automatic Paginator<...> iteration)

getQuoted

GET /2/tweets/{id}/quote_tweets Paginated Get Quoted Posts Retrieves a list of Posts that quote a specific Post by its ID.

Parameters

String
required
id (path parameter).
Returns: Schemas.GetPostsQuotedPostsResponse (use getQuotedPages(...) for automatic Paginator<...> iteration)

getRepostedBy

GET /2/tweets/{id}/retweeted_by Paginated Get Reposted By Retrieves a list of Users who reposted a specific Post by its ID.

Parameters

String
required
id (path parameter).
Returns: Schemas.GetPostsRepostedByResponse (use getRepostedByPages(...) for automatic Paginator<...> iteration)

getReposts

GET /2/tweets/{id}/retweets Paginated Get Reposts Retrieves a list of Posts that repost a specific Post by its ID.

Parameters

String
required
id (path parameter).
Returns: Schemas.GetPostsRepostsResponse (use getRepostsPages(...) for automatic Paginator<...> iteration)

hideReply

PUT /2/tweets/{tweet_id}/hidden Hide Reply Hides or unhides a reply to a conversation owned by the authenticated user.

Parameters

String
required
tweet_id (path parameter).
Schemas.HidePostsReplyRequest
required
Request payload.
Returns: Schemas.HidePostsReplyResponse

searchAll

GET /2/tweets/search/all Paginated Search All Posts Retrieves Posts from the full archive matching a search query. At most one of start_time, since_id may be provided. At most one of end_time, until_id may be provided. At most one of pagination_token, next_token may be provided.

Parameters

String
required
query (query parameter).
Returns: Schemas.SearchPostsAllResponse (use searchAllPages(...) for automatic Paginator<...> iteration)

searchRecent

GET /2/tweets/search/recent Paginated Search Recent Posts Retrieves Posts from the last 7 days matching a search query. At most one of start_time, since_id may be provided. At most one of end_time, until_id may be provided. At most one of pagination_token, next_token may be provided.

Parameters

String
required
query (query parameter).
Returns: Schemas.SearchPostsRecentResponse (use searchRecentPages(...) for automatic Paginator<...> iteration)