> ## 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 |
| :- | :- | :- | :- |
| [`CreateBotAsync`](#createbotasync) | `POST /2/bots` | Standard | Create a Bot |
| [`DeleteBotAsync`](#deletebotasync) | `DELETE /2/bots/{id}` | Standard | Delete Bot |
| [`GetAsync`](#getasync) | `GET /2/bots` | Standard | Get Bots |
| [`RevokeBotTokenAsync`](#revokebottokenasync) | `DELETE /2/bots/{id}/token` | Standard | Revoke Bot Token |
| [`RotateBotTokenAsync`](#rotatebottokenasync) | `POST /2/bots/{id}/token` | Standard | Rotate Bot Token |
| [`UpdateBotAsync`](#updatebotasync) | `PUT /2/bots/{id}` | Standard | Update Bot |

## `CreateBotAsync`

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.

```csharp theme={null}
using System;
using Xdk;
using Xdk.Models;

using var client = new XClient(new XClientOptions
{
    BearerToken = Environment.GetEnvironmentVariable("X_BEARER_TOKEN"),
});

var response = await client.Bots.CreateBotAsync(new CreateBotRequest { Handle = "example" });
Console.WriteLine(response);
```

### Parameters

**body** `CreateBotRequest` *required*

Request payload.

**Returns:** `Task<CreateBotResponse>`

***

## `DeleteBotAsync`

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.

```csharp theme={null}
using System;
using Xdk;

using var client = new XClient(new XClientOptions
{
    BearerToken = Environment.GetEnvironmentVariable("X_BEARER_TOKEN"),
});

var response = await client.Bots.DeleteBotAsync("1895000000000000000");
Console.WriteLine(response);
```

### Parameters

**id** `string` *required*

`id` (path parameter).

**Returns:** `Task<DeleteBotResponse>`

***

## `GetAsync`

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.

```csharp theme={null}
using System;
using Xdk;

using var client = new XClient(new XClientOptions
{
    BearerToken = Environment.GetEnvironmentVariable("X_BEARER_TOKEN"),
});

var response = await client.Bots.GetAsync();
Console.WriteLine(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:** `Task<GetBotsResponse>`

***

## `RevokeBotTokenAsync`

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.

```csharp theme={null}
using System;
using Xdk;

using var client = new XClient(new XClientOptions
{
    BearerToken = Environment.GetEnvironmentVariable("X_BEARER_TOKEN"),
});

var response = await client.Bots.RevokeBotTokenAsync("1895000000000000000");
Console.WriteLine(response);
```

### Parameters

**id** `string` *required*

`id` (path parameter).

**Returns:** `Task<RevokeBotTokenResponse>`

***

## `RotateBotTokenAsync`

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.

```csharp theme={null}
using System;
using System.Collections.Generic;
using Xdk;
using Xdk.Models;

using var client = new XClient(new XClientOptions
{
    BearerToken = Environment.GetEnvironmentVariable("X_BEARER_TOKEN"),
});

var response = await client.Bots.RotateBotTokenAsync(
    "1895000000000000000",
    new RotateBotTokenRequest { Scopes = new List<string> { "example" } }
);
Console.WriteLine(response);
```

### Parameters

**id** `string` *required*

`id` (path parameter).

**body** `RotateBotTokenRequest` *required*

Request payload.

**Returns:** `Task<RotateBotTokenResponse>`

***

## `UpdateBotAsync`

PUT `/2/bots/{id}`

**Update Bot**

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

```csharp theme={null}
using System;
using Xdk;
using Xdk.Models;

using var client = new XClient(new XClientOptions
{
    BearerToken = Environment.GetEnvironmentVariable("X_BEARER_TOKEN"),
});

var response = await client.Bots.UpdateBotAsync(
    "1895000000000000000",
    new UpdateBotRequest { DisplayName = "example" }
);
Console.WriteLine(response);
```

### Parameters

**id** `string` *required*

`id` (path parameter).

**body** `UpdateBotRequest` *required*

Request payload.

**Returns:** `Task<UpdateBotResponse>`

***
