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

# Assign label

> Applies a label to a chat

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

## Description

Assigns an existing label to a chat. If the label is already present on the chat, the operation is treated as success (idempotent). The change is propagated to WhatsApp via app state.

## Example

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

## Success response

The response confirms the assignment by echoing the applied `tag_id`. `chat_jid` is not included when the handler delegates only to the service (`omitempty` fields); rely on `success`/`message` for the operation result.

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

## 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 (`5511999999999`), private JID (`...@s.whatsapp.net` or `...@lid`), group JID (`...@g.us`), or newsletter.
</ParamField>

<ParamField body="tagId" type="string" required>
  ID of the label to assign.
</ParamField>

## Error responses

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

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

## Related

<CardGroup cols={2}>
  <Card title="Unassign label" href="/en/api/chat/tags-unassign">
    Remove the label from the chat.
  </Card>

  <Card title="Contacts by label" href="/en/api/chat/contacts-by-label">
    List every chat that has the label.
  </Card>
</CardGroup>
