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

# Asignar etiqueta

> Aplica una etiqueta a un chat

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

## Descripción

Asigna una etiqueta existente a un chat. Si la etiqueta ya está presente en el chat, la operación se considera exitosa (idempotente). El cambio se propaga a WhatsApp vía app state.

## Ejemplo

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

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

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

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

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

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

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

La respuesta confirma la asignación devolviendo el `tag_id` aplicado. `chat_jid` no se incluye cuando el handler delega solo al servicio (campos `omitempty`); confía en `success`/`message` para el resultado de la operación.

```json 200 OK theme={null}
{
  "success": true,
  "message": "Tag assigned successfully",
  "tag_id": "2"
}
```

## 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" required>
  Número de teléfono (`5511999999999`), JID privado (`...@s.whatsapp.net` o `...@lid`), JID de grupo (`...@g.us`) o newsletter.
</ParamField>

<ParamField body="tagId" type="string" required>
  ID de la etiqueta a asignar.
</ParamField>

## Respuestas de error

| HTTP | `error.message`                         | Cuándo ocurre         |
| ---- | --------------------------------------- | --------------------- |
| 400  | `Instance name is required`             | ,                     |
| 400  | `Invalid request body: <...>`           | JSON malformado.      |
| 400  | `Number is required`                    | ,                     |
| 400  | `tagId is required`                     | ,                     |
| 401  | `Invalid token`                         | ,                     |
| 404  | `Instance not found`                    | ,                     |
| 404  | `Tag not found`                         | El `tagId` no existe. |
| 503  | `Instance is not connected to WhatsApp` | ,                     |

```json Error 404 theme={null}
{
  "success": false,
  "error": { "message": "Tag not found" }
}
```

## Relacionados

<CardGroup cols={2}>
  <Card title="Desasignar etiqueta" href="/es/api/chat/tags-unassign">
    Quita la etiqueta del chat.
  </Card>

  <Card title="Contactos por etiqueta" href="/es/api/chat/contacts-by-label">
    Lista todos los chats que tienen la etiqueta.
  </Card>
</CardGroup>
