POST
/
api
/
v1
/
chat
/
blocks
Block a user
curl --request POST \
  --url https://api.example.com/api/v1/chat/blocks
import 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_body

Overview

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_BLOCKED for any existing match between the two users.
  • Send message (and the equivalent chat:message:send socket event) returns 403 CONVERSATION_BLOCKED if either side of an existing conversation tries to send.
  • The matcher (Phase 3+) treats a blocks row as a hard filter so no new match between the two users is ever produced.
Block is idempotent: calling it twice for the same 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

FieldTypeRequiredAllowed valuesExample
blockedUserIdstringyes24-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

FieldTypeNotesExample
blockedbooleanAlways true on success. Present as a positive ack for the mobile client.true

Example response

{
  "blocked": true
}

Error responses

StatusCodeMeaning
400VALIDATION_FAILEDblockedUserId missing, not a 24-char hex ObjectId, or equal to the caller’s id (cannot block yourself).
401UNAUTHENTICATEDMissing, malformed, or expired access token.
403ONBOARDING_INCOMPLETECaller 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 blocks row is upserted with blockerId = 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

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"
  }'