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

# Listar Tags

> Obtiene todos los tags únicos usados en tus contactos

Obtén una lista de todos los tags utilizados en tus contactos, ordenados por frecuencia de uso.

<Tip>
  Usa este endpoint para poblar dropdowns, autocompletado de tags, o para análisis de segmentación.
</Tip>

***

## Ejemplos

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET https://api.whaapy.com/contacts/v1/tags \
    -H "Authorization: Bearer wha_TU_API_KEY"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.whaapy.com/contacts/v1/tags', {
    headers: { 'Authorization': 'Bearer wha_TU_API_KEY' }
  });
  const data = await response.json();
  console.log(data.tags);
  ```

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

  response = requests.get(
      'https://api.whaapy.com/contacts/v1/tags',
      headers={'Authorization': 'Bearer wha_TU_API_KEY'}
  )
  print(response.json())
  ```

  ```php PHP theme={null}
  $ch = curl_init('https://api.whaapy.com/contacts/v1/tags');
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      'Authorization: Bearer wha_TU_API_KEY'
  ]);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  $response = curl_exec($ch);
  echo $response;
  ```
</RequestExample>

***

## Respuesta Exitosa

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "tags": [
      { "name": "lead", "count": 320 },
      { "name": "cliente", "count": 150 },
      { "name": "newsletter", "count": 89 },
      { "name": "premium", "count": 45 },
      { "name": "vip", "count": 12 },
      { "name": "campaña-enero", "count": 8 }
    ],
    "total_tags": 6
  }
  ```
</ResponseExample>

### Campos de la Respuesta

| Campo          | Tipo   | Descripción                          |
| -------------- | ------ | ------------------------------------ |
| `tags`         | array  | Array de objetos con nombre y conteo |
| `tags[].name`  | string | Nombre del tag                       |
| `tags[].count` | number | Número de contactos con este tag     |
| `total_tags`   | number | Total de tags únicos                 |

***

## Casos de Uso

<AccordionGroup>
  <Accordion title="Autocompletado en UI">
    Usa la lista de tags para sugerir opciones mientras el usuario escribe:

    ```javascript theme={null}
    const { tags } = await api.get('/contacts/v1/tags');
    const suggestions = tags
      .filter(t => t.name.includes(userInput))
      .map(t => t.name);
    ```
  </Accordion>

  <Accordion title="Dashboard de segmentación">
    Muestra la distribución de contactos por tag:

    ```javascript theme={null}
    const { tags, total_tags } = await api.get('/contacts/v1/tags');

    // Crear gráfico de barras con tags y conteos
    const chartData = tags.map(t => ({
      label: t.name,
      value: t.count
    }));
    ```
  </Accordion>

  <Accordion title="Validación de tags">
    Verifica que un tag existe antes de usarlo:

    ```javascript theme={null}
    const { tags } = await api.get('/contacts/v1/tags');
    const validTags = tags.map(t => t.name);

    const isValid = userTags.every(t => validTags.includes(t));
    ```
  </Accordion>
</AccordionGroup>

***

## Próximos Pasos

<CardGroup cols={2}>
  <Card title="Búsqueda por Tags" icon="magnifying-glass" href="/api-reference/contacts/search">
    Filtrar contactos por tags
  </Card>

  <Card title="Agregar Tags" icon="tag" href="/api-reference/contacts/update">
    Modificar tags de un contacto
  </Card>

  <Card title="Tags Masivos" icon="layer-group" href="/api-reference/contacts/bulk">
    Agregar/remover tags en lote
  </Card>

  <Card title="Campos Personalizados" icon="sliders" href="/api-reference/contacts/fields">
    Ver campos disponibles
  </Card>
</CardGroup>
