> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nodeloc.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Direct Messages and Chat

> List chats, send messages to people or groups, paginate history, and manage read positions

Every endpoint requires a [NodeLoc session](https://docs.nodeloc.com/en/api-reference/v1/accounts.md). Use `Content-Type: application/json` when sending a JSON body.

## Find a conversation

Call `GET /api/v1/chat` for the overview. It returns `directs` (direct messages), `channels`, `groups` (group chats you belong to), `directs_next`, and `unread_count`. Each list item's numeric `id` is a conversation ID. In a direct entry, `with` is the other person's username. In a channel entry, `joined` shows whether you are a member.

| What you want to access | Identifier in the path |
| - | - |
| Read or send a direct message | `/api/v1/messages/{username}` uses the other person's username. |
| Read or send channel and group messages | `/api/v1/chat/channels/{id}/messages` uses a conversation ID. |
| Set the read position or mute a conversation | `/api/v1/chat/conversations/{id}/...` uses a conversation ID for all three kinds of chat. |
| Delete a message | `/api/v1/chat/messages/{id}` uses the message's own ID. |

### Page through direct conversations

Call `GET /api/v1/messages?limit=30` for the direct conversation list. The response has `conversations`, `next`, and a direct-message `unread_count`. The list is ordered by most recent message. The default `limit` is 30 and the range is 1–100. To fetch the next page, pass both values from `next`, `before` (an RFC 3339 time) and `before_id` (a conversation ID). URL-encode the time in the query string. For example, `{"before":"2026-11-29T08:30:00Z","before_id":17}` becomes `?before=2026-11-29T08%3A30%3A00Z&before_id=17`. You can also begin paging from the overview's `directs_next`. The overview can include older unread conversations, so merge pages by `id`. Stop when `next` is `null`. A full page can be followed by an empty page.

## Read and paginate messages

This example uses `GET /api/v1/messages/alex?limit=1&read=0` to read the latest direct message. Channels and group chats use the same parameters and response shape, for example `GET /api/v1/chat/channels/28/messages?read=0`.

```json theme={null}
{
  "conversation_id": 17,
  "last_read_id": 96,
  "unread_count": 2,
  "next_before": 101,
  "messages": [
    {
      "id": 101,
      "from_me": false,
      "sender": "alex",
      "avatar": null,
      "html": "<p>See you tomorrow!</p>",
      "created_at": "2026-11-29T08:30:00Z"
    }
  ]
}
```

| Query parameter | Use |
| - | - |
| `limit` | 1–100 messages per page, defaulting to 30. |
| No cursor | Load the latest page in descending message ID order. |
| `before` | Send the previous page's `next_before` to load older messages, still newest first. Stop when the response omits `next_before`. |
| `after` | Send the latest local message ID to fetch newer messages in ascending ID order. If the page is full, continue with its last ID. |

Opening a direct chat with someone for the first time returns `{"messages":[]}`. Sending the first message creates the conversation. Message pages include `conversation_id` once the conversation exists. On the latest page, participants and joined members also get `last_read_id` and `unread_count` as they stood before the request. A deleted message remains in the list with `deleted: true` and empty `html`. A system message has an `event`. A quoted message is summarized in `reply`.

## Send or quote a message

Use `POST /api/v1/messages/{username}` for a direct message, or `POST /api/v1/chat/channels/{id}/messages` for a channel or group chat. Send the Markdown source as `raw`. To quote a message, set `reply_to` to the ID of a visible, undeleted ordinary message in the same conversation.

```json theme={null}
{
  "raw": "All right, **see you tomorrow**!",
  "reply_to": 101
}
```

Success returns HTTP `201` with a `message` object in the same shape as a message in the read response.

```json theme={null}
{
  "message": {
    "id": 102,
    "from_me": true,
    "sender": "sam",
    "avatar": null,
    "html": "<p>All right, <strong>see you tomorrow</strong>!</p>",
    "created_at": "2026-11-29T08:31:00Z",
    "reply": { "id": 101, "sender": "alex", "excerpt": "See you tomorrow!" }
  }
}
```

The body must have content. Direct messages allow up to 10,000 characters. Channel and group messages allow up to 4,000. Direct messaging depends on account permissions and the recipient's message settings. Any signed-in user can read a public channel. Sending requires membership and permission to post. Group chat reads and writes are limited to members.

## Read positions, muting, and membership

By default, fetching the latest page or polling with `after` advances the current user's read position. To fetch without advancing it, send `read=0`. After the user sees the message, use `PUT /api/v1/chat/conversations/{id}/read` with `{"message_id":102}`. Success returns `204`. Loading older messages with `before` leaves the position unchanged.

| Operation | Request and result |
| - | - |
| Get the chat unread total | `GET /api/v1/chat/unread` returns `{"unread_count":2}`. Muted direct chats contribute zero. Muted channels and groups contribute only unread messages that directly mention you. |
| Mute or unmute a conversation | `PUT /api/v1/chat/conversations/{id}/mute` mutes the conversation. `DELETE /api/v1/chat/conversations/{id}/mute` unmutes it. Both return `204`. |
| Join a channel | `PUT /api/v1/chat/channels/{id}/membership` returns `204`. |
| Leave a channel or group | `DELETE /api/v1/chat/channels/{id}/membership` returns `204`. A group owner can use `PUT /api/v1/chat/groups/{id}` with `{"owner":"lee"}` to transfer ownership before leaving, or use `DELETE /api/v1/chat/groups/{id}` to dissolve the group. |
| Create a group chat | `POST /api/v1/chat/groups` with `{"name":"Weekend plans","usernames":["alex","lee"]}` returns `201`, for example `{"group":{"id":42}}`. The name is optional. Invite at least two other members. |
| List group members | `GET /api/v1/chat/groups/{id}/members` returns `members`, `owner_me`, and `max_members`. |
| Delete a message | `DELETE /api/v1/chat/messages/{id}` returns `204`. Senders can delete their own messages. Group owners and chat moderators may delete messages within their permissions. |

## Common errors

| HTTP | `error.code` | Meaning |
| - | - | - |
| `400` | `invalid_message` | Marking a conversation as read requires a positive integer `message_id`. |
| `401` | `unauthorized` | A valid session is required. |
| `403` | `blocked`, `reply_only`, `trust_level_too_low`, `silenced` | The recipient's settings or the account's permissions prevent sending. |
| `403` | `not_member`, `staff_only` | Join the channel first, or the channel may allow only staff to post. |
| `404` | `not_found` | The user, conversation, or message is missing or hidden from the current account. |
| `422` | `invalid` | Check `error.fields`, for example for an empty body, an invalid reply target, or a malformed conversation cursor. |
| `429` | `rate_limited` | A sending rate or quota was reached. Follow `Retry-After`. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.