Assign User To Role
Assign a single role to a user.
Authentication
This endpoint requires a bearer access token for the System API.
Endpoint
POST /api/v1/users/{userId}/roles/{roleId}
Authorization: Bearer YOUR_ACCESS_TOKEN
Request
Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer token for a System API client |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
userId | integer | Yes | User identifier. Must be greater than 0. |
roleId | integer | Yes | Role identifier. Must be greater than 0. |
Query Parameters
This endpoint does not accept query parameters.
Request Body
This endpoint does not accept a request body.
Response
204 No Content
The role assignment was applied successfully.
This endpoint does not return a response body on success.
Errors
| Status | When it happens |
|---|---|
401 Unauthorized | The bearer token is missing, invalid, or expired |
403 Forbidden | The token is valid but does not have access to this endpoint |
404 Not Found | No user exists with the provided userId |
404 Example
User not found
Behavior
- The endpoint is idempotent for an already assigned role
- If the user already has the role, the request still succeeds with
204 No Content - Use an existing
roleIdvalue when calling this endpoint
Example
cURL
curl -X POST "https://your-tenant.guardhouse.cloud/api/v1/users/101/roles/1" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
.NET SDK
using Guardhouse.SDK.Services;
// Assumes AddGuardhouseClientWithApiClients(...) is already configured.
app.MapPost("/example/users/{userId:int}/roles/{roleId:int}", async (int userId, int roleId, IGuardhouseUsersClient usersClient) =>
{
var assigned = await usersClient.AssignUserToRoleAsync(userId, roleId);
return assigned ? Results.NoContent() : Results.NotFound();
});
Python SDK
# SDK support is in development.
# Use raw HTTP for now.
#
# Example shape:
# response = requests.post(
# "https://your-tenant.guardhouse.cloud/api/v1/users/101/roles/1",
# headers={"Authorization": "Bearer YOUR_ACCESS_TOKEN"},
# )
Notes
- Use Get User By ID to verify current role assignments.
- Use Get Roles to inspect available roles.