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

# Marcar chat o mensaje como favorito

> Marca un chat completo o un mensaje específico como favorito

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

## Descripción

Marca **un chat** como favorito (pasando `number`) **o** **un mensaje específico** (pasando `messageId`). Al menos uno de los dos debe estar presente.

<Info>
  Cuando se proporcionan ambos, **`messageId` tiene prioridad**, el favorito se registra en el mensaje.
</Info>

## Ejemplos

### Marcar chat como favorito

Marca la conversación entera como favorita pasando solo `number`. Úsalo para destacar contactos importantes en la lista, sin atar el favorito a un mensaje específico.

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

### Marcar mensaje como favorito

Marca un mensaje específico como favorito vía `messageId`. Cuando se envían ambos campos, `messageId` tiene prioridad y el favorito se registra en el mensaje en lugar del 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>

### Quitar favorito

Con `favorite: false`, deshace el favorito previamente registrado en el chat o el mensaje (según el campo proporcionado, misma regla de prioridad que en los ejemplos anteriores).

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

## Respuesta exitosa

El campo `type` indica qué se marcó: `"chat"` cuando marcaste la conversación entera, o `"message"` cuando pasaste un `messageId` (en ese caso `message_id` viene relleno). `chat_jid` siempre se devuelve. `favorite` refleja el estado final.

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

## Parámetros de ruta

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

## Cabeceras

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

## Cuerpo de la solicitud

<ParamField body="number" type="string">
  Número de teléfono o JID. Úsalo para marcar el **chat completo** como favorito.
</ParamField>

<ParamField body="messageId" type="string">
  ID del mensaje. Úsalo para marcar un **mensaje específico** como favorito. Tiene prioridad sobre `number`.
</ParamField>

<ParamField body="favorite" type="boolean" required>
  `true` marca como favorito, `false` quita el favorito.
</ParamField>

<Note>
  Debes enviar **al menos uno** de `number` y `messageId`.
</Note>

## Respuestas de error

| HTTP | `error.message`                          | Cuándo ocurre             |
| ---- | ---------------------------------------- | ------------------------- |
| 400  | `Instance name is required`              | ,                         |
| 400  | `Invalid request body: <...>`            | JSON malformado.          |
| 400  | `Either number or messageId is required` | Ninguno proporcionado.    |
| 401  | `Invalid token`                          | ,                         |
| 404  | `Instance not found`                     | ,                         |
| 404  | `Message not found`                      | El `messageId` no existe. |
| 503  | `Instance is not connected to WhatsApp`  | ,                         |

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

## Relacionados

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

  <Card title="Buscar mensaje" href="/es/api/chat/find-message">
    Recupera un mensaje marcado como favorito.
  </Card>
</CardGroup>
