---
title: "Users API"
description: "Manage Alpacon users through the API. Find users, create accounts, update profiles and remove access, with permission checks, pagination and error codes."
---

> Full documentation index: https://docs.alpacax.com/llms.txt

# Users

**Endpoint**: `/api/iam/users/`

Manage workspace users with a signed-in session or a personal API token (`alpat-`). Service tokens cannot call this API. A personal token needs the matching `user:<action>` scope as well as the caller’s permission on the user. Use `-` instead of a user UUID to refer to yourself, including on update and delete. Safe reads of `-` are exempt from the token scope check.

The examples use a personal token with the required scope and role permissions.

  

## List users

```http
GET /api/iam/users/
```

### Query parameters

| Parameter | Type | Description |
|---|---|---|
| `is_active`, `is_staff`, `is_superuser`, `is_ldap_user` | boolean | Filter by the corresponding account flag |
| `inactive` | boolean | Active members with no activity for 90 days, or none since joining more than 90 days ago |
| `superuser_role` | boolean | Active holders of the superuser role, rather than the `is_superuser` flag |
| `shell`, `username` | string | Exact match |
| `username__icontains` | string | Case-insensitive partial username match |
| `added_at` | datetime | Exact creation time |
| `added_at__gte`, `added_at__lte`, `added_at__gt`, `added_at__lt` | datetime | Creation time bounds |
| `exclude_group` | UUID | Exclude members of a group you may read |
| `search` | string | Search `username`, `first_name`, `last_name`, `email`, `phone`, `tags`, `description`, `uid`, `added_at` |
| `ordering` | string | `first_name`, `last_name`, `email`, `tags`, `uid`, `is_superuser`, `is_staff`, `is_active`, `date_joined`, `last_login`, `added_at`, `updated_at`; prefix `-` for descending |
| `page` | integer | Page number |
| `page_size` | integer | Results per page (default 15, maximum 100) |

Default ordering is superuser first, then staff, then active, then username and ID. `username` is not an accepted `ordering` value.

### Response

```json
{
  "count": 1,
  "current": 1,
  "next": null,
  "previous": null,
  "last": 1,
  "results": [
    {
      "id": "a540bf0f-8b37-4f03-8546-dd71c6b03329",
      "auth0_id": "",
      "username": "jsmith",
      "first_name": "Jane",
      "last_name": "Smith",
      "email": "jane.smith@example.com",
      "phone": "",
      "tags": "developer",
      "num_groups": 1,
      "uid": 2001,
      "is_active": true,
      "is_staff": false,
      "is_superuser": false,
      "is_ldap_user": false,
      "date_joined": "2026-10-20T10:00:00Z",
      "last_active": "2026-10-24T09:00:00Z",
      "permissions": {
        "update": true,
        "delete": true
      }
    }
  ]
}
```

`current`, `next`, `previous` and `last` are page numbers, not URLs. `permissions.update` and `permissions.delete` reflect role permissions; the action can still fail another check. `last_active` is the last successful authentication, regardless of authentication method.

### Example

```bash
curl -X GET "https://your-workspace.us1.alpacon.io/api/iam/users/?is_active=true&page_size=20" \
  -H "Authorization: token=\"alpat-xxxxxxxxxxxxxxxxxx\""
```

  
  

## Get user

```http
GET /api/iam/users/{user_id}/
```

`user_id` is a UUID or `-`. The `200 OK` response includes all list fields, including `permissions`, plus the following fields.

| Field | Description |
|---|---|
| `description`, `shell`, `home_directory` | Profile description, login shell and home directory |
| `added_at`, `updated_at` | Creation and update times |
| `websh_total_lifetime` | Total Websh time in seconds |
| `webftp_upload_bytes`, `webftp_download_bytes` | WebFTP transfer totals in bytes |

```bash
curl -X GET "https://your-workspace.us1.alpacon.io/api/iam/users/-/" \
  -H "Authorization: token=\"alpat-xxxxxxxxxxxxxxxxxx\""
```

  
  

