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

> Aprenda a listar cupones de una tienda usando el endpoint GET /stores/{storeId}/coupons.

## 📌 Endpoint

`GET /stores/{storeId}/coupons`

Lista los cupones de la tienda (no expirados).

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

***

## 🔐 Autenticación

* **Ruta privada**.
* Requiere header `Authorization` con su API key y plan activo.

```json theme={null}
{
	"Authorization": "TU_API_KEY_AQUI"
}
```

***

## 🧾 Parámetros de ruta

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

***

## ✅ Ejemplo de solicitud

```bash theme={null}
curl -X GET "https://api.cabrapi.com.br/v1/stores/STORE_ID/coupons?page=1&limit=20" \
	-H "Authorization: TU_API_KEY_AQUI"
```

***

## 🔎 Parámetros de consulta

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

***

## 🔄 Paginación por cursor

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

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

```bash theme={null}
curl -X GET "https://api.cabrapi.com.br/v1/stores/STORE_ID/coupons?cursor=v1:TU_CURSOR_AQUI&limit=20" \
	-H "Authorization: TU_API_KEY_AQUI"
```

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

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

* `cursor` y `page` **no pueden** usarse juntos (`400 INVALID_PAGINATION`).
* `nextCursor: null` con `hasMore: false` indican el fin de la lista (solo en modo cursor la API responde `200` con array vacío `[]`; en modo offset con `page`, cuando el total es `0`, la API devuelve `404 COUPONS_NOT_FOUND`).

***

## Snippet estándar (cURL)

Use el ejemplo cURL de la sección Ejemplo de solicitud anterior como snippet oficial.

***

## 📦 Respuesta exitosa (200)

```json theme={null}
{
	"code": "COUPONS_FETCHED",
	"coupons": [
		{
			"id": "COUPON_ID",
			"code": "bemvindo10",
			"discount": 10,
			"position": 1,
			"useLimit": -1,
			"rules": [],
			"expiredAt": null,
			"storeId": "STORE_ID",
			"createdAt": "2026-09-08T19:30:00Z",
			"updatedAt": "2026-09-08T19:30:00Z",
			"products": [
				{ "id": "PRODUCT_ID", "name": "Curso Premium" }
			],
			"categories": []
		}
	],
	"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 adicionales.

***

## ⚠️ Posibles errores

* `400 INVALID_DATA` → parámetros inválidos
* `400 INVALID_PAGINATION_LIMIT` → `limit` fuera del rango 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` usados juntos
* `401 API_KEY_NOT_PROVIDED` → header `Authorization` no enviado
* `401 INVALID_API_KEY` → API key inválida
* `401 UNAUTHENTICATED` → usuario no autenticado
* `403 USER_DISABLED` → usuario deshabilitado
* `403 NO_ACTIVE_SUBSCRIPTION` → sin plan activo
* `404 STORE_NOT_FOUND` → tienda no encontrada
* `404 COUPONS_NOT_FOUND` → ningún cupón encontrado (devuelto en modo offset cuando el total es `0`; solo el 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 no disponible


## OpenAPI

````yaml GET /stores/{storeId}/coupons
openapi: 3.1.0
info:
  title: caBRAPI
  version: 1.0.0
servers:
  - url: https://api.cabrapi.com.br/v1
security: []
paths:
  /stores/{storeId}/coupons:
    get:
      tags:
        - Coupons
      summary: List coupons
      operationId: listCoupons
      parameters:
        - $ref: '#/components/parameters/StoreId'
        - 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: COUPONS_FETCHED
                    type: string
                  coupons:
                    type: array
                    items:
                      $ref: '#/components/schemas/Coupon'
                  pagination:
                    $ref: '#/components/schemas/Pagination'
                required:
                  - code
                  - coupons
                  - pagination
                type: object
          description: List coupons.
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Invalid request.
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Missing or invalid API key.
        '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:
        - ApiKey: []
components:
  parameters:
    StoreId:
      in: path
      name: storeId
      required: true
      schema:
        type: string
        minLength: 1
        maxLength: 50
  schemas:
    Coupon:
      description: Store discount coupon.
      properties:
        categories:
          items:
            properties:
              id:
                format: uuid
                type: string
              name:
                type: string
            required:
              - id
              - name
            type: object
          type: array
        code:
          type: string
        createdAt:
          format: date-time
          type: string
        discount:
          type: integer
        expiredAt:
          format: date-time
          nullable: true
          type: string
        id:
          format: uuid
          type: string
        position:
          type: integer
        products:
          items:
            properties:
              id:
                format: uuid
                type: string
              name:
                type: string
            required:
              - id
              - name
            type: object
          type: array
        rules:
          items:
            properties:
              type:
                enum:
                  - SINGLE_USE_PER_CUSTOMER
                  - MIN_ORDER_AMOUNT
                  - AFFILIATE_ONLY
                  - MIN_ITEMS_QUANTITY
                  - PAYMENT_METHOD
                type: string
              value: {}
            required:
              - type
            type: object
          nullable: false
          type: array
        storeId:
          format: uuid
          type: string
        updatedAt:
          format: date-time
          type: string
        useLimit:
          type: integer
      required:
        - id
        - code
        - discount
        - position
        - useLimit
        - storeId
        - createdAt
        - updatedAt
        - products
        - categories
        - rules
        - expiredAt
      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
  securitySchemes:
    ApiKey:
      in: header
      name: Authorization
      type: apiKey
      x-default: YOUR_API_KEY_HERE

````

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