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

# Categorias e Catálogos

> Consulte catálogos e gerencie categorias antes de criar produtos

# Categorias e Catálogos

As categorias e catálogos são entidades pré-requisito para criar produtos. Este guia cobre como consultá-los e gerenciá-los.

## Catálogos

Os catálogos são criados automaticamente ao registrar o merchant. A API apenas permite consultá-los para obter o `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_sua_api_key"
  ```

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

  response = httpx.get(
      "https://api.ya.onl/v1/catalogs",
      headers={"X-API-Key": "yv_live_v1_sua_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_sua_api_key" },
  });
  const catalogs = await response.json();
  const catalogId = catalogs.data[0].id;
  console.log(`Catalog ID: ${catalogId}`);
  ```
</CodeGroup>

<Warning>
  Todo merchant tem um catálogo criado automaticamente. Use o `id` do primeiro resultado como `catalog_id` ao criar produtos e categorias.
</Warning>

## Categorias

As categorias são etiquetas globais que você pode atribuir a múltiplos produtos. São gerenciadas de forma independente.

### Criar Categoria

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://api.ya.onl/v1/categories" \
    -H "X-API-Key: yv_live_v1_sua_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_sua_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_sua_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 Categorias

<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_sua_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_sua_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_sua_api_key" },
    }
  );
  const data = await response.json();
  console.log(data);
  ```
</CodeGroup>

### Atualizar Categoria

<CodeGroup>
  ```bash cURL theme={null}
  curl -X PATCH "https://api.ya.onl/v1/categories/1" \
    -H "X-API-Key: yv_live_v1_sua_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_sua_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_sua_api_key",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ name: "Ropa y Accesorios" }),
  });
  const data = await response.json();
  console.log(data);
  ```
</CodeGroup>

### Excluir Categoria

<CodeGroup>
  ```bash cURL theme={null}
  curl -X DELETE "https://api.ya.onl/v1/categories/1" \
    -H "X-API-Key: yv_live_v1_sua_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_sua_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_sua_api_key" },
  });
  console.log(response.status); // 204
  ```
</CodeGroup>

<Warning>
  Excluir uma categoria a desvincula automaticamente de todos os produtos que a tinham atribuída. Essa ação não pode ser desfeita.
</Warning>

## Próximo Passo

Assim que tiver seu `catalog_id` e as categorias criadas, você pode começar a [gerenciar produtos](/pt/products/manage-products).


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