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

> Fixa (pin) ou desfixa um chat no topo da lista

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

## Descrição

Marca um chat como fixado (`pin: true`) ou remove a fixação (`pin: false`).

<Warning>
  O WhatsApp limita a **3 chats fixados** simultaneamente. Tentar fixar um quarto retorna erro do WhatsMeow propagado para a resposta.
</Warning>

## Exemplos

### Fixar

Com `pin: true`, o chat é movido para o topo da lista. Lembre que o WhatsApp permite no máximo 3 chats fixados ao mesmo tempo, tentar um quarto retorna erro.

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

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

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

  requests.post(
      f"https://ryzeapi.cloud/api/chat/pinChat/{os.environ['Instance_Name']}",
      headers={
          "token":        os.environ["Token_Instance"],
          "Content-Type": "application/json"
      },
      json={
          "number": "5511999999999",
          "pin":    True
      }
  )
  ```

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

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

  func main() {
      body := strings.NewReader(`{
          "number": "5511999999999",
          "pin":    true
      }`)
      req, _ := http.NewRequest("POST", "https://ryzeapi.cloud/api/chat/pinChat/"+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`, remove a fixação e o chat volta a ordenar normalmente por atividade. Libera espaço no limite de 3 fixados.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://ryzeapi.cloud/api/chat/pinChat/$Instance_Name" \
    -H "token: $Token_Instance" \
    -H "Content-Type: application/json" \
    -d '{
      "number": "5511999999999",
      "pin":    false
    }'
  ```

  ```javascript JavaScript theme={null}
  await fetch(`https://ryzeapi.cloud/api/chat/pinChat/${process.env.Instance_Name}`, {
    method: "POST",
    headers: {
      "token":        process.env.Token_Instance,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      number: "5511999999999",
      pin:    false
    })
  });
  ```

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

  requests.post(
      f"https://ryzeapi.cloud/api/chat/pinChat/{os.environ['Instance_Name']}",
      headers={
          "token":        os.environ["Token_Instance"],
          "Content-Type": "application/json"
      },
      json={
          "number": "5511999999999",
          "pin":    False
      }
  )
  ```

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

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

  func main() {
      body := strings.NewReader(`{
          "number": "5511999999999",
          "pin":    false
      }`)
      req, _ := http.NewRequest("POST", "https://ryzeapi.cloud/api/chat/pinChat/"+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>

## Resposta de sucesso

A resposta confirma a operação com `chat_jid` (JID resolvido a partir do `number`) e `pinned` refletindo o estado final. A `message` muda conforme o valor de `pin`: `"Chat pinned successfully"` ou `"Chat unpinned successfully"`.

```json 200 OK theme={null}
{
  "success": true,
  "message": "Chat pinned successfully",
  "chat_jid": "5511999999999@s.whatsapp.net",
  "pinned": true
}
```

## 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="number" type="string" required>
  Telefone, JID privado (`...@s.whatsapp.net` ou `...@lid`), JID de grupo (`...@g.us`) ou newsletter.
</ParamField>

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

## Respostas de erro

| HTTP | `error.message`                         | Quando ocorre    |
| ---- | --------------------------------------- | ---------------- |
| 400  | `Instance name is required`             | ,                |
| 400  | `Invalid request body: <...>`           | JSON malformado. |
| 400  | `Number is required`                    | ,                |
| 401  | `Invalid token`                         | ,                |
| 404  | `Instance not found`                    | ,                |
| 503  | `Instance is not connected to WhatsApp` | ,                |

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

## Relacionados

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

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