RealTimeX
Start For Free

RealTimeX

API Documentation

IntroductionAuthenticationBase URLHeadersError codes
List usersLoginGet userUpdate userDelete userGet my profileUpdate my profileBlock / unblock
Sample requestsSample responsesStatus codesAppendixChangelog

API Reference

Block / Unblock User

Overview

Block or unblock another chat participant from the signed-in user's perspective. Blocking stops messaging that person without deleting either chat account.

Send the target userId and a type of block or unblock. Typical chat actions: safety menu on a contact profile, or unblock from settings.

When to use this endpoint?

Use Block / Unblock when:

  • A chat participant taps Block on a contact or conversation.
  • Your report / safety flow ends in stopping messages from that peer.
  • They reverse a previous block (type: "unblock").
  • You need a reversible restriction instead of deleting a chat account.

Part of the Chat UserAPIs. Requires the chat user Bearer token for the acting participant. Pass the other person's id — you cannot block yourself.

PATCH{baseUrl}/api/{apiVersion}/user/block-unblock

Authentication

Required (Bearer token)

Tenant-scoped

Yes (tenant DB — requires x-client-id)

Request Headers

HeaderValueDescription
AuthorizationBearer <access_token>Chat user Access Token (Bearer) for the signed-in participant performing the block or unblock.
is-tenanttrueTargets the tenant DB ("true", needs x-client-id).
x-client-id{{clientId}}Tenant (client) id. Required when is-tenant=true.
Content-Typeapplication/jsonJSON request body.

Request Payload

Both fields are required on every call:

FieldTypeRequiredDescription
userIdstringRequiredTarget user's _id to block or unblock.
typestringRequiredAction: block or unblock.

Block

json
{
  "userId": "694b...a1",
  "type": "block"
}

Unblock

json
{
  "userId": "694b...a1",
  "type": "unblock"
}

Success Response (HTTP 200 OK)

On success, the API confirms the action. data may be null; rely on message for UI feedback.

json
{
  "success": true,
  "message": "User blocked successfully",
  "data": null,
  "error": null
}

Common Errors

Block / unblock fails when the token is missing or the target user does not exist.

HTTP 401 Unauthorized — No token

json
{
  "success": false,
  "message": "No token, authorization denied",
  "data": null,
  "error": "Unauthorized"
}

HTTP 404 Not Found — User missing

json
{
  "success": false,
  "message": "User not found",
  "data": null,
  "error": "User not found"
}
CodeReason
401 UnauthorizedAccess Token is missing, invalid, or expired.
404 Not FoundTarget userId does not exist in this tenant.
400 Bad RequestMissing userId / type, or type is not block / unblock.
500 Internal Server ErrorAn unexpected error occurred while updating the block list.

Best Practices

  • Optimistic UI: toggle Block in the chat profile menu immediately, then roll back if the API errors.
  • Hide or disable the message composer for blocked peers after a successful block.
  • Block is personal to the acting chat user — it is not a tenant-wide ban and not the same as Delete User.
  • Always send tenant headers with the chat user Bearer token over HTTPS.

Block state updated

Update conversation lists and contact menus to reflect the new state, then offer unblock from chat settings when needed.

PreviousUpdate my profileNextCreate

On this page

OverviewWhen to use this endpoint?Request HeadersRequest PayloadSuccess ResponseCommon ErrorsBest Practices