## Create user

```http
POST /api/iam/users/
```

Create an account with `user:create`. If your workspace uses Auth0 sign-in and is linked to an Auth0 organization, this route returns `405 Method Not Allowed`.

### Request parameters

| Field | Type | Required | Description |
|---|---|---|---|
| `username` | string | Yes | Up to 128 characters; must match `^[a-z][a-z0-9_-]*$` |
| `first_name`, `last_name`, `email`, `phone`, `tags`, `description` | string | No | Profile fields |
| `shell` | string | No | Login shell; default `/bin/bash` |
| `is_active` | boolean | No | Active status |
| `is_staff`, `is_superuser` | boolean | No | Only a Superuser may set either to `true` |
| `is_ldap_user` | boolean | No | `true` checks the LDAP directory connection |

You cannot supply `password` on create. Alpacon generates it and returns it once in the `201 Created` response. Save it when you receive it. The UID is assigned from 2000 upward, and the home directory is `/home/{username}`.

Reserved names, names already used by a user or application, and names of server accounts with UID at most 1000 or groups with GID at most 1000 are refused. For a non-superuser, a match with another existing server account or group requires approval: the request returns `400 approval_superuser_approve_required`, and the account is created after approval. A Superuser can create that account directly.

### Response

`201 Created` returns the user fields and a one-time `password`. For example, these fields identify the new account and its generated password:

```json
{
  "id": "a540bf0f-8b37-4f03-8546-dd71c6b03329",
  "username": "jsmith",
  "uid": 2001,
  "home_directory": "/home/jsmith",
  "password": "<generated-password>"
}
```

### Example

```bash
curl -X POST "https://your-workspace.us1.alpacon.io/api/iam/users/" \
  -H "Authorization: token=\"alpat-xxxxxxxxxxxxxxxxxx\"" \
  -H "Content-Type: application/json" \
  -d '{"username": "jsmith", "first_name": "Jane", "last_name": "Smith"}'
```

  
  

## Update user

```http
PATCH /api/iam/users/{user_id}/
PUT /api/iam/users/{user_id}/
```

You may update yourself. Updating another user requires `user:update` on that user, granted globally or for that object. `user_id` accepts a UUID or `-`.

### Request parameters

| Field | Type | Description |
|---|---|---|
| `first_name`, `last_name`, `phone`, `tags`, `description`, `shell` | string | Profile fields |
| `email` | string | Read-only on Alpacon Cloud |
| `is_active` | boolean | Activate or deactivate another account, subject to the rules below |
| `is_ldap_user` | boolean | LDAP user status; the directory is checked when setting `true` or updating an existing LDAP user |
| `password` | string | Accepted only when an admin account calls the user's UUID path and the workspace uses local login or has no Auth0 organization; otherwise ignored |

`username`, `is_staff` and `is_superuser` are read-only on update. Change administrative access through role assignment.

Changing your own `is_active`, through either `-` or your UUID, returns `400 user_patch_forbidden`; sending its current value is allowed. Activating or deactivating an admin or superuser account requires `user:remove_privileged`. Deactivation is refused for the last active superuser, last active admin, or sole owner of a group. Deactivation closes the user’s Websh and WebFTP sessions.

### Response

`200 OK` with the updated user.

### Example

```bash
curl -X PATCH "https://your-workspace.us1.alpacon.io/api/iam/users/-/" \
  -H "Authorization: token=\"alpat-xxxxxxxxxxxxxxxxxx\"" \
  -H "Content-Type: application/json" \
  -d '{"first_name": "Janet", "tags": "developer, senior"}'
```

  
  

## Delete user

```http
DELETE /api/iam/users/{user_id}/
```

`user_id` accepts a UUID or `-`. Deleting another user requires `user:delete`. If the target is an admin or superuser, you also need `user:remove_privileged`; self-deletion is exempt from this extra permission. Superusers hold it by default, admins do not, and it can be delegated through a custom global role.

