---
title: "POST /users/{user_id}/roles"
method: POST
path: "/users/{user_id}/roles"
tags: ["Users"]
---

# POST /users/{user_id}/roles

`POST /users/{user_id}/roles`

## Request

- Base URL: `/api` (relative, and the document was published on a file host, not at the API’s origin)
- URL: `/api/users/{user_id}/roles`
- Auth: HTTP bearer

## Path parameters

- `user_id` integer, required

## Request body

- AssignRoleRequest: Body of `POST /users/{user_id}/roles`. The target user comes from the path; the body names only the role.
  - `role_type` string, required
  - `user_id` integer, nullable: Deprecated: the target is the path's `user_id`. Still accepted for older clients, but only when it equals the path id (otherwise 400).

## Response `200`

Role assigned; the user and all of its roles

- RouteUserWithRoles
  - `roles` RouteRole[], required
    - `created_at` string, date-time, required
    - `id` integer, required
    - `name` string, required
    - `updated_at` string, date-time, required
  - `user` RouteUser, required
    - `created_at` string, date-time, required
    - `deleted_at` string, date-time, nullable
    - `email` string, required
    - `email_verified` boolean, required
    - `id` integer, required
    - `image` string, required
    - `mfa_enabled` boolean, required
    - `must_change_password` boolean, required
    - `name` string, required
    - `updated_at` string, date-time, required
    - `username` string, required

## Other responses

- `400`: Invalid role type, or a deprecated body user_id that differs from the path
- `401`: Unauthorized
- `403`: Admin role required or self-modification forbidden
- `404`: User or role not found
- `500`: Internal server error

## Changes

- **2026-11-26** `e1864d950604`: 5 breaking
  - the `roles/items/created_at` response's property type changed from `integer` to `string`, and format from `int64` to `date-time` for status `200`
  - the `roles/items/updated_at` response's property type changed from `integer` to `string`, and format from `int64` to `date-time` for status `200`
  - the `user/created_at` response's property type changed from `integer` to `string`, and format from `int64` to `date-time` for status `200`
  - the `user/deleted_at` response's property type changed from `integer, null` to `string, null`, and format from `int64` to `date-time` for status `200`
  - …1 more
- **2026-11-26** `199b8052eb32`: 4 info
  - the request property `user_id` became nullable
  - the request property `user_id` became optional
  - request property `user_id` deprecated
  - added the media type `application/json` for the response with the status `200`
- **2026-07-27** `1b060c0a4ba3`: 2 info
  - added the non-success response with the status `401`
  - added the non-success response with the status `403`

[Operation history](https://skmtc.dev/gotempsh/apis/temps/changes/users/:user_id/roles/post.md)

---

[API](https://skmtc.dev/gotempsh/apis/temps.md) - [All operations](https://skmtc.dev/gotempsh/apis/temps/llms.txt) - [OpenAPI document](https://skmtc.dev/gotempsh/apis/temps/revisions/3b040526eb43?raw)
