> ## Documentation Index
> Fetch the complete documentation index at: https://docs.x.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PostsClient

> Methods for X API v2 Posts endpoints.

Access **Posts** endpoints via `client.posts()` (`PostsClient`).

## Methods

| Method | Endpoint | Behavior | Summary |
| :- | :- | :- | :- |
| [`create`](#create) | `POST /2/tweets` | Standard | Create or Edit Post |
| [`createPostDraft`](#createpostdraft) | `POST /2/posts/drafts` | Standard | Create Post Draft |
| [`delete`](#delete) | `DELETE /2/tweets/{id}` | Standard | Delete Post |
| [`deletePostDraft`](#deletepostdraft) | `DELETE /2/posts/drafts/{id}` | Standard | Delete Post Draft |
| [`getAnalytics`](#getanalytics) | `GET /2/tweets/analytics` | Standard | Get Post Analytics |
| [`getById`](#getbyid) | `GET /2/tweets/{id}` | Standard | Get Post by ID |
| [`getByIds`](#getbyids) | `GET /2/tweets` | Standard | Get Posts by IDs |
| [`getCountsAll`](#getcountsall) | `GET /2/tweets/counts/all` | Paginated | Get Count of All Posts |
| [`getCountsRecent`](#getcountsrecent) | `GET /2/tweets/counts/recent` | Paginated | Get Count of Recent Posts |
| [`getLikingUsers`](#getlikingusers) | `GET /2/tweets/{id}/liking_users` | Paginated | Get Liking Users |
| [`getPostDrafts`](#getpostdrafts) | `GET /2/posts/drafts` | Paginated | Get Post Drafts |
| [`getQuoted`](#getquoted) | `GET /2/tweets/{id}/quote_tweets` | Paginated | Get Quoted Posts |
| [`getRepostedBy`](#getrepostedby) | `GET /2/tweets/{id}/retweeted_by` | Paginated | Get Reposted By |
| [`getReposts`](#getreposts) | `GET /2/tweets/{id}/retweets` | Paginated | Get Reposts |
| [`hideReply`](#hidereply) | `PUT /2/tweets/{tweet_id}/hidden` | Standard | Hide Reply |
| [`searchAll`](#searchall) | `GET /2/tweets/search/all` | Paginated | Search All Posts |
| [`searchRecent`](#searchrecent) | `GET /2/tweets/search/recent` | Paginated | Search Recent Posts |

## `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.

```java theme={null}
import com.x.xdk.Schemas;
import com.x.xdk.XClient;

XClient client = XClient.builder()
    .accessToken(System.getenv("X_ACCESS_TOKEN"))
    .build();

var response = client.posts().create(new Schemas.CreatePostsRequest().text("Hello from XDK!"));
System.out.println(response);
```

### Parameters

**body** `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.

```java theme={null}
import com.x.xdk.Schemas;
import com.x.xdk.XClient;

XClient client = XClient.builder()
    .accessToken(System.getenv("X_ACCESS_TOKEN"))
    .build();

var response = client.posts().createPostDraft(new Schemas.CreatePostDraftRequest().text("Hello from XDK!"));
System.out.println(response);
```

### Parameters

**body** `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.

```java theme={null}
import com.x.xdk.XClient;

XClient client = XClient.builder()
    .accessToken(System.getenv("X_ACCESS_TOKEN"))
    .build();

var response = client.posts().delete("1895000000000000000");
System.out.println(response);
```

### Parameters

**id** `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.

```java theme={null}
import com.x.xdk.XClient;

XClient client = XClient.builder()
    .accessToken(System.getenv("X_ACCESS_TOKEN"))
    .build();

var response = client.posts().deletePostDraft("1895000000000000000");
System.out.println(response);
```

### Parameters

**id** `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.

```java theme={null}
import com.x.xdk.XClient;
import java.util.List;

XClient client = XClient.builder()
    .accessToken(System.getenv("X_ACCESS_TOKEN"))
    .build();

var response = client.posts().getAnalytics(
    List.of("1895000000000000000"),
    "2026-01-01T00:00:00Z",
    "2026-01-02T00:00:00Z"
);
System.out.println(response);
```

### Parameters

**ids** `List\<String\>` *required*

`ids` (query parameter).

**startTime** `String` *required*

`start_time` (query parameter).

**endTime** `String` *required*

`end_time` (query parameter).

**Optional parameters (PostsClient.GetAnalyticsOptions — 2)**

**options.granularity** `String`

`granularity` (query parameter).

**options.analyticsFields** `List\<String\>`

A comma separated list of Analytics fields to display.

**Returns:** `Schemas.GetPostsAnalyticsResponse`

***

## `getById`

GET `/2/tweets/{id}`

**Get Post by ID**

Retrieves details of a specific Post by its ID.

```java theme={null}
import com.x.xdk.XClient;

XClient client = XClient.builder()
    .bearerToken(System.getenv("X_BEARER_TOKEN"))
    .build();

var response = client.posts().getById("1895000000000000000");
System.out.println(response);
```

### Parameters

**id** `String` *required*

`id` (path parameter).

**Optional parameters (PostsClient.GetByIdOptions — 6)**

**options.postFields** `List\<String\>`

A comma separated list of Post fields to display.

**options.expansions** `List\<String\>`

A comma separated list of fields to expand.

**options.userFields** `List\<String\>`

A comma separated list of User fields to display.

**options.mediaFields** `List\<String\>`

A comma separated list of Media fields to display.

**options.pollFields** `List\<String\>`

A comma separated list of Poll fields to display.

**options.placeFields** `List\<String\>`

A comma separated list of Place fields to display.

**Returns:** `Schemas.GetPostsByIdResponse`

***

## `getByIds`

GET `/2/tweets`

**Get Posts by IDs**

Retrieves details of multiple Posts by their IDs.

```java theme={null}
import com.x.xdk.XClient;
import java.util.List;

XClient client = XClient.builder()
    .bearerToken(System.getenv("X_BEARER_TOKEN"))
    .build();

var response = client.posts().getByIds(List.of("1895000000000000000"));
System.out.println(response);
```

### Parameters

**ids** `List\<String\>` *required*

`ids` (query parameter).

**Optional parameters (PostsClient.GetByIdsOptions — 6)**

**options.postFields** `List\<String\>`

A comma separated list of Post fields to display.

**options.expansions** `List\<String\>`

A comma separated list of fields to expand.

**options.userFields** `List\<String\>`

A comma separated list of User fields to display.

**options.mediaFields** `List\<String\>`

A comma separated list of Media fields to display.

**options.pollFields** `List\<String\>`

A comma separated list of Poll fields to display.

**options.placeFields** `List\<String\>`

A comma separated list of Place fields to display.

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

```java theme={null}
import com.x.xdk.XClient;

XClient client = XClient.builder()
    .bearerToken(System.getenv("X_BEARER_TOKEN"))
    .build();

for (var page : client.posts().getCountsAllPages("from:XDevelopers")) {
    System.out.println(page);
}
```

### Parameters

**query** `String` *required*

`query` (query parameter).

**Optional parameters (PostsClient.GetCountsAllOptions — 8)**

**options.startTime** `String`

`start_time` (query parameter).

**options.endTime** `String`

`end_time` (query parameter).

**options.sinceId** `String`

`since_id` (query parameter).

**options.untilId** `String`

`until_id` (query parameter).

**options.nextToken** `String`

A base32hex-encoded pagination token.

**options.paginationToken** `String`

A base32hex-encoded pagination token.

**options.granularity** `String`

`granularity` (query parameter).

**options.searchCountFields** `String`

`search_count.fields` (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.

```java theme={null}
import com.x.xdk.XClient;

XClient client = XClient.builder()
    .bearerToken(System.getenv("X_BEARER_TOKEN"))
    .build();

for (var page : client.posts().getCountsRecentPages("from:XDevelopers")) {
    System.out.println(page);
}
```

### Parameters

**query** `String` *required*

`query` (query parameter).

**Optional parameters (PostsClient.GetCountsRecentOptions — 8)**

**options.startTime** `String`

Must be within the last 7 days.

**options.endTime** `String`

`end_time` (query parameter).

**options.sinceId** `String`

`since_id` (query parameter).

**options.untilId** `String`

`until_id` (query parameter).

**options.nextToken** `String`

A base32hex-encoded pagination token.

**options.paginationToken** `String`

A base32hex-encoded pagination token.

**options.granularity** `String`

`granularity` (query parameter).

**options.searchCountFields** `String`

`search_count.fields` (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.

```java theme={null}
import com.x.xdk.XClient;

XClient client = XClient.builder()
    .accessToken(System.getenv("X_ACCESS_TOKEN"))
    .build();

for (var page : client.posts().getLikingUsersPages("1895000000000000000")) {
    System.out.println(page);
}
```

### Parameters

**id** `String` *required*

`id` (path parameter).

**Optional parameters (PostsClient.GetLikingUsersOptions — 5)**

**options.maxResults** `Integer`

`max_results` (query parameter).

**options.paginationToken** `String`

A base32hex-encoded pagination token.

**options.userFields** `List\<String\>`

A comma separated list of User fields to display.

**options.expansions** `List\<String\>`

A comma separated list of fields to expand.

**options.postFields** `List\<String\>`

A comma separated list of Post fields to display.

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

```java theme={null}
import com.x.xdk.XClient;

XClient client = XClient.builder()
    .accessToken(System.getenv("X_ACCESS_TOKEN"))
    .build();

for (var page : client.posts().getPostDraftsPages()) {
    System.out.println(page);
}
```

### Parameters

**Optional parameters (PostsClient.GetPostDraftsOptions — 2)**

**options.maxResults** `Integer`

The maximum number of drafts to return.

**options.paginationToken** `String`

The meta.next\_token of the previous page.

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

```java theme={null}
import com.x.xdk.XClient;

XClient client = XClient.builder()
    .bearerToken(System.getenv("X_BEARER_TOKEN"))
    .build();

for (var page : client.posts().getQuotedPages("1895000000000000000")) {
    System.out.println(page);
}
```

### Parameters

**id** `String` *required*

`id` (path parameter).

**Optional parameters (PostsClient.GetQuotedOptions — 9)**

**options.maxResults** `Integer`

`max_results` (query parameter).

**options.paginationToken** `String`

A base32hex-encoded pagination token.

**options.exclude** `List\<String\>`

`exclude` (query parameter).

**options.postFields** `List\<String\>`

A comma separated list of Post fields to display.

**options.expansions** `List\<String\>`

A comma separated list of fields to expand.

**options.userFields** `List\<String\>`

A comma separated list of User fields to display.

**options.mediaFields** `List\<String\>`

A comma separated list of Media fields to display.

**options.pollFields** `List\<String\>`

A comma separated list of Poll fields to display.

**options.placeFields** `List\<String\>`

A comma separated list of Place fields to display.

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

```java theme={null}
import com.x.xdk.XClient;

XClient client = XClient.builder()
    .bearerToken(System.getenv("X_BEARER_TOKEN"))
    .build();

for (var page : client.posts().getRepostedByPages("1895000000000000000")) {
    System.out.println(page);
}
```

### Parameters

**id** `String` *required*

`id` (path parameter).

**Optional parameters (PostsClient.GetRepostedByOptions — 5)**

**options.maxResults** `Integer`

`max_results` (query parameter).

**options.paginationToken** `String`

A base32hex-encoded pagination token.

**options.userFields** `List\<String\>`

A comma separated list of User fields to display.

**options.expansions** `List\<String\>`

A comma separated list of fields to expand.

**options.postFields** `List\<String\>`

A comma separated list of Post fields to display.

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

```java theme={null}
import com.x.xdk.XClient;

XClient client = XClient.builder()
    .bearerToken(System.getenv("X_BEARER_TOKEN"))
    .build();

for (var page : client.posts().getRepostsPages("1895000000000000000")) {
    System.out.println(page);
}
```

### Parameters

**id** `String` *required*

`id` (path parameter).

**Optional parameters (PostsClient.GetRepostsOptions — 8)**

**options.maxResults** `Integer`

`max_results` (query parameter).

**options.paginationToken** `String`

A base32hex-encoded pagination token.

**options.postFields** `List\<String\>`

A comma separated list of Post fields to display.

**options.expansions** `List\<String\>`

A comma separated list of fields to expand.

**options.userFields** `List\<String\>`

A comma separated list of User fields to display.

**options.mediaFields** `List\<String\>`

A comma separated list of Media fields to display.

**options.pollFields** `List\<String\>`

A comma separated list of Poll fields to display.

**options.placeFields** `List\<String\>`

A comma separated list of Place fields to display.

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

```java theme={null}
import com.x.xdk.Schemas;
import com.x.xdk.XClient;

XClient client = XClient.builder()
    .accessToken(System.getenv("X_ACCESS_TOKEN"))
    .build();

var response = client.posts().hideReply(
    "1895000000000000000",
    new Schemas.HidePostsReplyRequest().hidden(true)
);
System.out.println(response);
```

### Parameters

**tweetId** `String` *required*

`tweet_id` (path parameter).

**body** `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.

```java theme={null}
import com.x.xdk.XClient;

XClient client = XClient.builder()
    .bearerToken(System.getenv("X_BEARER_TOKEN"))
    .build();

for (var page : client.posts().searchAllPages("from:XDevelopers")) {
    System.out.println(page);
}
```

### Parameters

**query** `String` *required*

`query` (query parameter).

**Optional parameters (PostsClient.SearchAllOptions — 14)**

**options.startTime** `String`

`start_time` (query parameter).

**options.endTime** `String`

`end_time` (query parameter).

**options.sinceId** `String`

`since_id` (query parameter).

**options.untilId** `String`

`until_id` (query parameter).

**options.maxResults** `Integer`

`max_results` (query parameter).

**options.nextToken** `String`

A base32hex-encoded pagination token.

**options.paginationToken** `String`

A base32hex-encoded pagination token.

**options.sortOrder** `String`

`sort_order` (query parameter).

**options.postFields** `List\<String\>`

A comma separated list of Post fields to display.

**options.expansions** `List\<String\>`

A comma separated list of fields to expand.

**options.userFields** `List\<String\>`

A comma separated list of User fields to display.

**options.mediaFields** `List\<String\>`

A comma separated list of Media fields to display.

**options.pollFields** `List\<String\>`

A comma separated list of Poll fields to display.

**options.placeFields** `List\<String\>`

A comma separated list of Place fields to display.

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

```java theme={null}
import com.x.xdk.XClient;

XClient client = XClient.builder()
    .bearerToken(System.getenv("X_BEARER_TOKEN"))
    .build();

for (var page : client.posts().searchRecentPages("from:XDevelopers")) {
    System.out.println(page);
}
```

### Parameters

**query** `String` *required*

`query` (query parameter).

**Optional parameters (PostsClient.SearchRecentOptions — 14)**

**options.maxResults** `Integer`

`max_results` (query parameter).

**options.nextToken** `String`

A base32hex-encoded pagination token.

**options.paginationToken** `String`

A base32hex-encoded pagination token.

**options.startTime** `String`

Must be within the last 7 days.

**options.endTime** `String`

`end_time` (query parameter).

**options.sinceId** `String`

`since_id` (query parameter).

**options.untilId** `String`

`until_id` (query parameter).

**options.sortOrder** `String`

`sort_order` (query parameter).

**options.postFields** `List\<String\>`

A comma separated list of Post fields to display.

**options.expansions** `List\<String\>`

A comma separated list of fields to expand.

**options.userFields** `List\<String\>`

A comma separated list of User fields to display.

**options.mediaFields** `List\<String\>`

A comma separated list of Media fields to display.

**options.pollFields** `List\<String\>`

A comma separated list of Poll fields to display.

**options.placeFields** `List\<String\>`

A comma separated list of Place fields to display.

**Returns:** `Schemas.SearchPostsRecentResponse` (use `searchRecentPages(...)` for automatic `Paginator<...>` iteration)

***
