# devices.draining.set

`POST /api/public/v1/devices/{id}/draining`

Pause (draining: true) or resume new sessions on a machine: while paused no person, run or app opens a browser there (start returns CAPACITY_UNAVAILABLE with reason draining; automatic placement picks another machine); browsers already running continue.

- Capability: `device.manage`
- Command (idempotent): yes — send a `command_id`; resending the same id and body returns the stored receipt
- MCP tool: `devices_draining_set`

## Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `id` | path | string (uuid) | Yes | Device id |
| `command_id` | body | string (uuid) | Yes | Client-generated UUID for this command. Send the same id (and body) again to get the stored receipt instead of a second change; a different body under the same id is CONFLICT. |
| `draining` | body | boolean | Yes | true pauses new sessions on this machine (running ones continue); false resumes |

## Response

`201` with `{ data, replayed: false, correlation_id }` the first time; `200` with `replayed: true` for a repeated `command_id`.

| Field | Type | Always present | Description |
|---|---|---|---|
| `data` | object | Yes |  |
| `data.device_id` | string (uuid) | Yes |  |
| `data.draining` | boolean | Yes | true while new sessions are paused |
| `data.draining_since` | string (date-time) | No |  |
| `data.running` | integer | Yes | Browsers still running on the machine (they continue) (min -9007199254740991, max 9007199254740991) |
| `data.revision` | integer | Yes | (min -9007199254740991, max 9007199254740991) |
| `correlation_id` | string (uuid) | Yes |  |
| `replayed` | boolean | No | true when this command_id was already applied and the stored receipt came back |

New fields can appear at any time; ignore the ones you do not know.

## Errors

| Code | HTTP | Retryable |
|---|---|---|
| `UNAUTHENTICATED` | 401 | No |
| `FORBIDDEN` | 403 | No |
| `RATE_LIMITED` | 429 | Yes |
| `VALIDATION_FAILED` | 422 | No |
| `NOT_FOUND` | 404 | No |
| `CONFLICT` | 409 | No |
| `OUTCOME_UNKNOWN` | 202 | Yes |
| `CAPACITY_UNAVAILABLE` | 503 | Yes |
| `DEPENDENCY_UNAVAILABLE` | 503 | Yes |
| `UNKNOWN` | 500 | No |

## Examples (curl)

```bash
curl -X POST "https://browlix.com/api/public/v1/devices/<id>/draining" \
  -H "Authorization: Bearer $BROWLIX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"command_id":"<uuid>","draining":true}'
```

## Examples (TypeScript SDK)

```ts
import { Browlix } from "@browlix/sdk";

const bx = new Browlix({ apiKey: process.env.BROWLIX_API_KEY! });
const reply = await bx.call("devices.draining.set", { path: { id: "<id>" }, body: {"draining":true} });
console.log(reply.data);
```

## Examples (Python)

```python
import os, uuid
import requests

r = requests.post(
    "https://browlix.com/api/public/v1/devices/<id>/draining",
    headers={"Authorization": f"Bearer {os.environ['BROWLIX_API_KEY']}"},
    json={"command_id":str(uuid.uuid4()),"draining":True},
    timeout=60,
)
print(r.status_code, r.json())
```

## Examples (MCP)

```json
{
  "method": "tools/call",
  "params": {
    "name": "devices_draining_set",
    "arguments": {
      "id": "<id>",
      "draining": true
    }
  }
}
```
