POST
/
api
/
v1
/
chat
/
conversations
/
:id
/
read
Mark conversation read
curl --request POST \
  --url https://api.example.com/api/v1/chat/conversations/:id/read
import requests

url = "https://api.example.com/api/v1/chat/conversations/:id/read"

response = requests.post(url)

print(response.text)
const options = {method: 'POST'};

fetch('https://api.example.com/api/v1/chat/conversations/:id/read', 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/conversations/:id/read",
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/conversations/:id/read"

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/conversations/:id/read")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.example.com/api/v1/chat/conversations/:id/read")

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 that the caller has read all messages in this conversation up to and including upToMessageId. Two things happen server-side:
  1. Every message in this conversation created at or before upToMessageId.createdAt, not sent by the caller, and without an existing readBy entry for the caller, gets a readBy entry appended. The append is atomic and bulk: a single updateMany, not one update per message.
  2. The caller’s participantState[*].unreadCount is reset to 0 and lastReadMessageId is set to upToMessageId.
The newlyReceiptedCount in the response is the count of messages whose readBy was newly added in step 1 — useful for the client to decide whether to broadcast a chat:message:read socket event (a 0 count is a no-op and can be suppressed). Mark-read is also available as a socket event (chat:read) — same service method, same dedup. See Socket events.

Authentication

Bearer <accessToken> required. requireOnboarded middleware applied.

Path parameters

NameTypeRequiredNotesExample
idstringyes24-char hex ObjectId of the conversation.66400a8f1c2b4d5e6f7a9000

Query parameters

None.

Request body

FieldTypeRequiredAllowed valuesExample
upToMessageIdstringyes24-char hex ObjectId of a message in this conversation. Inclusive cursor: all messages with createdAt <= upToMessageId.createdAt get a receipt.66400a8f1c2b4d5e6f7aa001

Example payload

{
  "upToMessageId": "66400a8f1c2b4d5e6f7aa001"
}

Response — 200 OK

FieldTypeNotesExample
newlyReceiptedCountintegerNumber of messages whose readBy was newly added. Zero on a no-op (e.g. the caller had already marked everything read).1

Example response

{
  "newlyReceiptedCount": 1
}

Error responses

StatusCodeMeaning
400VALIDATION_FAILEDupToMessageId missing or not a 24-char hex ObjectId.
401UNAUTHENTICATEDMissing, malformed, or expired access token.
403ONBOARDING_INCOMPLETECaller has not finished onboarding.
403FORBIDDENCaller is not a participant of this conversation.
404NOT_FOUNDNo conversation with that id.
If upToMessageId is a valid ObjectId but doesn’t reference a message in this conversation, the call returns 200 { "newlyReceiptedCount": 0 } (no rows match the bulk update). It does not 404 — the message id is a cursor hint, not a strict reference.

Side effects

  • Bulk readBy append on the matching messages rows (one DB round trip).
  • participantState[caller].unreadCount = 0.
  • participantState[caller].lastReadMessageId = upToMessageId.
  • (When called over the socket transport) a chat:message:read broadcast is emitted to the conversation:<id> room so the sender’s UI can update its delivery indicators in real time. The REST endpoint does not emit the broadcast — callers that want live read-receipts should use the socket event.

See also

curl

curl -X POST https://api.swappr.co.uk/api/v1/chat/conversations/66400a8f1c2b4d5e6f7a9000/read \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "upToMessageId": "66400a8f1c2b4d5e6f7aa001"
  }'