> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wappfy.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Labels

> अपने chats और contacts को organize करने के लिए WhatsApp Business labels बनाएं और manage करें।

# Labels

Labels एक WhatsApp Business feature है जो आपको अपने chats को categorize और organize करने की सुविधा देता है। Wappfy API के माध्यम से, आप custom labels बना सकते हैं, उन्हें chats पर assign कर सकते हैं, और label के अनुसार chats प्राप्त कर सकते हैं।

<Note>
  Labels केवल WhatsApp Business accounts पर उपलब्ध हैं। Personal WhatsApp accounts labels को support नहीं करते।
</Note>

सभी label endpoints एक specific instance से जुड़े हैं:

```
/api/instances/{instanceId}/labels/...
```

***

## एक Label बनाएं

एक name और color के साथ नया label बनाएं।

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.wappfy.io/api/instances/inst_abc123/labels \
    -H "X-Api-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "VIP Customer",
      "color": 1
    }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/labels",
    {
      method: "POST",
      headers: {
        "X-Api-Key": "YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        name: "VIP Customer",
        color: 1,
      }),
    }
  );

  const label = await response.json();
  console.log(label.data.id);
  ```
</CodeGroup>

**Response:**

```json theme={null}
{
  "data": {
    "id": "1",
    "name": "VIP Customer",
    "color": 1
  }
}
```

### Label Colors

WhatsApp Business number द्वारा पहचाने जाने वाले label colors का एक निश्चित सेट support करता है:

| Color ID | Color      |
| -------- | ---------- |
| `0`      | हल्का ग्रे |
| `1`      | हरा        |
| `2`      | नीला       |
| `3`      | पीला       |
| `4`      | गुलाबी/लाल |

***

## Labels की सूची

Instance की सभी labels प्राप्त करें।

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.wappfy.io/api/instances/inst_abc123/labels \
    -H "X-Api-Key: YOUR_API_KEY"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/labels",
    {
      headers: { "X-Api-Key": "YOUR_API_KEY" },
    }
  );

  const { data } = await response.json();
  data.forEach((label) => {
    console.log(`${label.id}: ${label.name} (color: ${label.color})`);
  });
  ```
</CodeGroup>

**Response:**

```json theme={null}
{
  "data": [
    { "id": "1", "name": "New Customer", "color": 0 },
    { "id": "2", "name": "VIP Customer", "color": 1 },
    { "id": "3", "name": "Pending Payment", "color": 3 },
    { "id": "4", "name": "Resolved", "color": 2 }
  ]
}
```

***

## एक Label Update करें

किसी मौजूदा label का name या color update करें।

```bash theme={null}
curl -X PUT https://api.wappfy.io/api/instances/inst_abc123/labels/2 \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Premium Customer",
    "color": 2
  }'
```

***

## एक Label Delete करें

एक label को स्थायी रूप से delete करें। यह label को उन सभी chats से हटा देता है जिन पर यह assign था।

```bash theme={null}
curl -X DELETE https://api.wappfy.io/api/instances/inst_abc123/labels/2 \
  -H "X-Api-Key: YOUR_API_KEY"
```

<Warning>
  किसी label को delete करने से वह सभी संबंधित chats से हट जाता है। यह action पूर्ववत नहीं किया जा सकता।
</Warning>

***

## Chat Labels

### किसी Chat के Labels प्राप्त करें

किसी specific chat पर assign किए गए सभी labels प्राप्त करें।

```bash theme={null}
curl https://api.wappfy.io/api/instances/inst_abc123/labels/chats/5511999998888@s.whatsapp.net \
  -H "X-Api-Key: YOUR_API_KEY"
```

**Response:**

```json theme={null}
{
  "data": [
    { "id": "1", "name": "New Customer", "color": 0 },
    { "id": "3", "name": "Pending Payment", "color": 3 }
  ]
}
```

### Chat पर Labels Set करें

एक chat पर एक या अधिक labels assign करें। यह chat पर मौजूदा किसी भी labels को replace कर देता है।

