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

# Create Coupon

> Creates a coupon. Exactly one of `amount_off` or `percent_off` must be provided; supplying
both, or neither, is rejected. When `duration` is `repeating`, `duration_in_months` is
required.



## OpenAPI

````yaml /openapi.json post /v1/coupons
openapi: 3.1.0
info:
  title: Flex API
  description: >-
    The Flex API powers HSA/FSA payment processing for healthcare commerce:
    checkout sessions, payment intents, subscriptions, customers, refunds,
    disputes, and eligibility. Authenticate with your partner API key as a
    Bearer token. All endpoints are scoped to your partner account, and test
    mode is fully supported via test API keys.
  version: 0.1.0
servers:
  - url: https://api.withflex.com
security:
  - BearerAuth: []
tags:
  - name: Balance Transactions
  - name: Captures
  - name: Checkout Sessions
  - name: Coupons
  - name: Customers
  - name: Disputes
  - name: Events
  - name: Exports
  - name: Files
  - name: Invoices
  - name: Letters
  - name: Orders
  - name: Payment Intents
  - name: Payment Links
  - name: Payouts
  - name: Prices
  - name: Products
  - name: Promo Codes
  - name: Receipts
  - name: Refunds
  - name: Setup Intents
  - name: Shipping Rates
  - name: Subscriptions
paths:
  /v1/coupons:
    post:
      tags:
        - Coupons
      summary: Create Coupon
      description: >-
        Creates a coupon. Exactly one of `amount_off` or `percent_off` must be
        provided; supplying

        both, or neither, is rejected. When `duration` is `repeating`,
        `duration_in_months` is

        required.
      operationId: v1.coupons.create
      requestBody:
        description: An envelope wrapping a single coupon object.
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CouponBody_for_CreateCouponRequest'
            example:
              coupon:
                name: Coupon
                amount_off: 100
                duration: once
                percent_off: 10
                max_redemptions: 100
                metadata:
                  key: value
        required: true
      responses:
        '200':
          description: An envelope wrapping a single coupon object.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CouponBody_for_V1Coupon'
              example:
                coupon:
                  coupon_id: fcoup_1234567890
                  amount_off: 2500
                  duration: once
                  metadata:
                    order_id: '8842'
                    channel: shopify
                  name: Example
                  valid: false
                  created_at: '2026-06-15T14:30:00Z'
                  test_mode: false
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HttpErrorOut'
              example:
                code: string
                detail: string
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HttpErrorOut'
              example:
                code: string
                detail: string
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HttpErrorOut'
              example:
                code: string
                detail: string
        '409':
          description: Conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HttpErrorOut'
              example:
                code: string
                detail: string
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
              example:
                detail:
                  - loc:
                      - string
                    msg: string
                    type: string
        '429':
          description: Too Many Requests
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HttpErrorOut'
              example:
                code: string
                detail: string
      security:
        - BearerAuth:
            - coupons:write
