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

# Categorías y Catálogos

> Consulta catálogos y gestiona categorías antes de crear productos

# Categorías y Catálogos

Las categorías y catálogos son entidades prerequisito para crear productos. Esta guía cubre cómo consultarlos y gestionarlos.

## Catálogos

Los catálogos se crean automáticamente al registrar el merchant. La API solo permite consultarlos para obtener el `catalog_id`.

### Listar Catálogos

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://api.ya.onl/v1/catalogs" \
    -H "X-API-Key: yv_live_v1_tu_api_key"
  ```

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

  response = httpx.get(
      "https://api.ya.onl/v1/catalogs",
      headers={"X-API-Key": "yv_live_v1_tu_api_key"},
  )
  catalogs = response.json()
  catalog_id = catalogs["data"][0]["id"]
  print(f"Catalog ID: {catalog_id}")
  ```

  ```javascript Node.js theme={null}
  const response = await fetch("https://api.ya.onl/v1/catalogs", {
    headers: { "X-API-Key": "yv_live_v1_tu_api_key" },
  });
  const catalogs = await response.json();
  const catalogId = catalogs.data[0].id;
  console.log(`Catalog ID: ${catalogId}`);
  ```
</CodeGroup>

<Warning>
  Todo merchant tiene un catálogo creado automáticamente. Usa el `id` del primer resultado como `catalog_id` al crear productos y categorías.
</Warning>

## Categorías

Las categorías son etiquetas globales que puedes asignar a múltiples productos. Se gestionan de forma independiente.

### Crear Categoría

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://api.ya.onl/v1/categories" \
    -H "X-API-Key: yv_live_v1_tu_api_key" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Ropa",
      "catalog_id": 1
    }'
  ```

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

  response = httpx.post(
      "https://api.ya.onl/v1/categories",
      headers={"X-API-Key": "yv_live_v1_tu_api_key"},
      json={"name": "Ropa", "catalog_id": 1},
  )
  category = response.json()
  print(f"Category ID: {category['id']}")
  ```

  ```javascript Node.js theme={null}
  const response = await fetch("https://api.ya.onl/v1/categories", {
    method: "POST",
    headers: {
      "X-API-Key": "yv_live_v1_tu_api_key",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ name: "Ropa", catalog_id: 1 }),
  });
  const category = await response.json();
  console.log(`Category ID: ${category.id}`);
  ```
</CodeGroup>

### Listar Categorías

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://api.ya.onl/v1/categories?page=1&limit=20" \
    -H "X-API-Key: yv_live_v1_tu_api_key"
  ```

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

  response = httpx.get(
      "https://api.ya.onl/v1/categories",
      params={"page": 1, "limit": 20},
      headers={"X-API-Key": "yv_live_v1_tu_api_key"},
  )
  print(response.json())
  ```

  ```javascript Node.js theme={null}
  const response = await fetch(
    "https://api.ya.onl/v1/categories?page=1&limit=20",
    {
      headers: { "X-API-Key": "yv_live_v1_tu_api_key" },
    }
  );
  const data = await response.json();
  console.log(data);
  ```
</CodeGroup>

### Actualizar Categoría

<CodeGroup>
  ```bash cURL theme={null}
  curl -X PATCH "https://api.ya.onl/v1/categories/1" \
    -H "X-API-Key: yv_live_v1_tu_api_key" \
    -H "Content-Type: application/json" \
    -d '{"name": "Ropa y Accesorios"}'
  ```

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

  response = httpx.patch(
      "https://api.ya.onl/v1/categories/1",
      headers={"X-API-Key": "yv_live_v1_tu_api_key"},
      json={"name": "Ropa y Accesorios"},
  )
  print(response.json())
  ```

  ```javascript Node.js theme={null}
  const response = await fetch("https://api.ya.onl/v1/categories/1", {
    method: "PATCH",
    headers: {
      "X-API-Key": "yv_live_v1_tu_api_key",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ name: "Ropa y Accesorios" }),
  });
  const data = await response.json();
  console.log(data);
  ```
</CodeGroup>

### Eliminar Categoría

<CodeGroup>
  ```bash cURL theme={null}
  curl -X DELETE "https://api.ya.onl/v1/categories/1" \
    -H "X-API-Key: yv_live_v1_tu_api_key"
  ```

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

  response = httpx.delete(
      "https://api.ya.onl/v1/categories/1",
      headers={"X-API-Key": "yv_live_v1_tu_api_key"},
  )
  print(response.status_code)  # 204
  ```

  ```javascript Node.js theme={null}
  const response = await fetch("https://api.ya.onl/v1/categories/1", {
    method: "DELETE",
    headers: { "X-API-Key": "yv_live_v1_tu_api_key" },
  });
  console.log(response.status); // 204
  ```
</CodeGroup>

<Warning>
  Eliminar una categoría la desvincula automáticamente de todos los productos que la tenían asignada. Esta acción no se puede deshacer.
</Warning>

## Siguiente Paso

Una vez que tengas tu `catalog_id` y las categorías creadas, puedes empezar a [gestionar productos](/products/manage-products).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.