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

# Create a coupon

> Creates a percentage-off coupon. The buyer enters its `code` at checkout to apply it to the invoice.




## OpenAPI

````yaml /api-reference/openapi.en.json post /billing/coupons
openapi: 3.1.0
info:
  title: Infi API
  version: 0.0.1
  description: >
    The Infi REST API: catalog, customers, usage metering, subscriptions,

    invoices, payments and checkout.


    **Authentication.** Send your secret key as `Authorization: Bearer
    sk_test_…`

    (sandbox) or `sk_live_…` (production). The key prefix selects the
    environment.

    Checkout routes (`/pay/*`) and `/public/*` take no key: they run in the

    payer's browser.


    **Idempotency.** Every request that changes data requires an

    `Idempotency-Key` header. A retry with the same key returns the original

    response instead of running again.


    **Amounts.** Money and quantities travel as decimal strings (`"150.00"`,

    `"0.0001"`), never as floating-point numbers.


    **Errors.** The body carries `error_code` (stable, branch on it), `message`

    (for humans) and `tracer_id` (send it to support). Rate-limit and
    idempotency

    errors are nested under `error`, with `code` and `request_id`.
servers:
  - url: https://api-sandbox.beinfi.com
    description: Sandbox
  - url: https://api.beinfi.com
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Catalog
  - name: Customers
  - name: Metering
  - name: Subscriptions
  - name: Invoices
  - name: Payments
  - name: Checkout
  - name: Coupons
  - name: Billing
  - name: Account
  - name: Webhooks
  - name: Test account
  - name: Rail
  - name: Storefronts
paths:
  /billing/coupons:
    post:
      tags:
        - Coupons
      summary: Create a coupon
      description: >
        Creates a percentage-off coupon. The buyer enters its `code` at checkout
        to apply it to the invoice.
      operationId: createCoupon
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateCouponRequest'
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Coupon'
          description: Created.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '422':
          $ref: '#/components/responses/ValidationFailed'
components:
  schemas:
    CreateCouponRequest:
      type: object
      required:
        - code
        - percentOff
        - duration
      properties:
        code:
          type: string
          description: >-
            Coupon code: 3 to 32 characters from uppercase letters, digits, `_`
            and `-` (e.g. `BLACKFRIDAY-20`).
        percentOff:
          type: string
          description: Discount percentage, as a decimal string, above 0 and up to 100.
        duration:
          type: string
          enum:
            - once
            - repeating
            - forever
          description: >-
            `once` (first invoice only), `repeating` (for `durationInCycles`
            cycles) or `forever` (every invoice).
        durationInCycles:
          type:
            - integer
            - 'null'
          description: >-
            Required (1 or more) when `duration` is `repeating`; omit it
            otherwise.
        maxRedemptions:
          type:
            - integer
            - 'null'
          description: Total redemption limit. Omit for no limit.
        redeemBy:
          type:
            - string
            - 'null'
          format: date-time
          description: Deadline for applying the coupon. Omit for no deadline.
      description: A new coupon's details.
    Coupon:
      type: object
      required:
        - id
        - code
        - percentOff
        - duration
        - timesRedeemed
        - status
        - createdAt
        - updatedAt
      properties:
        id:
          type: string
          format: uuid
        code:
          type: string
          description: The code the buyer enters at checkout.
        percentOff:
          type: string
          description: Discount percentage, as a decimal string (`"15"` = 15%).
        duration:
          type: string
          enum:
            - once
            - repeating
            - forever
          description: >-
            `once` (first invoice only), `repeating` (for `durationInCycles`
            cycles) or `forever` (every invoice).
        durationInCycles:
          type:
            - integer
            - 'null'
          description: How many cycles the discount lasts. Only on `repeating` coupons.
        maxRedemptions:
          type:
            - integer
            - 'null'
          description: How many times the coupon can be used in total. `null` = no limit.
        timesRedeemed:
          type: integer
          description: How many times the coupon has been used.
        redeemBy:
          type:
            - string
            - 'null'
          format: date-time
          description: Last moment the coupon can be applied. `null` = no deadline.
        status:
          type: string
          enum:
            - active
            - archived
          description: '`active` (accepted at checkout) or `archived` (no longer accepted).'
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
      description: >-
        A percentage discount the buyer applies at checkout with its `code`. On
        subscriptions, `duration` sets how many cycles the discount lasts.
    Error:
      type: object
      required:
        - message
        - error_code
        - tracer_id
      properties:
        message:
          type: string
          description: Human-readable sentence.
        error_code:
          $ref: '#/components/schemas/ErrorCode'
          description: Stable error code. Branch on it.
        tracer_id:
          type: string
          description: Request id. Include it when contacting support.
      description: >-
        The standard error body. It is flat (no `error` wrapper) and the trace
        id is `tracer_id`.
    ValidationError:
      type: object
      required:
        - message
        - error_code
        - tracer_id
        - errors
      properties:
        message:
          type: string
        error_code:
          $ref: '#/components/schemas/ErrorCode'
        tracer_id:
          type: string
        errors:
          type: array
          items:
            type: object
            required:
              - field
              - value
              - constraint
              - description
            properties:
              field:
                type: string
              value:
                type: string
              constraint:
                type: string
              description:
                type: string
          description: >-
            Per-field detail (`field`, `description`). Always present on a
            `422`; may be empty.
      description: >-
        Body of a `422`. Same shape as `Error`, plus `errors[]` with per-field
        detail. That is where the sentence telling you what to fix lives (for
        example, "product has no published version").
    ErrorCode:
      type: string
      examples:
        - internal_error
        - validation_failed
        - bad_request
        - unauthorized
        - forbidden
        - not_found
        - conflict
        - rate_limited
      description: >-
        Stable error code. The list is open: besides the generic codes, each
        area defines its own (`coupon_expired`, `insufficient_balance`,
        `version_not_draft`, `idempotency_key_reused`…). Handle a code you do
        not recognize by its HTTP status and show `message`; do not fail parsing
        the response.
  responses:
    Unauthorized:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
      description: Missing or invalid API key.
    ValidationFailed:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ValidationError'
      description: One or more fields are invalid. Per-field detail is in `errors[]`.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Your account's secret key: `Authorization: Bearer sk_test_…` or
        `sk_live_…`. Server-side only.

````