Skip to main content

Block User By ID

Suspend a user and revoke current access.

Authentication

This endpoint requires a bearer access token for the System API.

Endpoint

PATCH /api/v1/users/{userId}/block
Authorization: Bearer YOUR_ACCESS_TOKEN
Content-Type: application/json

Request

Headers

HeaderRequiredDescription
AuthorizationYesBearer token for a System API client
Content-TypeYesMust be application/json

Path Parameters

ParameterTypeRequiredDescription
userIdintegerYesUser identifier. Must be greater than 0.

Query Parameters

This endpoint does not accept query parameters.

Request Body

{
"triggerWebhook": false,
"notifyUserViaEmail": true,
"suspensionReason": "Repeated policy violations",
"blockedByUserId": 9001
}

Request Fields

FieldTypeRequiredDescription
triggerWebhookbooleanNoAccepted by the API for webhook workflow control. Default: false.
notifyUserViaEmailbooleanNoWhen true, the user receives the restricted-access email. Default: false.
suspensionReasonstringNoReason for the suspension. Maximum length: 250.
blockedByUserIdintegerYesIdentifier of the acting user who performed the block action. Must be greater than 0.

Validation Rules

  • blockedByUserId must be greater than 0
  • suspensionReason must not exceed 250 characters

Response

204 No Content

The user was blocked successfully.

This endpoint does not return a response body on success.

Errors

StatusWhen it happens
400 Bad RequestThe request body is invalid
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

  • Current access for the user is revoked before the suspension is stored
  • The user is marked as suspended
  • Suspension metadata is stored, including time, actor, and reason
  • When notifyUserViaEmail is true, the restricted-access email is sent
  • triggerWebhook is accepted by the endpoint, but this endpoint does not currently expose a documented webhook result

Example

cURL

curl -X PATCH "https://your-tenant.guardhouse.cloud/api/v1/users/101/block" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"triggerWebhook": false,
"notifyUserViaEmail": true,
"suspensionReason": "Repeated policy violations",
"blockedByUserId": 9001
}'

.NET SDK

using Guardhouse.SDK.Models.Users;
using Guardhouse.SDK.Services;

// Assumes AddGuardhouseClientWithApiClients(...) is already configured.
app.MapPatch("/example/users/{userId:int}/block", async (int userId, IGuardhouseUsersClient usersClient) =>
{
var blocked = await usersClient.BlockUserAsync(userId, new BlockUserRequest
{
TriggerWebhook = false,
NotifyUserViaEmail = true,
SuspensionReason = "Repeated policy violations",
BlockedByUserId = 9001
});

return blocked ? Results.NoContent() : Results.NotFound();
});

Python SDK

# SDK support is in development.
# Use raw HTTP for now.
#
# Example shape:
# response = requests.patch(
# "https://your-tenant.guardhouse.cloud/api/v1/users/101/block",
# headers={
# "Authorization": "Bearer YOUR_ACCESS_TOKEN",
# "Content-Type": "application/json",
# },
# json={
# "triggerWebhook": False,
# "notifyUserViaEmail": True,
# "suspensionReason": "Repeated policy violations",
# "blockedByUserId": 9001,
# },
# )

Notes