> ## 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.

# Fixar mensagem

> Fixa (pin) ou desfixa uma mensagem dentro de um chat

**Auth:** `TokenAccount` ou `TokenInstance` • **Rate-limit:** `Global` (100/min) • **Idempotente:** sim

## Descrição

Fixa (`pin: true`) ou desfixa (`pin: false`) uma mensagem **dentro** de um chat. O chat, o autor da mensagem e a direção (`fromMe`) são resolvidos automaticamente a partir do `messageId`, você só precisa informar a mensagem.

<Warning>
  Ao contrário de **favoritar** (que é privado e silencioso), fixar uma mensagem é uma ação **visível para todos** os participantes da conversa: o WhatsApp exibe "fixou uma mensagem". O protocolo só oferece "fixar para todos", não existe fixar apenas para você.
</Warning>

<Note>
  A mensagem precisa existir no banco da instância (ter sido recebida/enviada por ela). Caso contrário a API retorna `message with ID ... not found`.
</Note>

## Exemplos

### Fixar

Com `pin: true`, a mensagem é fixada no topo do chat pelo tempo definido em `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>

### Desfixar

Com `pin: false`, a mensagem é desfixada. O campo `duration` é ignorado.

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

## Resposta de sucesso

`chat_jid` é resolvido a partir do `messageId`, `pinned` reflete o estado final e `duration` é ecoado apenas quando se fixa. A `message` muda conforme o `pin`: `"Message pinned successfully"` ou `"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"
}
```

## Parâmetros de rota

<ParamField path="instance" type="string" required>
  Nome da instância.
</ParamField>

## Headers

| Nome           | Obrigatório              | Exemplo            | Descrição                      |
| -------------- | ------------------------ | ------------------ | ------------------------------ |
| `Content-Type` | sim                      | `application/json` | ,                              |
| `token`        | sim (ou `Authorization`) | `a1b2c3d4-...`     | TokenAccount ou TokenInstance. |

## Request body

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

<ParamField body="messageId" type="string" required>
  ID da mensagem a fixar/desfixar. O chat e o autor são resolvidos automaticamente a partir dele.
</ParamField>

<ParamField body="duration" type="string" default="7d">
  Por quanto tempo a mensagem fica fixada: `"24h"`, `"7d"` ou `"30d"`. Usado apenas quando `pin: true`; ignorado ao desfixar.
</ParamField>

## Respostas de erro

| HTTP | `error.message`                                      | Quando ocorre                              |
| ---- | ---------------------------------------------------- | ------------------------------------------ |
| 400  | `Instance name is required`                          | ,                                          |
| 400  | `Invalid request body: <...>`                        | JSON malformado.                           |
| 400  | `messageId is required`                              | ,                                          |
| 401  | `Invalid token`                                      | ,                                          |
| 404  | `Instance not found`                                 | ,                                          |
| 500  | `message with ID <...> not found`                    | Mensagem não existe no banco da instância. |
| 500  | `invalid duration "<...>": use "24h", "7d" or "30d"` | Valor de `duration` inválido.              |
| 500  | `WhatsApp client is not connected`                   | Instância desconectada.                    |

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

## Relacionados

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

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