---
search:
  tags:
    - Roles & access
    - POST
seo:
  description: >-
    Assigns an organization-wide or scoped role. Omit scope (or set scope.type
    to… Reference for the POST /users/{id}/roles endpoint in the Fuxam API v4.
sidebar:
  label: Assign a role to a user
  badge: POST
title: Assign a role to a user
type: openapi-operation
---
Assigns an organization-wide or scoped role. Omit `scope` (or set `scope.type` to `organization`) for an institution-wide grant. Supported scoped types: `course` (by course code), `cohort`, `program` (study programs from GET /study-programs), `continuingEducation` (programs from GET /continuing-education — both program types write `studyProgramId`), `module`, `room`, `group`, and `exam`. Superadmin roles cannot be assigned via the API. Idempotent via `Idempotency-Key` header.

`POST /users/{id}/roles`

**Request body** (`application/json`, required)

- `roleId` (string, required)
- `scope` (object)

Request body example, Organization-wide role:

```json
{
  "roleId": "clxrole1234"
}
```

Request body example, Course-scoped role:

```json
{
  "roleId": "clxrole1234",
  "scope": {
    "type": "course",
    "courseCodes": [
      "CS101",
      "MATH201"
    ]
  }
}
```

Request body example, Cohort-scoped role:

```json
{
  "roleId": "clxrole1234",
  "scope": {
    "type": "cohort",
    "cohortIds": [
      "clxcohort1234"
    ]
  }
}
```

Request body example, Study program-scoped role:

```json
{
  "roleId": "clxrole1234",
  "scope": {
    "type": "program",
    "programIds": [
      "clxprogram1234"
    ]
  }
}
```

Request body example, Continuing education program-scoped role:

```json
{
  "roleId": "clxrole1234",
  "scope": {
    "type": "continuingEducation",
    "continuingEducationIds": [
      "clxce1234"
    ]
  }
}
```

Request body example, Module-scoped role:

```json
{
  "roleId": "clxrole1234",
  "scope": {
    "type": "module",
    "moduleIds": [
      "clxmodule1234"
    ]
  }
}
```

Request body example, Room-scoped role:

```json
{
  "roleId": "clxrole1234",
  "scope": {
    "type": "room",
    "roomIds": [
      "clxroom1234"
    ]
  }
}
```

Request body example, User group-scoped role:

```json
{
  "roleId": "clxrole1234",
  "scope": {
    "type": "group",
    "groupIds": [
      "clxgroup1234"
    ]
  }
}
```

Request body example, Exam-scoped role:

```json
{
  "roleId": "clxrole1234",
  "scope": {
    "type": "exam",
    "examIds": [
      "clxexam1234"
    ]
  }
}
```

**Responses**

- `200` — Role assigned
- `400` — Bad Request
- `401` — Unauthorized
- `403` — Forbidden
- `404` — Not Found
- `409` — Conflict — duplicate email or membership code (body includes \`existingUserId\` when known), a time-tracking session that is already running (\`activeSession\`), a time-tracking interval that overlaps an existing log (\`conflictingLog\`), idempotency key reused with a different body (\`idempotency\_key\_reused\`), or concurrent request with the same key still in progress (\`idempotency\_key\_in\_progress\`)
- `429` — Too Many Requests — 1000 requests per minute per institution. Includes \`X-RateLimit-Limit\`, \`X-RateLimit-Remaining\`, \`X-RateLimit-Reset\` (ISO-8601), and \`Retry-After\` (seconds).
- `500` — Internal Server Error
- `503` — Service unavailable — idempotency store temporarily unreachable, or the database is busy (lock wait, transaction timeout, or exhausted serialization/deadlock retries). Database contention includes \`Retry-After: 1\`. The idempotency key is released. Retry the same key (\`service\_unavailable\`).

Response example, 200:

```json
{
  "data": {
    "success": true,
    "assignments": [
      {
        "id": "clxassign1234",
        "roleId": "clxrole1234",
        "role": {
          "id": "string",
          "name": "string",
          "color": "string"
        },
        "layerId": "string",
        "courseCode": "string",
        "cohortId": "string",
        "studyProgramId": "string",
        "moduleId": "string",
        "roomId": "string",
        "userGroupId": "string",
        "examId": "string",
        "createdAt": "2019-08-24T14:15:22Z"
      }
    ]
  },
  "meta": {
    "requestId": "req_1234567890_abc",
    "timestamp": "2026-06-02T07:00:00.000Z",
    "version": "v4",
    "watermark": "2019-08-24T14:15:22Z"
  }
}
```
