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

# Favorite chat or message

> Marks an entire chat or a specific message as a favorite

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

## Description

Marks **a chat** as favorite (by passing `number`) **or** **a specific message** (by passing `messageId`). At least one of the two must be present.

<Info>
  When both are provided, **`messageId` takes precedence**, the favorite is recorded on the message.
</Info>

## Examples

### Favorite a chat

Marks the entire conversation as a favorite by passing only `number`. Use this to highlight important contacts in the list, without tying the favorite to a specific message.

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

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

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

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

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

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

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

### Favorite a message

Favorites a specific message via `messageId`. When both fields are sent, `messageId` takes precedence and the favorite is recorded on the message instead of the chat.

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

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

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

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

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

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

  func main() {
      body := strings.NewReader(`{
          "messageId": "3EB08FCF27E532F1B0F5",
          "favorite":  true
      }`)
      req, _ := http.NewRequest("POST", "https://ryzeapi.cloud/api/chat/favorite/"+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>

### Remove favorite

With `favorite: false`, undoes the previously recorded favorite on the chat or the message (depending on which field was provided, same precedence rule as in the previous examples).

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

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

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

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

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

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

  func main() {
      body := strings.NewReader(`{
          "messageId": "3EB08FCF27E532F1B0F5",
          "favorite":  false
      }`)
      req, _ := http.NewRequest("POST", "https://ryzeapi.cloud/api/chat/favorite/"+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 `type` field indicates what was marked: `"chat"` when you favorited the entire conversation, or `"message"` when you passed a `messageId` (in that case `message_id` is filled in). `chat_jid` is always returned. `favorite` reflects the final state.

```json 200 OK theme={null}
{
  "success": true,
  "message": "Message favorited successfully",
  "chat_jid": "5511999999999@s.whatsapp.net",
  "message_id": "3EB08FCF27E532F1B0F5",
  "favorite": true,
  "type": "message"
}
```

## 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">
  Phone number or JID. Use to favorite the **entire chat**.
</ParamField>

<ParamField body="messageId" type="string">
  Message ID. Use to favorite a **specific message**. Takes precedence over `number`.
</ParamField>

<ParamField body="favorite" type="boolean" required>
  `true` favorites, `false` removes the favorite.
</ParamField>

<Note>
  You must send **at least one** of `number` and `messageId`.
</Note>

## Error responses

| HTTP | `error.message`                          | When it happens             |
| ---- | ---------------------------------------- | --------------------------- |
| 400  | `Instance name is required`              | ,                           |
| 400  | `Invalid request body: <...>`            | Malformed JSON.             |
| 400  | `Either number or messageId is required` | Neither provided.           |
| 401  | `Invalid token`                          | ,                           |
| 404  | `Instance not found`                     | ,                           |
| 404  | `Message not found`                      | `messageId` does not exist. |
| 503  | `Instance is not connected to WhatsApp`  | ,                           |

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

## Related

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

  <Card title="Find message" href="/en/api/chat/find-message">
    Retrieve a favorited message.
  </Card>
</CardGroup>
