---
title: "Load message context around a target (for \"jump to message\" UX)"
method: GET
path: "/v2/apps/{appId}/chats/{chatId}/messages/context"
tags: ["Chats"]
---

# Load message context around a target (for "jump to message" UX)

`GET /v2/apps/{appId}/chats/{chatId}/messages/context`

## Request

- Base URL: `https://api.chat.ethora.com`
- URL: `https://api.chat.ethora.com/v2/apps/{appId}/chats/{chatId}/messages/context`
- Auth: one of:
  - HTTP bearer
  - HTTP bearer

**Auth**: Tenant Actor

Returns the target message plus `radius` messages on each side, all
from the same Mongo archive as `/messages/search`. Built for the
"user clicks a search hit → land in the right spot of the chat" flow:
one request gives the surrounding window of history so the frontend
can render it and scroll the target into view.

Reads come from the archive (not MAM) so that whatever the search
endpoint returned is guaranteed to be present in the context window.

Pagination semantics use a `(createdAt, _id)` tie-break, so two
messages with the same millisecond timestamp don't reshuffle between
requests. Use `hasMoreBefore` / `hasMoreAfter` to decide whether to
fetch the next outer window.

Visibility identical to search: B2B sees everything, user tokens
must have access to the requested chat (groupchat membership or
private-chat participant), otherwise 403.

## Path parameters

- `appId` string, required
- `chatId` string, required

## Query parameters

- `aroundStanzaId` string
- `aroundMessageId` string
- `radius` integer

## Response `200`

Items are returned in chronological order (oldest first), with
the target somewhere in the middle.
```
{
  items: [
    { _id, appId, chatId, chatType, room, from, fromUserId,
      to, toUserId, body, messageId, stanzaId, createdAt }
  ],
  target: { ...same shape as items[N]... },
  hasMoreBefore: boolean,
  hasMoreAfter:  boolean,
  appId, chatId, radius
}
```

## Other responses

- `400`: Bad Request
- `401`: Unauthorized
- `403`: User token has no access to this chat. ``` { error: string, code: 'CHAT_FORBIDDEN', details: { chatId } } ```
- `404`: No message with that stanzaId / messageId in this chat's archive. ``` { error: string, code: 'TARGET_NOT_FOUND', details: { chatId, aroundStanzaId, aroundMessageId } } ```
- `422`: Validation error — missing chatId, missing both around* params, radius out of [0..50]. ``` { error: string, code: 'VALIDATION_ERROR' } ```
- `500`: Internal Server Error

---

[API](https://skmtc.dev/ethora/apis/platform-api.md) · [All operations](https://skmtc.dev/ethora/apis/platform-api/llms.txt) · [OpenAPI document](https://skmtc.dev/ethora/apis/platform-api/revisions/01b6e64378ee?raw)
