# Disable employee accounts

Source: [Disable employee accounts](<https://docs.gptunnel.ru/en/access/disable/>)

<a id="_top"></a>
> **Note: Organization API key**
>
> Use an API key for your organization with the Full dashboard access permission. The key must have been created by an owner or administrator. [Get an API key](<https://docs.gptunnel.ru/en/>).

<a id="disable-accounts"></a>
## Disable accounts

`POST https://gptunnel.ru/api/v1/access/disableAccounts`

Disable one or more employee accounts by login. A disabled employee cannot sign in, and their active sessions are terminated. A login counts toward `disabled` only once the account is disabled and its sessions are terminated. Each login is processed independently. A failure for one login does not stop the rest.

> **Tip: Which accounts you can disable**
>
> You can disable only accounts created by this organization whose role is equal to or lower than the key creator’s role. You cannot disable the key creator’s own account. Retrying is safe. For an already disabled account the API attempts to end any remaining active sessions. Retry after `session_termination_failed`.

### Request headers

| Parameter | Type | Description |
| --- | --- | --- |
| `Authorization` (required) | `string` | API key |

### Request parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `logins` (required) | `string[]` | Array of 1 to 25 employee logins. Send a one-item array to disable one account. |

The response contains `disabled` (number of disabled accounts), `failed` (number of failed items), and `failedLogins` (reason and explanation for each failure).

Error reasons in `failedLogins`:

### Error reasons

| Parameter | Type | Description |
| --- | --- | --- |
| `not_found` | `string` | No employee in the organization has this login |
| `forbidden` | `string` | You can't shut down an account with a higher role, your own account or an account that wasn't created by this organization |
| `session_termination_failed` | `string` | The account is disabled, but some active sessions could not be terminated. Retry for this login so the server can end the remaining sessions. |
| `error` | `string` | An unexpected error occurred while processing this employee |

<a id="example-request"></a>
### Example request

Set `GPTUNNEL_API_KEY` and replace the placeholders with values for your organization.

<a id="tab-panel-0-0"></a>
**Python**

```python
import json
import os
from urllib.request import Request, urlopen

key = os.environ.get("GPTUNNEL_API_KEY")
if not key:
    raise SystemExit("Set GPTUNNEL_API_KEY")

body = {
  "logins": [
    "ivanov",
    "petrov"
  ]
}
request = Request(
    "https://gptunnel.ru/api/v1/access/disableAccounts",
    method="POST",
    headers={
        "Authorization": key,
        "Content-Type": "application/json",
    },
    data=json.dumps(body).encode("utf-8"),
)
with urlopen(request, timeout=30) as response:
    print(json.load(response))
```

<a id="tab-panel-0-1"></a>
**cURL**

```bash
curl --request POST \
  --url 'https://gptunnel.ru/api/v1/access/disableAccounts' \
  --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \
  --header 'Content-Type: application/json' \
  --data '{
  "logins": [
    "ivanov",
    "petrov"
  ]
}'
```

<a id="tab-panel-0-2"></a>
**JavaScript (Node.js)**

```javascript
const key = process.env.GPTUNNEL_API_KEY
if (!key) throw new Error("Set GPTUNNEL_API_KEY")

const body = {
  "logins": [
    "ivanov",
    "petrov"
  ]
}
const response = await fetch("https://gptunnel.ru/api/v1/access/disableAccounts", {
  method: "POST",
  headers: {
    Authorization: key,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(body),
})
if (!response.ok) throw new Error(await response.text())
console.log(await response.json())
```

<a id="example-response"></a>
### Example response

<a id="tab-panel-1-0"></a>
**200 OK**

```json
{
  "code": 0,
  "disabled": 1,
  "failed": 1,
  "failedLogins": [
    {
      "login": "petrov",
      "reason": "not_found",
      "message": "Employee not found in the organization."
    }
  ]
}
```

<a id="tab-panel-1-1"></a>
**400 Invalid input**

```json
{
  "code": 3,
  "message": "Invalid input, check schema issues.",
  "details": []
}
```

<a id="tab-panel-1-2"></a>
**401 Unauthorized**

```json
{
  "error": {
    "message": "Unauthorized",
    "type": "unauthorized_request_error",
    "param": null,
    "code": null
  }
}
```

<a id="tab-panel-1-3"></a>
**403 Forbidden**

```json
{
  "code": 7,
  "message": "Not allowed to perform this action for the organization."
}
```

<a id="tab-panel-1-4"></a>
**403 Personal account**

```json
{
  "code": 13,
  "message": "This section is not available from a personal account. Use a business organization API key."
}
```

<a id="tab-panel-1-5"></a>
**500 Server error**

```json
{
  "code": 1,
  "message": "Internal server error.",
  "trace_id": "66a346f64dcb57627c03d596"
}
```