components:
  schemas:
    CouponBody_for_CreateCouponRequest:
      description: An envelope wrapping a single coupon object.
      type: object
      required:
        - coupon
      properties:
        coupon:
          $ref: '#/components/schemas/CreateCouponRequest'
          description: The coupon.
      example:
        coupon:
          name: Coupon
          amount_off: 100
          duration: once
          percent_off: 10
          max_redemptions: 100
          metadata:
            key: value
    CouponBody_for_V1Coupon:
      description: An envelope wrapping a single coupon object.
      type: object
      required:
        - coupon
      properties:
        coupon:
          $ref: '#/components/schemas/V1Coupon'
          description: The coupon.
      example:
        coupon:
          coupon_id: fcoup_1234567890
          amount_off: 2500
          duration: once
          metadata:
            order_id: '8842'
            channel: shopify
          name: Example
          valid: false
          created_at: '2026-06-15T14:30:00Z'
          test_mode: false
    HttpErrorOut:
      title: HttpError
      description: The error response returned when a request cannot be completed.
      type: object
      required:
        - code
        - detail
      properties:
        code:
          description: A short machine-readable error code identifying the type of error.
          type: string
        detail:
          description: A human-readable explanation of what went wrong.
          type: string
      example:
        code: string
        detail: string
    HTTPValidationError:
      description: The error response returned when request validation fails (HTTP 422).
      type: object
      required:
        - detail
      properties:
        detail:
          description: The list of validation errors, one entry per invalid field.
          type: array
          items:
            $ref: '#/components/schemas/ValidationErrorItem'
      example:
        detail:
          - loc:
              - string
            msg: string
            type: string
    CreateCouponRequest:
      description: >-
        Parameters for creating a coupon. Exactly one of `amount_off` or
        `percent_off` must be set.
      type: object
      required:
        - name
      properties:
        applies_to:
          description: >-
            An object containing directions for what this Coupon will apply
            discounts to. If null, the coupon applies to the entire order.
          anyOf:
            - $ref: '#/components/schemas/AppliesTo'
            - type: 'null'
        name:
          description: Name of the coupon displayed to customers.
          type: string
          example: Coupon
        amount_off:
          description: >-
            A positive integer representing the amount to subtract from an
            invoice total (required if percent_off is not passed).
          type:
            - integer
            - 'null'
          format: int32
          example: 100
        duration:
          description: >-
            Specifies how long the discount will be in effect if used on a
            subscription. Defaults to once.
          anyOf:
            - $ref: '#/components/schemas/CouponDuration'
            - type: 'null'
          example: once
        duration_in_months:
          description: >-
            Required only if duration is repeating, in which case it must be a
            positive integer that specifies the number of months the discount
            will be in effect.
          type:
            - integer
            - 'null'
          format: int32
          example: null
        percent_off:
          description: >-
            A positive float larger than 0, and smaller or equal to 100, that
            represents the discount the coupon will apply (required if
            amount_off is not passed).
          type:
            - number
            - 'null'
          format: double
          example: 10
        max_redemptions:
          description: >-
            A positive integer specifying the number of times the coupon can be
            redeemed before it’s no longer valid.
          type:
            - integer
            - 'null'
          format: int32
          example: 100
        metadata:
          description: Metadata to attach to this coupon.
          type:
            - object
            - 'null'
          example:
            key: value
      example:
        applies_to:
          products: []
        name: Coupon
        amount_off: 100
        duration: once
        percent_off: 10
        max_redemptions: 100
        metadata:
          key: value
    V1Coupon:
      description: >-
        A coupon contains information about a percent-off or amount-off discount
        you might want to apply to a customer. Coupons may be applied to
        subscriptions and checkout sessions.
      type: object
      required:
        - coupon_id
        - created_at
        - duration
        - name
        - test_mode
        - valid
      properties:
        coupon_id:
          description: Unique identifier for the object.
          type: string
          example: fcoup_1234567890
        amount_off:
          description: >-
            Amount that will be taken off the subtotal of any invoices for this
            customer.
          type:
            - integer
            - 'null'
          format: int32
          example: 2500
        applies_to:
          description: >-
            An object containing the ID of the product that the coupon can be
            applied to.
          anyOf:
            - $ref: '#/components/schemas/AppliesTo'
            - type: 'null'
        duration:
          $ref: '#/components/schemas/CouponDuration'
          description: >-
            One of forever, once, and repeating. Describes how long a customer
            who applies this coupon will get the discount.
        duration_in_months:
          description: >-
            If duration is repeating, the number of months the coupon applies.
            Null if coupon duration is forever or once.
          type:
            - integer
            - 'null'
          format: int32
        metadata:
          description: >-
            Set of key-value pairs that you can attach to an object. This can be
            useful for storing additional information about the object in a
            structured format.
          type:
            - object
            - 'null'
          example:
            order_id: '8842'
            channel: shopify
        name:
          description: Name of the coupon displayed to customers.
          type: string
          example: Example
        percent_off:
          description: >-
            Percent that will be taken off the subtotal of any invoices for this
            customer for the duration of the coupon.
          type:
            - number
            - 'null'
          format: double
        max_redemptions:
          description: >-
            Maximum number of times this coupon can be redeemed, in total,
            across all customers, before it is no longer valid.
          type:
            - integer
            - 'null'
          format: int32
        times_redeemed:
          description: Number of times this coupon has been applied to a customer.
          type:
            - integer
            - 'null'
          format: int32
        valid:
          description: >-
            Taking account of the above properties, whether this coupon can
            still be applied to a customer.
          type: boolean
          example: false
        created_at:
          $ref: '#/components/schemas/Timestamptz'
          description: Date when this coupon was created.
          example: '2026-06-15T14:30:00Z'
        test_mode:
          description: Whether the coupon is in test mode
          type: boolean
          example: false
      example:
        coupon_id: fcoup_1234567890
        amount_off: 2500
        applies_to:
          products: []
        duration: once
        metadata:
          order_id: '8842'
          channel: shopify
        name: Example
        valid: false
        created_at: '2026-06-15T14:30:00Z'
        test_mode: false
    ValidationErrorItem:
      description: >-
        Validation errors have their own schema to provide context for invalid
        requests eg. mismatched types and out of bounds values. There may be any
        number of these per 422 UNPROCESSABLE ENTITY error.
      type: object
      required:
        - loc
        - msg
        - type
      properties:
        loc:
          description: >-
            The location as a [`Vec`] of [`String`]s -- often in the form
            `["body", "field_name"]`, `["query", "field_name"]`, etc. They may,
            however, be arbitarily deep.
          type: array
          items:
            type: string
        msg:
          description: The message accompanying the validation error item.
          type: string
        type:
          description: >-
            The type of error, often "type_error" or "value_error", but
            sometimes with more context like as "value_error.number.not_ge"
          type: string
      example:
        loc:
          - string
        msg: string
        type: string
    AppliesTo:
      description: What a coupon's discount is restricted to.
      anyOf:
        - type: object
          required:
            - products
          properties:
            products:
              description: The product that this coupon applies to.
              type: array
              items:
                type: string
                example: fprod_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        - type: object
          required:
            - prices
          properties:
            prices:
              description: The price that this coupon applies to.
              type: array
              items:
                type: string
                example: fprice_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        - type: object
          required:
            - fee_types
          properties:
            fee_types:
              description: The fee types that this coupon applies to.
              type: array
              items:
                $ref: '#/components/schemas/FeeType'
        - $ref: '#/components/schemas/AppliesToShipping'
      example:
        products:
          - fprod_01J9XR8M3K7VZ8N2YB4WJ6T0RA
    CouponDuration:
      type: string
      enum:
        - once
        - repeating
        - forever
      x-ms-enum:
        name: CouponDuration
        modelAsString: false
        values:
          - value: once
            name: Once
            description: >-
              Applies to the first charge from a subscription with this coupon
              applied.
          - value: repeating
            name: Repeating
            description: >-
              Applies to charges in the first duration_in_months months from a
              subscription with this coupon applied.
          - value: forever
            name: Forever
            description: >-
              Applies to all charges from a subscription with this coupon
              applied.
      description: >-
        - `once`: Applies to the first charge from a subscription with this
        coupon applied.

        - `repeating`: Applies to charges in the first duration_in_months months
        from a subscription with this coupon applied.

        - `forever`: Applies to all charges from a subscription with this coupon
        applied.
      example: once
    Timestamptz:
      description: >-
        A timestamp encoded as an RFC 3339 / ISO 8601 string (e.g.
        `2026-06-15T14:30:00Z`).
      type: string
      example: string
    FeeType:
      description: >-
        The kind of fee applied to a checkout session: a Letter of Medical
        Necessity consultation fee, or a custom fee you define.
      type: string
      enum:
        - lmn_consultation
        - custom
      example: lmn_consultation
    AppliesToShipping:
      description: The coupon applies to shipping.
      type: string
      enum:
        - shipping
      example: shipping
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: Use a Bearer token to access this API.

````