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

# Buscar Productos por Categoría

> Cómo listar los productos públicos de una categoría específica usando el endpoint GET /stores/{storeId}/categories/{categoryId}/products.

## 📌 Endpoint

`GET /stores/{storeId}/categories/{categoryId}/products`

Devuelve los productos públicos (no deshabilitados) que pertenecen a una categoría de una tienda.

Los productos se devuelven en el orden de `position` (ascendente).

***

## 🔐 Autenticación

* **Ruta pública** para consulta.
* La tienda debe existir y tener plan activo.

***

## 🧾 Parámetros de ruta

| Parámetro | Tipo | Obligatorio | Descripción |
| - | - | - | - |
| `storeId` | string | Sí | ID de la tienda |
| `categoryId` | string | Sí | ID de la categoría |

***

## ✅ Ejemplo de solicitud

```bash theme={null}
curl -X GET "https://api.cabrapi.com.br/v1/stores/STORE_ID/categories/CATEGORY_ID/products?page=1&limit=20"
```

***

## 🔎 Parámetros de consulta

| Parámetro | Tipo | Obligatorio | Descripción |
| - | - | - | - |
| `page` | number | No | Página actual (predeterminado: `1`) |
| `limit` | number | No | Ítems por página (predeterminado: `20`, máximo: `100`) |
| `cursor` | string | No | Cursor opaco para paginación por cursor. Usa el `nextCursor` de la respuesta anterior. No puede usarse junto con `page` |

***

## 🔄 Paginación por cursor

Para listas grandes (más de \~100 ítems), prefiere la paginación por **cursor** en lugar de `page`:

1. Haz la primera llamada **sin** `cursor`.
2. Si `hasMore` es `true`, la respuesta trae el campo `nextCursor`.
3. Envía ese `nextCursor` en el parámetro `cursor` de la siguiente solicitud para buscar la página siguiente.

```bash theme={null}
curl -X GET "https://api.cabrapi.com.br/v1/stores/STORE_ID/categories/CATEGORY_ID/products?cursor=v1:TU_CURSOR_AQUI&limit=20"
```

En modo cursor, la paginación se devuelve solo con `nextCursor`, `hasMore` y `limit`:

```json theme={null}
{
  "code": "PRODUCTS_BY_CATEGORY_FETCHED",
  "products": [],
  "pagination": {
    "nextCursor": "v1:e2xFn...",
    "hasMore": true,
    "limit": 20
  }
}
```

* `cursor` y `page` **no pueden** usarse juntos (`400 INVALID_PAGINATION`).
* Cuando no hay productos en la categoría, el modo **offset** (sin `cursor`) devuelve `404 PRODUCTS_NOT_FOUND`, mientras que el modo **cursor** devuelve `200` con `products: []`, `nextCursor: null` y `hasMore: false`.
* `nextCursor: null` con `hasMore: false` indican el fin de la lista (la API responde `200` con array vacío).

***

## 📦 Respuesta exitosa (200)

```json theme={null}
{
  "code": "PRODUCTS_BY_CATEGORY_FETCHED",
  "products": [
    {
      "id": "d4f2b5ff-7ae5-4a00-8f18-5d7b6f20f2b8",
      "name": "Curso Premium",
      "disabled": false,
      "position": 1,
      "description": "Acesso completo ao conteúdo.",
      "price": 49.9,
      "image": null,
      "delivery": "DIGITAL",
      "stock": 100,
      "sold": 12,
      "storeId": "STORE_ID",
      "metadata": {},
      "createdAt": "2026-03-02T20:00:00.000Z",
      "updatedAt": "2026-03-02T20:00:00.000Z",
      "categories": [
        {
          "id": "CATEGORY_ID",
          "name": "Cursos"
        }
      ]
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 1,
    "totalPages": 1,
    "nextCursor": null,
    "hasMore": false
  }
}
```

> La primera llamada (sin `cursor`) ya devuelve `nextCursor` y `hasMore` en la paginación, permitiendo iniciar la paginación por cursor sin llamadas extra.

***

## ⚠️ Posibles errores

