> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chamelio.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Create User

> Create a new user in your Chamelio organization with a specified role using an OAuth access token that carries the users:write scope.

## Endpoint

```
POST /v2/users
```

## Authentication

This endpoint requires an OAuth access token. Send it as a bearer token:

```bash theme={null}
Authorization: Bearer your_access_token
```

**Required scope:** `users:write`

> [!NOTE]
>
> The new user is recorded as created by the access token's user.

## Request Body

The request body must be a JSON object with the following fields:

### Required Fields

| Field | Type | Description |
| - | - | - |
| `email` | string | Email address of the new user |
| `first_name` | string | First name of the new user |

### Optional Fields

| Field | Type | Description |
| - | - | - |
| `last_name` | string | Last name of the new user. Defaults to an empty string |
| `role` | string | Organization role to assign. One of `admin`, `editor`, `member`, `viewer`. Defaults to `viewer` |
| `is_sso_user` | boolean | Whether the user authenticates via single sign-on (SSO). Defaults to `false` |

## Request Example

```bash cURL theme={null}
curl -X POST https://platform.chamelio.ai/v2/users \
  -H "Authorization: Bearer your_access_token" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "new.user@example.com",
    "first_name": "New",
    "last_name": "User",
    "role": "editor",
    "is_sso_user": false
  }'
```

```python Python theme={null}
import requests

url = "https://platform.chamelio.ai/v2/users"
headers = {
    "Authorization": "Bearer your_access_token",
    "Content-Type": "application/json"
}
payload = {
    "email": "new.user@example.com",
    "first_name": "New",
    "last_name": "User",
    "role": "editor",
    "is_sso_user": False
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())
```

```javascript JavaScript theme={null}
const response = await fetch('https://platform.chamelio.ai/v2/users', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer your_access_token',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    email: 'new.user@example.com',
    first_name: 'New',
    last_name: 'User',
    role: 'editor',
    is_sso_user: false
  })
});

const data = await response.json();
console.log(data);
```

## Response

### Success Response

**Status Code:** `200 OK`

```json theme={null}
{
  "user_id": 1003,
  "email": "new.user@example.com"
}
```

### Response Fields

| Field | Type | Description |
| - | - | - |
| `user_id` | integer | Unique identifier of the newly created user |
| `email` | string | Email address of the newly created user |

## Error Responses

### 400 Bad Request

Returned when the request is invalid - for example, a malformed email or a user that already exists - or
when the access token has no user behind it.
`client_credentials` tokens act as the admin who created the application, so this applies only to
tokens issued before application creators were recorded.

```json theme={null}
{
  "detail": "User with this email already exists"
}
```

```json theme={null}
{
  "detail": "client_credentials tokens are not associated with a user"
}
```

### 401 Unauthorized

Returned when the access token is missing, unknown, revoked, or expired, or when an `X-API-Key` was
sent instead of a bearer token. See [OAuth error responses](https://docs.chamelio.ai/api-reference/oauth-apps.md#error-responses).

```json theme={null}
{
  "detail": "Invalid access token"
}
```

### 403 Forbidden

Returned when the token does not carry the required scope.

```json theme={null}
{
  "detail": "Insufficient scope; this endpoint requires: users:write"
}
```

### 422 Unprocessable Entity

Returned when the request body fails validation.

```json theme={null}
{
  "detail": "Validation error"
}
```

### 429 Too Many Requests

Returned when your organization exceeds its per-minute request limit.

```json theme={null}
{
  "detail": "Rate limit exceeded"
}
```

### 500 Internal Server Error

Returned when the user could not be created due to a server error.

```json theme={null}
{
  "detail": "Failed to create user"
}
```

## Notes

> [!NOTE]
>
> The new user is always created in the organization the token is bound to. The role defaults to `viewer`
> if omitted - set `role` explicitly to grant broader access.

> [!WARNING]
>
> `users:write` allows creating users with any role, including `admin`. Grant this scope only to
> applications that genuinely need to provision users.

## Use Cases

This endpoint is useful for:

* **User provisioning** - Programmatically onboard users from an external system
* **SSO onboarding** - Pre-create SSO users so they can sign in via your identity provider
* **Auditable provisioning** - Record which administrator's session created each user
