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

# Contacts by label

> Filters chats that have one or more labels assigned

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

## Description

Returns chats that have at least one of the given labels. You can filter by **IDs**, by **names** (case-insensitive), or return every chat that has any label at all.

<Tip>
  Use `refresh=true` to force a sync with WhatsApp before listing, useful when a label was changed on the phone and you want the latest data.
</Tip>

## Examples

### By IDs

Filters chats that have at least one of the labels listed in `?labelIds=1,2`. Useful when you already know the IDs from [`/tags-list`](/en/api/chat/tags-list).

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://ryzeapi.cloud/api/chat/contactsByLabel/$Instance_Name?labelIds=1,2" \
    -H "token: $Token_Instance"
  ```

  ```javascript JavaScript theme={null}
  await fetch(`https://ryzeapi.cloud/api/chat/contactsByLabel/${process.env.Instance_Name}?labelIds=1,2`, {
    method: "GET",
    headers: {
      "token": process.env.Token_Instance
    }
  });
  ```

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

  requests.get(
      f"https://ryzeapi.cloud/api/chat/contactsByLabel/{os.environ['Instance_Name']}?labelIds=1,2",
      headers={"token": os.environ["Token_Instance"]}
  )
  ```

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

  import (
      "net/http"
      "os"
  )

  func main() {
      req, _ := http.NewRequest("GET", "https://ryzeapi.cloud/api/chat/contactsByLabel/"+os.Getenv("Instance_Name")+"?labelIds=1,2", nil)
      req.Header.Set("token", os.Getenv("Token_Instance"))
      http.DefaultClient.Do(req)
  }
  ```
</CodeGroup>

### By names (with refresh)

Filters by name via `?labelNames=VIP,Support` (case-insensitive) and adds `refresh=true` to force a sync with WhatsApp before listing, ensuring changes made on the phone are already visible.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://ryzeapi.cloud/api/chat/contactsByLabel/$Instance_Name?labelNames=VIP,Support&refresh=true" \
    -H "token: $Token_Instance"
  ```

  ```javascript JavaScript theme={null}
  await fetch(`https://ryzeapi.cloud/api/chat/contactsByLabel/${process.env.Instance_Name}?labelNames=VIP,Support&refresh=true`, {
    method: "GET",
    headers: {
      "token": process.env.Token_Instance
    }
  });
  ```

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

  requests.get(
      f"https://ryzeapi.cloud/api/chat/contactsByLabel/{os.environ['Instance_Name']}?labelNames=VIP,Support&refresh=true",
      headers={"token": os.environ["Token_Instance"]}
  )
  ```

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

  import (
      "net/http"
      "os"
  )

  func main() {
      req, _ := http.NewRequest("GET", "https://ryzeapi.cloud/api/chat/contactsByLabel/"+os.Getenv("Instance_Name")+"?labelNames=VIP,Support&refresh=true", nil)
      req.Header.Set("token", os.Getenv("Token_Instance"))
      http.DefaultClient.Do(req)
  }
  ```
</CodeGroup>

### All with labels

Without `labelIds` or `labelNames`, returns every chat that has any label assigned. Useful to audit the overall use of labels on the account.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://ryzeapi.cloud/api/chat/contactsByLabel/$Instance_Name" \
    -H "token: $Token_Instance"
  ```

  ```javascript JavaScript theme={null}
  await fetch(`https://ryzeapi.cloud/api/chat/contactsByLabel/${process.env.Instance_Name}`, {
    method: "GET",
    headers: {
      "token": process.env.Token_Instance
    }
  });
  ```

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

  requests.get(
      f"https://ryzeapi.cloud/api/chat/contactsByLabel/{os.environ['Instance_Name']}",
      headers={"token": os.environ["Token_Instance"]}
  )
  ```

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

  import (
      "net/http"
      "os"
  )

  func main() {
      req, _ := http.NewRequest("GET", "https://ryzeapi.cloud/api/chat/contactsByLabel/"+os.Getenv("Instance_Name"), nil)
      req.Header.Set("token", os.Getenv("Token_Instance"))
      http.DefaultClient.Do(req)
  }
  ```
</CodeGroup>

## Success response

`chats` is a list of `ChatWithLabels` objects grouping every label associated with each chat. Use `total_chats` for the number of unique chats and `total_rows` for the total number of chat-label pairs. `refreshed` indicates whether the cache was rebuilt in this call (`refresh=true`); `filter_label_ids` repeats the IDs effectively applied.

```json 200 OK theme={null}
{
  "success": true,
  "message": "Chats by label retrieved successfully",
  "chats": [
    {
      "chat_jid": "5511999999999@s.whatsapp.net",
      "labels": [
        { "id": "1", "name": "Important" }
      ]
    },
    {
      "chat_jid": "5511988887777@s.whatsapp.net",
      "labels": [
        { "id": "1", "name": "Important" },
        { "id": "2", "name": "VIP" }
      ]
    }
  ],
  "total_chats": 2,
  "total_rows": 3,
  "refreshed": false,
  "filter_label_ids": ["1"]
}
```

## Path parameters

<ParamField path="instance" type="string" required>
  Instance name.
</ParamField>

## Headers

| Name    | Required                 | Example        | Description                    |
| ------- | ------------------------ | -------------- | ------------------------------ |
| `token` | yes (or `Authorization`) | `a1b2c3d4-...` | TokenAccount or TokenInstance. |

## Query params

<ParamField query="labelIds" type="string">
  Label IDs separated by comma. Example: `"1,2,3"`.
</ParamField>

<ParamField query="labelNames" type="string">
  Label names separated by comma (case-insensitive). Example: `"VIP,Support"`.
</ParamField>

<ParamField query="refresh" type="boolean" default="false">
  If `true`, syncs labels with WhatsApp before returning.
</ParamField>

<Note>
  Without `labelIds` or `labelNames`, returns **every** chat that has any label.
</Note>

## Error responses

| HTTP | `error.message`                         | When it happens               |
| ---- | --------------------------------------- | ----------------------------- |
| 400  | `Instance name is required`             | Empty `:instance`.            |
| 401  | `Invalid token`                         | ,                             |
| 404  | `Instance not found`                    | ,                             |
| 503  | `Instance is not connected to WhatsApp` | Required when `refresh=true`. |

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

## Related

<CardGroup cols={2}>
  <Card title="List labels" href="/en/api/chat/tags-list">
    Retrieve IDs and names to use in the filter.
  </Card>

  <Card title="Assign label" href="/en/api/chat/tags-assign">
    Add a label to a chat.
  </Card>
</CardGroup>
