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

# Pin message

> Pin or unpin a message inside a chat

**Auth:** `TokenAccount` or `TokenInstance` • **Rate-limit:** `Global` (100/min) • **Idempotent:** yes

## Description

Pins (`pin: true`) or unpins (`pin: false`) a message **inside** a chat. The chat, the message author and the direction (`fromMe`) are resolved automatically from `messageId`, you only need to provide the message.

<Warning>
  Unlike **favoriting** (which is private and silent), pinning a message is an action **visible to everyone** in the conversation: WhatsApp shows "pinned a message". The protocol only offers "pin for all", there is no pin-for-me-only.
</Warning>

<Note>
  The message must exist in the instance database (it must have been received/sent by it). Otherwise the API returns `message with ID ... not found`.
</Note>

## Examples

### Pin

With `pin: true`, the message is pinned to the top of the chat for the time set in `duration`.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://ryzeapi.cloud/api/chat/pinMessage/$Instance_Name" \
    -H "token: $Token_Instance" \
    -H "Content-Type: application/json" \
    -d '{
      "pin":       true,
      "messageId": "3EB0XXXXXXXXXXXXXXXX",
      "duration":  "7d"
    }'
  ```

  ```javascript JavaScript theme={null}
  await fetch(`https://ryzeapi.cloud/api/chat/pinMessage/${process.env.Instance_Name}`, {
    method: "POST",
    headers: {
      "token":        process.env.Token_Instance,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      pin:       true,
      messageId: "3EB0XXXXXXXXXXXXXXXX",
      duration:  "7d"
    })
  });
  ```

  ```python Python theme={null}
  import os, requests

  requests.post(
      f"https://ryzeapi.cloud/api/chat/pinMessage/{os.environ['Instance_Name']}",
      headers={
          "token":        os.environ["Token_Instance"],
          "Content-Type": "application/json"
      },
      json={
          "pin":       True,
          "messageId": "3EB0XXXXXXXXXXXXXXXX",
          "duration":  "7d"
      }
  )
  ```

  ```go Go theme={null}
  package main

  import (
      "net/http"
      "os"
      "strings"
  )

  func main() {
      body := strings.NewReader(`{
          "pin":       true,
          "messageId": "3EB0XXXXXXXXXXXXXXXX",
          "duration":  "7d"
      }`)
      req, _ := http.NewRequest("POST", "https://ryzeapi.cloud/api/chat/pinMessage/"+os.Getenv("Instance_Name"), body)
      req.Header.Set("token", os.Getenv("Token_Instance"))
      req.Header.Set("Content-Type", "application/json")
      http.DefaultClient.Do(req)
  }
  ```
</CodeGroup>

### Unpin

With `pin: false`, the message is unpinned. The `duration` field is ignored.

```bash cURL theme={null}
curl -X POST "https://ryzeapi.cloud/api/chat/pinMessage/$Instance_Name" \
  -H "token: $Token_Instance" \
  -H "Content-Type: application/json" \
  -d '{
    "pin":       false,
    "messageId": "3EB0XXXXXXXXXXXXXXXX"
  }'
```

## Success response

`chat_jid` is resolved from `messageId`, `pinned` reflects the final state and `duration` is echoed only when pinning. The `message` changes with `pin`: `"Message pinned successfully"` or `"Message unpinned successfully"`.

```json 200 OK theme={null}
{
  "success": true,
  "message": "Message pinned successfully",
  "chat_jid": "5511999999999@s.whatsapp.net",
  "message_id": "3EB0XXXXXXXXXXXXXXXX",
  "pinned": true,
  "duration": "7d"
}
```

## Path parameters

<ParamField path="instance" type="string" required>
  Instance name.
</ParamField>

## Headers

| Name           | Required                 | Example            | Description                    |
| -------------- | ------------------------ | ------------------ | ------------------------------ |
| `Content-Type` | yes                      | `application/json` | ,                              |
| `token`        | yes (or `Authorization`) | `a1b2c3d4-...`     | TokenAccount or TokenInstance. |

## Request body

<ParamField body="pin" type="boolean" required>
  `true` pins, `false` unpins.
</ParamField>

<ParamField body="messageId" type="string" required>
  ID of the message to pin/unpin. The chat and author are resolved automatically from it.
</ParamField>

<ParamField body="duration" type="string" default="7d">
  How long the message stays pinned: `"24h"`, `"7d"` or `"30d"`. Used only when `pin: true`; ignored when unpinning.
</ParamField>

## Error responses

| HTTP | `error.message`                                      | When it happens                                  |
| ---- | ---------------------------------------------------- | ------------------------------------------------ |
| 400  | `Instance name is required`                          | ,                                                |
| 400  | `Invalid request body: <...>`                        | Malformed JSON.                                  |
| 400  | `messageId is required`                              | ,                                                |
| 401  | `Invalid token`                                      | ,                                                |
| 404  | `Instance not found`                                 | ,                                                |
| 500  | `message with ID <...> not found`                    | Message does not exist in the instance database. |
| 500  | `invalid duration "<...>": use "24h", "7d" or "30d"` | Invalid `duration` value.                        |
| 500  | `WhatsApp client is not connected`                   | Instance disconnected.                           |

```json Error 400 theme={null}
{
  "success": false,
  "error": { "message": "messageId is required" }
}
```

## Related

<CardGroup cols={2}>
  <Card title="Pin chat" href="/en/api/chat/pinChat">
    `POST /api/chat/pinChat/:instance`
  </Card>

  <Card title="Favorite" href="/en/api/chat/favorite">
    `POST /api/chat/favorite/:instance`
  </Card>
</CardGroup>