The API checks authority first, then refuses deletion of a sole group owner, the last active superuser or admin, and the billing owner of a workspace with an active subscription.

### Query parameters

| Parameter | Type | Description |
|---|---|---|
| `purge` | boolean | `true` also removes the user's home directories on servers. The user record is anonymized either way |

The account is immediately deactivated and its user record anonymized. Cleanup then removes memberships, roles and personal API tokens, closes sessions and revokes work sessions. Only accounts provisioned by Alpacon are removed from enabled, undeleted servers. An enabled server that is offline receives the account-removal request when its agent reconnects. A disabled server is not touched. Discovered accounts are unlinked from the user but left on the server.

### Response

```http
204 No Content
```

The response does not report server cleanup progress.

### Example

```bash
curl -X DELETE "https://your-workspace.us1.alpacon.io/api/iam/users/a540bf0f-8b37-4f03-8546-dd71c6b03329/?purge=true" \
  -H "Authorization: token=\"alpat-xxxxxxxxxxxxxxxxxx\""
```

  

## Read permissions and server accounts

These read routes accept a user UUID or `-`. Reading another user requires `user:read`. Personal tokens need `user:read` for these actions unless the path uses `-`.

```http
GET /api/iam/users/{user_id}/permissions/
GET /api/iam/users/{user_id}/server-presence/
GET /api/iam/users/{user_id}/effective-permissions/
```

| Route | Response |
|---|---|
| `permissions/` | Without `permission`, returns permission patterns in `global` and `object_scoped`. With `permission`, returns `{"allowed": true}` or `{"allowed": false}`. Optionally supply `content_type` and `object_id` for an object check; `object_id` requires `content_type` |
| `server-presence/` | Paginated server accounts for the user, including account UID, username, UID conflicts, login status and active sudo-grant count. Includes servers outside the caller's server list; deleted servers are excluded |
| `effective-permissions/` | Effective permissions from direct roles and group roles, with their origins and a summary |

## Error responses

| Status | Error code | Description |
|---|---|---|
| 400 | `user_username_invalid` | Username does not match the required format |
| 400 | `user_username_disallowed` | Username is reserved |
| 400 | `user_username_in_use` | Username is already in use |
| 400 | `approval_superuser_approve_required` | Creating an account with this existing server account or group name needs approval |
| 400 | `user_patch_forbidden` | Non-superuser sets administrative flags on create, or a user changes their own active status |
| 400 | `user_unique_superuser` | Cannot remove or deactivate the last active superuser |
| 400 | `user_unique_admin` | Cannot remove or deactivate the last active admin |
| 400 | `user_unique_group_owner` | Cannot remove or deactivate a group’s sole owner |
| 400 | `user_unique_active_user` | Cannot deactivate the last active user |
| 400 | `user_billing_owner` | Cannot delete the billing owner while the workspace is subscribed |
| 400 | `ldap_connection_error` | Cannot connect to the LDAP directory |
| 400 | `ldap_undefined_error` | LDAP check failed on create |
| 400 | `ldap_user_not_found` | LDAP user lookup failed on update |
| 400 | `ldap_user_info_cannot_be_updated` | LDAP user information cannot be updated this way |
| 400 | `invalid_input` | Invalid permission-check parameters |
| 401 | `auth_token_missing` | Not authenticated |
| 403 | `rbac_permission_required` | Role grants no permission for this action |
| 403 | `rbac_object_permission_required` | Role does not grant this action on this user |
| 403 | `api_token_scope_missing` | Personal token lacks the required scope |
| 403 | `user_privileged_removal_forbidden` | Missing `user:remove_privileged` for a privileged account |
| 403 | `workspace_suspended` | Writes are refused while the workspace is suspended |
| 404 | `api_not_found` | User not found or not accessible |
| 405 | — | Create is unavailable with Auth0 sign-in and a linked Auth0 organization; response uses `{"detail": "..."}` |

Source: https://docs.alpacax.com/reference/api/iam/users/