<CodeGroup>
  ```bash cURL theme={null}
  curl -X PUT https://api.wappfy.io/api/instances/inst_abc123/labels/chats/5511999998888@s.whatsapp.net \
    -H "X-Api-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "label_ids": ["1", "2"]
    }'
  ```

  ```javascript Node.js theme={null}
  await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/labels/chats/5511999998888@s.whatsapp.net",
    {
      method: "PUT",
      headers: {
        "X-Api-Key": "YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        label_ids: ["1", "2"],
      }),
    }
  );
  ```
</CodeGroup>

<Tip>
  किसी chat से सभी labels हटाने के लिए, एक empty array pass करें: `{"label_ids": []}`।
</Tip>

### Label के अनुसार Chats प्राप्त करें

किसी specific label assign किए गए सभी chats प्राप्त करें।

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.wappfy.io/api/instances/inst_abc123/labels/2/chats \
    -H "X-Api-Key: YOUR_API_KEY"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch(
    "https://api.wappfy.io/api/instances/inst_abc123/labels/2/chats",
    {
      headers: { "X-Api-Key": "YOUR_API_KEY" },
    }
  );

  const { data } = await response.json();
  console.log(`${data.length} chats with the "VIP Customer" label`);
  ```
</CodeGroup>

**Response:**

```json theme={null}
{
  "data": [
    {
      "chat_id": "5511999998888@s.whatsapp.net",
      "name": "Maria Silva"
    },
    {
      "chat_id": "5511888887777@s.whatsapp.net",
      "name": "Carlos Oliveira"
    }
  ]
}
```

***

## सामान्य उपयोग के मामले

<AccordionGroup>
  <Accordion title="नए leads को स्वचालित रूप से tag करना">
    `message.received` events को सुनने के लिए webhook का उपयोग करें। जब किसी अज्ञात contact से message आए, तो API के माध्यम से "New Lead" label assign करें। यह आपकी team को नई बातचीत को तेजी से पहचानने और प्राथमिकता देने में मदद करता है।
  </Accordion>

  <Accordion title="Support ticket status track करना">
    "Open", "In Progress", और "Resolved" जैसे labels बनाएं। जैसे-जैसे आपकी team support requests पर काम करती है, label को update करें। एक simple support queue बनाने के लिए "Label के अनुसार Chats प्राप्त करें" endpoint का उपयोग करें।
  </Accordion>

  <Accordion title="Broadcasts के लिए customers को segment करना">
    Customers को category के अनुसार label करें (जैसे, "VIP", "Wholesale", "Retail")। Broadcast messages भेजते समय, एक label के लिए सभी chats fetch करें और loop में messages भेजें।
  </Accordion>
</AccordionGroup>

***

## Endpoint Reference

| Method   | Endpoint                                     | विवरण                              |
| -------- | -------------------------------------------- | ---------------------------------- |
| `POST`   | `/api/instances/{id}/labels`                 | नया label बनाएं                    |
| `GET`    | `/api/instances/{id}/labels`                 | सभी labels की सूची                 |
| `PUT`    | `/api/instances/{id}/labels/{labelId}`       | Label update करें                  |
| `DELETE` | `/api/instances/{id}/labels/{labelId}`       | Label delete करें                  |
| `GET`    | `/api/instances/{id}/labels/chats/{chatId}`  | Chat के labels प्राप्त करें        |
| `PUT`    | `/api/instances/{id}/labels/chats/{chatId}`  | Chat पर labels set करें            |
| `GET`    | `/api/instances/{id}/labels/{labelId}/chats` | Label के अनुसार chats प्राप्त करें |

***

## Error Handling

| Status Code | विवरण                                         |
| ----------- | --------------------------------------------- |
| `400`       | अमान्य label color या आवश्यक fields गायब हैं। |
| `404`       | Label या chat नहीं मिला।                      |
| `409`       | समान name वाला label पहले से मौजूद है।        |
| `422`       | अमान्य chat ID format।                        |
