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

# Fijar mensaje

> Fija (pin) o desfija un mensaje dentro de un chat

**Auth:** `TokenAccount` o `TokenInstance` • **Rate-limit:** `Global` (100/min) • **Idempotente:** sí

## Descripción

Fija (`pin: true`) o desfija (`pin: false`) un mensaje **dentro** de un chat. El chat, el autor del mensaje y la dirección (`fromMe`) se resuelven automáticamente a partir del `messageId`, solo necesitas indicar el mensaje.

<Warning>
  A diferencia de **marcar como favorito** (que es privado y silencioso), fijar un mensaje es una acción **visible para todos** los participantes de la conversación: WhatsApp muestra "fijó un mensaje". El protocolo solo ofrece "fijar para todos", no existe fijar solo para ti.
</Warning>

<Note>
  El mensaje debe existir en la base de datos de la instancia (haber sido recibido/enviado por ella). De lo contrario, la API devuelve `message with ID ... not found`.
</Note>

## Ejemplos

### Fijar

Con `pin: true`, el mensaje se fija en la parte superior del chat durante el tiempo definido en `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>

### Desfijar

Con `pin: false`, el mensaje se desfija. El campo `duration` se ignora.

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

## Respuesta de éxito

`chat_jid` se resuelve a partir del `messageId`, `pinned` refleja el estado final y `duration` se devuelve solo al fijar. El `message` cambia según `pin`: `"Message pinned successfully"` o `"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 ruta

<ParamField path="instance" type="string" required>
  Nombre de la instancia.
</ParamField>

## Headers

| Nombre         | Obligatorio            | Ejemplo            | Descripción                   |
| -------------- | ---------------------- | ------------------ | ----------------------------- |
| `Content-Type` | sí                     | `application/json` | ,                             |
| `token`        | sí (o `Authorization`) | `a1b2c3d4-...`     | TokenAccount o TokenInstance. |

## Request body

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

<ParamField body="messageId" type="string" required>
  ID del mensaje a fijar/desfijar. El chat y el autor se resuelven automáticamente a partir de él.
</ParamField>

<ParamField body="duration" type="string" default="7d">
  Cuánto tiempo permanece fijado el mensaje: `"24h"`, `"7d"` o `"30d"`. Solo se usa cuando `pin: true`; se ignora al desfijar.
</ParamField>

## Respuestas de error

| HTTP | `error.message`                                      | Cuándo ocurre                                             |
| ---- | ---------------------------------------------------- | --------------------------------------------------------- |
| 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`                    | El mensaje no existe en la base de datos de la instancia. |
| 500  | `invalid duration "<...>": use "24h", "7d" or "30d"` | Valor de `duration` inválido.                             |
| 500  | `WhatsApp client is not connected`                   | Instancia desconectada.                                   |

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

## Relacionados

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

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