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

# Criar Cupom

> Aprenda a criar cupons usando o endpoint POST /stores/{storeId}/coupons.

## Endpoint

`POST /stores/{storeId}/coupons`

Cria um novo cupom para produtos e/ou categorias.

***

## Autenticação

* Rota privada.
* Requer header `Authorization` com sua API key e plano ativo.

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

***

## Parâmetros de rota

| Parâmetro | Tipo | Obrigatório | Descrição |
| - | - | - | - |
| `storeId` | string | Sim | ID da loja |

***

## Body (JSON)

| Campo | Tipo | Obrigatório | Regras |
| - | - | - | - |
| `code` | string | Sim | 3-32 caracteres |
| `discount` | number | Sim | 1 a 100 |
| `useLimit` | number | Não | inteiro -1 a 9999 (`-1` ilimitado) |
| `rules` | object\[] | Não | regras: `SINGLE_USE_PER_CUSTOMER`, `MIN_ORDER_AMOUNT` (`value` em centavos), `AFFILIATE_ONLY` (`value` código ou array), `MIN_ITEMS_QUANTITY` (`value` inteiro), `PAYMENT_METHOD` (`value` ex.: `PIX`) |
| `expiredAt` | date | Não | data futura ou `null` |
| `productIds` | string\[] | Condicional | obrigatório se `categoryIds` não for enviado |
| `categoryIds` | string\[] | Condicional | obrigatório se `productIds` não for enviado |

É necessário enviar ao menos um entre `productIds` e `categoryIds`.

***

## Exemplo de requisição

```bash theme={null}
curl -X POST "https://api.cabrapi.com.br/v1/stores/STORE_ID/coupons" \
	-H "Authorization: SUA_API_KEY_AQUI" \
	-H "Content-Type: application/json" \
	-d '{
		"code": "BEMVINDO10",
		"discount": 10,
		"useLimit": -1,
		"productIds": ["PRODUCT_ID"]
	}'
```

***

## Snippet padrão (cURL)

Use o exemplo cURL da seção Exemplo de requisição acima como snippet oficial.

***

## Resposta de sucesso (201)

```json theme={null}
{
	"code": "COUPON_CREATED",
	"coupon": {
		"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": []
	}
}
```

***

## Possíveis erros

* `400 INVALID_DATA` -> body inválido
* `400 INVALID_DATA_CODE` -> `code` ausente ou fora de 3 a 32 caracteres
* `400 INVALID_DATA_DISCOUNT` -> `discount` ausente ou fora de 1 a 100
* `400 INVALID_DATA_USE_LIMIT` -> `useLimit` fora de -1 a 9999
* `400 INVALID_DATA_RULES` -> `rules` inválido ou regra malformada
* `400 INVALID_DATA_EXPIRED_AT` -> `expiredAt` inválido ou não está no futuro
* `400 INVALID_DATA_SCOPE_REQUIRED` -> nenhum entre `productIds` e `categoryIds` foi enviado
* `400 RELATION_NOT_FOUND` -> produto/categoria inválido
* `401 API_KEY_NOT_PROVIDED` -> header `Authorization` não enviado
* `401 INVALID_API_KEY` -> API key inválida
* `401 UNAUTHENTICATED` -> usuário não autenticado
* `403 USER_DISABLED` -> usuário desativado
* `403 NO_ACTIVE_SUBSCRIPTION` -> sem plano ativo
* `403 COUPON_LIMIT_REACHED` -> limite de cupons do plano atingido
* `404 STORE_NOT_FOUND` -> loja não encontrada
* `409 COUPON_ALREADY_EXISTS` -> código já existente
* `429 RATE_LIMIT_EXCEEDED` -> limite de requisições por minuto excedido
* `500 INTERNAL_SERVER_ERROR` -> erro interno
* `503 SERVICE_UNAVAILABLE` -> serviço indisponível


## OpenAPI

````yaml POST /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:
    post:
      tags:
        - Coupons
      summary: Create coupon
      operationId: createCoupon
      parameters:
        - $ref: '#/components/parameters/StoreId'
      requestBody:
        required: true
        description: Coupon details (code, discount, expiration).
        content:
          application/json:
            schema:
              type: object
              required:
                - code
                - discount
              properties:
                code:
                  type: string
                  minLength: 3
                  maxLength: 32
                discount:
                  type: integer
                  minimum: 1
                  maximum: 100
                useLimit:
                  type: integer
                  minimum: -1
                  maximum: 9999
                  nullable: true
                rules:
                  type: array
                  nullable: true
                  maxItems: 32
                  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
                expiredAt:
                  format: date-time
                  nullable: true
                  type: string
                productIds:
                  type: array
                  items:
                    type: string
                    minLength: 1
                    maxLength: 50
                categoryIds:
                  type: array
                  items:
                    type: string
                    minLength: 1
                    maxLength: 50
      responses:
        '201':
          content:
            application/json:
              schema:
                properties:
                  code:
                    example: COUPON_CREATED
                    type: string
                  coupon:
                    $ref: '#/components/schemas/Coupon'
                required:
                  - code
                  - coupon
                type: object
          description: Create coupon.
        '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.
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Resource already exists.
        '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
    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.