Skip to main content

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​

HeaderRequiredDescription
AuthorizationYesBearer token for a System API client

Path Parameters​

ParameterTypeRequiredDescription
userIdintegerYesUser identifier. Must be greater than 0.
roleIdintegerYesRole 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​

StatusWhen it happens
401 UnauthorizedThe bearer token is missing, invalid, or expired
403 ForbiddenThe token is valid but does not have access to this endpoint
404 Not FoundNo 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 roleId value 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 (raw HTTP)​

# The Python beta does not expose System API helpers.
# 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​