* `400 INVALID_DATA` → parámetro inválido
* `400 INVALID_PAGINATION_LIMIT` → `limit` fuera del intervalo permitido (`1` a `100`)
* `400 INVALID_PAGINATION_PAGE` → `page` inválida
* `400 INVALID_PAGINATION_CURSOR` → `cursor` inválido o malformado
* `400 INVALID_PAGINATION` → `page` y `cursor` utilizados juntos
* `401 UNAUTHENTICATED` → no fue posible identificar al usuario de la suscripción
* `403 NO_ACTIVE_SUBSCRIPTION` → plan inactivo o expirado
* `404 STORE_NOT_FOUND` → tienda no encontrada
* `404 PRODUCTS_NOT_FOUND` → ningún producto encontrado para la categoría (devuelto solo en modo offset cuando `total` es `0`; en modo cursor devuelve `200` con `[]`)
* `429 RATE_LIMIT_EXCEEDED` → límite de solicitudes por minuto excedido
* `500 INTERNAL_SERVER_ERROR` → error interno
* `503 SERVICE_UNAVAILABLE` → servicio o base de datos no disponible


## OpenAPI

````yaml GET /stores/{storeId}/categories/{categoryId}/products
openapi: 3.1.0
info:
  title: caBRAPI
  version: 1.0.0
servers:
  - url: https://api.cabrapi.com.br/v1
security: []
paths:
  /stores/{storeId}/categories/{categoryId}/products:
    get:
      tags:
        - Categories
      summary: List products by category
      operationId: listCategoryProducts
      parameters:
        - $ref: '#/components/parameters/StoreId'
        - $ref: '#/components/parameters/CategoryId'
        - in: query
          name: page
          schema:
            default: 1
            minimum: 1
            type: integer
        - in: query
          name: limit
          schema:
            default: 20
            maximum: 100
            minimum: 1
            type: integer
        - description: Opaque cursor from previous page (do not combine with page).
          in: query
          name: cursor
          schema:
            type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  code:
                    example: PRODUCTS_BY_CATEGORY_FETCHED
                    type: string
                  products:
                    type: array
                    items:
                      $ref: '#/components/schemas/Product'
                  pagination:
                    $ref: '#/components/schemas/Pagination'
                required:
                  - code
                  - products
                  - pagination
                type: object
          description: List products by category.
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Invalid request.
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Unauthorized (missing store owner or unavailable database).
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Forbidden (inactive plan or insufficient permissions).
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Resource not found.
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Rate limit exceeded.
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Internal server error.
        '503':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Service unavailable.
      security: []
components:
  parameters:
    StoreId:
      in: path
      name: storeId
      required: true
      schema:
        type: string
        minLength: 1
        maxLength: 50
    CategoryId:
      in: path
      name: categoryId
      required: true
      schema:
        type: string
        minLength: 1
        maxLength: 50
  schemas:
    Product:
      description: Store product.
      properties:
        categories:
          items:
            properties:
              id:
                format: uuid
                type: string
              name:
                type: string
            required:
              - id
              - name
            type: object
          type: array
        createdAt:
          format: date-time
          type: string
        delivery:
          enum:
            - DIGITAL
            - PHYSICAL
          type: string
        description:
          nullable: true
          type: string
        disabled:
          type: boolean
        id:
          format: uuid
          type: string
        image:
          nullable: true
          type: string
        metadata:
          nullable: true
          type: object
        name:
          type: string
        position:
          type: integer
        price:
          type: number
        sold:
          type: integer
        stock:
          type: integer
        storeId:
          format: uuid
          type: string
        updatedAt:
          format: date-time
          type: string
      required:
        - id
        - name
        - position
        - price
        - delivery
        - stock
        - sold
        - storeId
        - disabled
        - createdAt
        - updatedAt
        - categories
      type: object
    Pagination:
      properties:
        hasMore:
          type: boolean
        limit:
          type: integer
        nextCursor:
          nullable: true
          type: string
        page:
          type: integer
        total:
          type: integer
        totalPages:
          type: integer
      type: object
    Error:
      properties:
        code:
          example: STORE_NOT_FOUND
          type: string
      required:
        - code
      type: object

````

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