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

# Create Promotion Code

> Creates a new promotion code for a coupon.



## OpenAPI

````yaml /openapi.json post /promotion-codes
openapi: 3.1.0
info:
  title: OpenLoop API
  version: 0.1.0
  description: >-
    Unified reference for the OpenLoop Patient (clinical) and Payments & Revenue
    APIs.
servers:
  - url: https://api.openloophealth.com/v0.1
    description: Production partner edge
  - url: https://api-staging.openloophealth.com/v0.1
    description: Staging partner edge (sandbox credentials)
security: []
paths:
  /promotion-codes:
    post:
      tags:
        - Promotion Codes
      summary: Create Promotion Code
      description: Creates a new promotion code for a coupon.
      parameters:
        - in: header
          name: Idempotency-Key
          required: false
          schema:
            type: string
          description: >-
            Deduplicates retried requests with the same key and parameters
            instead of creating a second resource. Recommended: an opaque,
            randomly-generated value such as a UUID.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                provider_coupon_id:
                  type: string
                  description: >-
                    Provider coupon id (the payment provider coupon id) the
                    promotion code applies to.
                code:
                  type: string
                  description: Promotion code value (e.g., `"SUMMER20"`).
                active:
                  type: boolean
                  description: Whether the code is active; defaults to `true`.
                max_redemptions:
                  type: number
                  description: Max total redemptions. Positive integer.
                provider_customer_id:
                  type: string
                  description: Restrict the code to a single provider customer.
                expires_at:
                  type: number
                  description: >-
                    Expiry as a Unix timestamp in seconds; must be in the
                    future.
                metadata:
                  type: object
                  properties:
                    campaign:
                      type: string
                  description: String key/value pairs forwarded to the provider.
                restrictions:
                  type: object
                  properties:
                    first_time_transaction:
                      type: boolean
                      description: Restrict to a customer's first transaction.
                    minimum_amount:
                      type: number
                      description: >-
                        Minimum order amount (minor units). Positive integer;
                        required together with `minimum_amount_currency`.
                    minimum_amount_currency:
                      type: string
                      description: >-
                        Currency for `minimum_amount` (three-letter ISO code);
                        required together with `minimum_amount`.
                  description: >-
                    Optional usage restrictions. `minimum_amount` and
                    `minimum_amount_currency` must be provided together.
              required:
                - provider_coupon_id
                - code
            example:
              provider_coupon_id: 20OFF
              code: SUMMER20
              active: true
              max_redemptions: 100
              provider_customer_id: test_customer_id
              expires_at: 1000
              metadata:
                campaign: summer
              restrictions:
                first_time_transaction: true
                minimum_amount: 5000
                minimum_amount_currency: usd
      responses:
        '200':
          description: Success.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      code:
                        type: string
                        description: Promotion code value.
                      provider_coupon_id:
                        type: string
                        description: Provider coupon id the promotion code belongs to.
                      active:
                        type: boolean
                        description: Active status.
                      provider_promotion_code_id:
                        type: string
                        description: >-
                          Provider promotion code id (the payment provider
                          `promo_...`).
                      max_redemptions:
                        type:
                          - number
                          - 'null'
                        description: Max total redemptions (`null` if unset).
                      provider_customer_id:
                        type:
                          - string
                          - 'null'
                        description: Restricted-to customer id (`null` if unset).
                      expires_at:
                        type:
                          - number
                          - 'null'
                        description: Expiry Unix timestamp in seconds (`null` if unset).
                      metadata:
                        type: object
                        additionalProperties:
                          type: string
                        description: String key/value metadata map (`{}` if none).
                      restrictions:
                        type: object
                        properties:
                          first_time_transaction:
                            type:
                              - boolean
                              - 'null'
                          minimum_amount:
                            type:
                              - integer
                              - 'null'
                          minimum_amount_currency:
                            type:
                              - string
                              - 'null'
                        description: >-
                          `{ first_time_transaction, minimum_amount,
                          minimum_amount_currency }`; amount/currency `null` if
                          unset.
                required:
                  - data
              example:
                data:
                  code: SUMMER20
                  provider_coupon_id: 20OFF
                  active: true
                  provider_promotion_code_id: test_promotion_code_id_2
                  max_redemptions: 100
                  provider_customer_id: test_customer_id
                  expires_at: 1000
                  metadata:
                    campaign: summer
                  restrictions:
                    first_time_transaction: true
                    minimum_amount: 5000
                    minimum_amount_currency: usd
        '400':
          description: 'ValidationError: Missing `provider_coupon_id` or missing `code`.'
        '401':
          description: Missing or invalid bearer token.
        '403':
          description: >-
            No configuration exists for your account, or provider access has
            been disabled for it.
        '500':
          description: Payment provider integration error.
      security:
        - serviceToken: []
        - userToken: []
components:
  securitySchemes:
    serviceToken:
      type: oauth2
      description: >-
        Service (M2M) access token issued by POST /auth/token using the
        client_credentials grant. Required scopes, where known, are listed on
        each operation below.
      flows:
        clientCredentials:
          tokenUrl: https://api.openloophealth.com/v0.1/auth/token
          scopes: {}
    userToken:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        User access token issued by POST /auth/token via the verification-code
        grant (after Verify a one-time code) or the refresh_token grant.

````

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