# Ban User - Block Members From Your Subscription Bot

> Ban a user from your project, preventing them from accessing your Telegram or Discord community.

Source: https://docs.botsubscription.com/api/users/ban/

Block a member from accessing your paid community on Telegram or Discord. Banned users cannot subscribe to new plans. Banning can terminate existing memberships and remove access; unbanning does not restore terminated memberships. You can optionally include a reason for internal record-keeping.

<ApiEndpoint method="PUT" endpoint="/v2/projects/{project_id}/ban/{user_id}" />

<ApiAuthorization type="Bearer API Key" />

**API key access:** Unrestricted project API key required. Restricted keys cannot call this endpoint.

<ApiSection title="Path Parameters">
  <ApiParameter name="project_id" type="string" required description="The unique identifier of the project." />
  <ApiParameter name="user_id" type="string" required description="The unique identifier of the user to ban (numeric ID)." />
</ApiSection>

<ApiSection title="Request Body">
  <ApiParameter name="reason" type="string" description="Optional reason for banning the user (1-500 characters)." />
</ApiSection>

If `removal_pending`, `retry_scheduled` or `warnings` reports unfinished removal, the ban is recorded but access removal must not be treated as complete.

<ApiSamplePane>

<ApiRequestSample title="Request">

```bash
curl -X PUT "https://api.botsubscription.com/v2/projects/YOUR_PROJECT_ID/ban/123456789012345678" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
```

```javascript
const project_id = 'YOUR_PROJECT_ID';
const user_id = '123456789012345678';
const response = await fetch(`https://api.botsubscription.com/v2/projects/${project_id}/ban/${user_id}`, {
  method: 'PUT',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({})
});
const data = await response.json();
```

```python
import requests

project_id = 'YOUR_PROJECT_ID'
user_id = '123456789012345678'
response = requests.put(
    f'https://api.botsubscription.com/v2/projects/{project_id}/ban/{user_id}',
    headers={'Authorization': 'Bearer YOUR_API_KEY'},
    json={}
)
data = response.json()
```

```php
$project_id = 'YOUR_PROJECT_ID';
$user_id = '123456789012345678';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.botsubscription.com/v2/projects/{$project_id}/ban/{$user_id}");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{}');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
```

</ApiRequestSample>

<ApiResponseTabs>
  <ApiResponse status={200} description="User banned">

```json
{
  "ok": true,
  "request_id": "11111111-1111-1111-1111-111111111111",
  "method": "PUT",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/ban/123456789012345678",
  "code": 200,
  "message": "User banned successfully",
  "data": {
    "user_id": "123456789012345678",
    "banned_at": "2025-01-15T10:30:00.000Z",
    "banned_by": null,
    "banned_reason": null
  }
}
```

  </ApiResponse>
  <ApiResponse status={200} description="User banned; access removal is still pending">

```json
{
  "ok": true,
  "request_id": "11111111-1111-1111-1111-111111111111",
  "method": "PUT",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/ban/123456789012345678",
  "code": 200,
  "message": "User banned successfully",
  "data": {
    "user_id": "123456789012345678",
    "banned_at": "2025-01-15T10:30:00.000Z",
    "banned_by": null,
    "banned_reason": null,
    "removal_pending": true,
    "retry_scheduled": true,
    "warnings": [
      "Membership removal is awaiting a retry."
    ]
  }
}
```

  </ApiResponse>
  <ApiResponse status={409} description="User already banned">

```json
{
  "ok": false,
  "request_id": "11111111-1111-1111-1111-111111111111",
  "method": "PUT",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/ban/123456789012345678",
  "code": 409,
  "error": {
    "error_code": "CONFLICT",
    "message": "User is already banned."
  }
}
```

  </ApiResponse>
  <ApiResponse status={404} description="User not found">

```json
{
  "ok": false,
  "request_id": "11111111-1111-1111-1111-111111111111",
  "method": "PUT",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/ban/123456789012345678",
  "code": 404,
  "error": {
    "error_code": "NOT_FOUND",
    "message": "User not found"
  }
}
```

  </ApiResponse>
  <ApiResponse status={401} description="Invalid or expired API key">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "PUT",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/ban/123456789012345678",
  "code": 401,
  "error": {
    "message": "Invalid or expired authentication token.",
    "error_code": "UNAUTHORIZED"
  }
}
```

  </ApiResponse>
</ApiResponseTabs>

</ApiSamplePane>
