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

> Pins or unpins a chat at the top of the list

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

## Description

Marks a chat as pinned (`pin: true`) or removes the pin (`pin: false`).

<Warning>
  WhatsApp limits to **3 pinned chats** simultaneously. Trying to pin a fourth returns a WhatsMeow error propagated to the response.
</Warning>

## Examples

### Pin

With `pin: true`, the chat moves to the top of the list. Remember WhatsApp allows at most 3 pinned chats at the same time, trying a fourth returns an error.

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

### Unpin

With `pin: false`, removes the pin and the chat returns to normal sorting by activity. Frees a slot in the limit of 3 pinned chats.

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

## Success response

The response confirms the operation with `chat_jid` (JID resolved from `number`) and `pinned` reflecting the final state. The `message` changes depending on the value of `pin`: `"Chat pinned successfully"` or `"Chat unpinned successfully"`.

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

## 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="number" type="string" required>
  Phone number, private JID (`...@s.whatsapp.net` or `...@lid`), group JID (`...@g.us`), or newsletter.
</ParamField>

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

## Error responses

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

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

## Related

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

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