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

# BotsClient

> Methods for X API v2 Bots endpoints.

Access **Bots** endpoints via `client.bots()` (`BotsClient`).

## Methods

| Method | Endpoint | Behavior | Summary |
| :- | :- | :- | :- |
| [`createBot`](#createbot) | `POST /2/bots` | Standard | Create a Bot |
| [`deleteBot`](#deletebot) | `DELETE /2/bots/{id}` | Standard | Delete Bot |
| [`get`](#get) | `GET /2/bots` | Standard | Get Bots |
| [`revokeBotToken`](#revokebottoken) | `DELETE /2/bots/{id}/token` | Standard | Revoke Bot Token |
| [`rotateBotToken`](#rotatebottoken) | `POST /2/bots/{id}/token` | Standard | Rotate Bot Token |
| [`updateBot`](#updatebot) | `PUT /2/bots/{id}` | Standard | Update Bot |

## `createBot`

POST `/2/bots`

**Create a Bot**

Creates a bot account in the calling app's project and returns its bearer token. Idempotent on handle: repeating the request for a handle that already names one of the project's bots returns that bot with a freshly minted token, revoking the previous one — safe to retry when a response was lost, since the replaced token was never seen. With an OAuth 2.0 user token, the user must be an admin of the project's developer account. On API Connect, where the request bills the user's own account, the bot is created in the user's project instead; its token is still minted for the calling app.

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

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

var response = client.bots().createBot(new Schemas.CreateBotRequest().handle("example"));
System.out.println(response);
```

### Parameters

**body** `Schemas.CreateBotRequest` *required*

Request payload.

**Returns:** `Schemas.CreateBotResponse`

***

## `deleteBot`

DELETE `/2/bots/{id}`

**Delete Bot**

Deletes a bot account from the calling app's project. With an OAuth 2.0 user token, the user must be an admin of the project's developer account. On API Connect, where the request bills the user's own account, the bot is deleted from the user's project instead.

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

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

var response = client.bots().deleteBot("1895000000000000000");
System.out.println(response);
```

### Parameters

**id** `String` *required*

`id` (path parameter).

**Returns:** `Schemas.DeleteBotResponse`

***

## `get`

GET `/2/bots`

**Get Bots**

Retrieves the bot accounts in the calling app's project. meta.max\_bots is the most bots the project can have.

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

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

var response = client.bots().get();
System.out.println(response);
```

### Parameters

**Optional parameters (BotsClient.GetOptions — 3)**

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

***

## `revokeBotToken`

DELETE `/2/bots/{id}/token`

**Revoke Bot Token**

Revokes a bot's bearer token. The bot account is kept, and rotating its token mints a new one.

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

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

var response = client.bots().revokeBotToken("1895000000000000000");
System.out.println(response);
```

### Parameters

**id** `String` *required*

`id` (path parameter).

**Returns:** `Schemas.RevokeBotTokenResponse`

***

## `rotateBotToken`

POST `/2/bots/{id}/token`

**Rotate Bot Token**

Mints a new bearer token for a bot and invalidates every token previously issued for it. The new token is returned only once.

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

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

var response = client.bots().rotateBotToken(
    "1895000000000000000",
    new Schemas.RotateBotTokenRequest().scopes(List.of("example"))
);
System.out.println(response);
```

### Parameters

**id** `String` *required*

`id` (path parameter).

**body** `Schemas.RotateBotTokenRequest` *required*

Request payload.

**Returns:** `Schemas.RotateBotTokenResponse`

***

## `updateBot`

PUT `/2/bots/{id}`

**Update Bot**

Updates a bot's handle, display name, or who may send it Direct Messages.

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

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

var response = client.bots().updateBot(
    "1895000000000000000",
    new Schemas.UpdateBotRequest().displayName("example")
);
System.out.println(response);
```

### Parameters

**id** `String` *required*

`id` (path parameter).

**body** `Schemas.UpdateBotRequest` *required*

Request payload.

**Returns:** `Schemas.UpdateBotResponse`

***
