Skip to Content
MySagra 1.4.0 is released 🎉

Users

Manage user accounts and their roles. All endpoints require admin authentication.

User Object

{ "id": "clxyz123456789abcdef", "username": "john_doe", "role": { "id": "clxyz123456789abcdef", "name": "admin" } }
FieldTypeDescription
idstringUnique identifier (CUID)
usernamestringUser’s username
role.idstringRole identifier
role.namestringRole name (e.g. admin, operator)

GET /v1/users

Retrieve all users.

Authentication: Bearer token (admin)

Response 200 OK

[ { "id": "clxyz123456789abcdef", "username": "john_doe", "role": { "id": "clxyz123456789abcdef", "name": "admin" } } ]

Errors

StatusDescription
401Unauthorized
403Forbidden

GET /v1/users/{id}

Retrieve a single user by ID.

Authentication: Bearer token (admin)

Path Parameters

ParameterTypeDescription
idstringUser ID (CUID)

Response 200 OK

Returns a User Object.

Errors

StatusDescription
400Invalid user ID
401Unauthorized
403Forbidden
404User not found

POST /v1/users

Create a new user.

Authentication: Bearer token (admin)

Request Body

{ "username": "john_doe", "password": "password123", "roleId": "clxyz123456789abcdef" }
FieldTypeRequiredDescription
usernamestringYesUsername (min 6 characters)
passwordstringYesPassword (min 8 characters)
roleIdstringYesRole ID to assign

Response 201 Created

Returns the created User Object.

Errors

StatusDescription
400Invalid request body
401Unauthorized
403Forbidden
409Username already exists

PUT /v1/users/{id}

Update an existing user.

Authentication: Bearer token (admin)

Path Parameters

ParameterTypeDescription
idstringUser ID (CUID)

Request Body

{ "username": "john_doe", "password": "newpassword123", "roleId": "clxyz123456789abcdef" }
FieldTypeRequiredDescription
usernamestringYesUsername (min 6 characters)
passwordstringYesPassword (min 8 characters)
roleIdstringYesRole ID to assign

Response 200 OK

Returns the updated User Object.

Errors

StatusDescription
400Invalid request body
401Unauthorized
403Forbidden
404User not found

DELETE /v1/users/{id}

Delete a user.

Authentication: Bearer token (admin)

Path Parameters

ParameterTypeDescription
idstringUser ID (CUID)

Response 204 No Content

Errors

StatusDescription
400Invalid user ID
401Unauthorized
403Forbidden
404User not found
Last updated on