Block a user
curl --request POST \
--url https://api.example.com/api/v1/chat/blocksimport requests
url = "https://api.example.com/api/v1/chat/blocks"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.example.com/api/v1/chat/blocks', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/chat/blocks",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/chat/blocks"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/v1/chat/blocks")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/chat/blocks")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodyChat
Block a user
Idempotent block. Severs the chat surface in both directions between the caller and the blocked user.
POST
/
api
/
v1
/
chat
/
blocks
Block a user
curl --request POST \
--url https://api.example.com/api/v1/chat/blocksimport requests
url = "https://api.example.com/api/v1/chat/blocks"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.example.com/api/v1/chat/blocks', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/chat/blocks",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/chat/blocks"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/v1/chat/blocks")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/chat/blocks")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodyOverview
Records a directed block (callerUserId → blockedUserId) in the blocks collection. Block is directed, but every server-side gate uses areBlockedEither — a single block in either direction is enough to prevent contact. Consequences:
- The handshake endpoint (create conversation from match) returns
403 CONVERSATION_BLOCKEDfor any existing match between the two users. - Send message (and the equivalent
chat:message:sendsocket event) returns403 CONVERSATION_BLOCKEDif either side of an existing conversation tries to send. - The matcher (Phase 3+) treats a
blocksrow as a hard filter so no new match between the two users is ever produced.
blockedUserId is a no-op on the second call. The unique (blockerId, blockedId) index collapses the second insert into an update; the response is identical.
Authentication
Bearer <accessToken> required. requireOnboarded middleware applied.
Path parameters
None.Query parameters
None.Request body
| Field | Type | Required | Allowed values | Example |
|---|---|---|---|---|
blockedUserId | string | yes | 24-char hex ObjectId of the user to block. MUST differ from the caller — blocking yourself returns 400 VALIDATION_FAILED. | 66400a8f1c2b4d5e6f7a8b01 |
Example payload
{
"blockedUserId": "66400a8f1c2b4d5e6f7a8b01"
}
Response — 200 OK
| Field | Type | Notes | Example |
|---|---|---|---|
blocked | boolean | Always true on success. Present as a positive ack for the mobile client. | true |
Example response
{
"blocked": true
}
Error responses
| Status | Code | Meaning |
|---|---|---|
| 400 | VALIDATION_FAILED | blockedUserId missing, not a 24-char hex ObjectId, or equal to the caller’s id (cannot block yourself). |
| 401 | UNAUTHENTICATED | Missing, malformed, or expired access token. |
| 403 | ONBOARDING_INCOMPLETE | Caller has not finished onboarding. |
Example error — 400 (self-block)
{
"type": "https://api.swappr.co.uk/errors/validation-failed",
"title": "Validation failed",
"status": 400,
"code": "VALIDATION_FAILED",
"detail": "cannot block yourself",
"instance": "/api/v1/chat/blocks",
"requestId": "01HZQ7K3M4N5P6Q7R8S9T0V1W2",
"errors": [
{ "path": "blockedUserId", "message": "must differ from caller" }
]
}
Side effects
- A
blocksrow is upserted withblockerId = caller,blockedId = blockedUserId. Re-calling with the same pair is a no-op. - Future calls to send message between the two users return
403 CONVERSATION_BLOCKED. - The matcher will not produce new matches between the two users.
Phase 4 does not automatically archive existing conversations on block — the conversation row remains, but every send is rejected at the gate. A future iteration may flip the conversation’s
status to BLOCKED for clarity in admin tooling; mobile clients should NOT rely on status as the block signal — CONVERSATION_BLOCKED from a send attempt is the authoritative answer.See also
- Unblock user — the inverse.
- Report user — record a moderation report alongside (or instead of) a block.
- Match → Conversation handshake — explains the
CONVERSATION_BLOCKEDgate.
curl
curl -X POST https://api.swappr.co.uk/api/v1/chat/blocks \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"blockedUserId": "66400a8f1c2b4d5e6f7a8b01"
}'