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

# Create Discount

> Create a discount for your account.



## OpenAPI

````yaml post /discounts
openapi: 3.1.0
info:
  title: public
  description: ''
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0
  version: 1.110.1
servers:
  - url: https://test.dodopayments.com/
    description: Test Mode Server Host
  - url: https://live.dodopayments.com/
    description: Live Mode Server Host
security: []
tags:
  - name: Products
  - name: Payments
  - name: Subscriptions
  - name: Addons
  - name: Customers
  - name: Refunds
  - name: Disputes
  - name: Events
  - name: License Keys
  - name: Entitlements
  - name: Licenses
  - name: Discounts
  - name: Meters
  - name: Credit Entitlements
  - name: Credit Entitlement Balances
  - name: Outgoing Webhooks
  - name: Checkout
  - name: Webhook Events
  - name: Payment Connector Webhooks
paths:
  /discounts:
    post:
      tags:
        - Discounts
      summary: >-
        POST /discounts

        If `code` is omitted or empty, a random 16-char uppercase code is
        generated.
      operationId: create_discount_handler
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateDiscountRequest'
        required: true
      responses:
        '200':
          description: Created discount
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DiscountResponse'
        '422':
          description: Invalid Request Object or Parameters
        '500':
          description: Something went wrong :(
      security:
        - API_KEY: []
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import DodoPayments from 'dodopayments';


            const client = new DodoPayments({
              bearerToken: process.env['DODO_PAYMENTS_API_KEY'], // This is the default and can be omitted
            });


            const discount = await client.discounts.create({ amount: 0, type:
            'flat' });


            console.log(discount.business_id);
        - lang: Python
          source: |-
            import os
            from dodopayments import DodoPayments

            client = DodoPayments(
                bearer_token=os.environ.get("DODO_PAYMENTS_API_KEY"),  # This is the default and can be omitted
            )
            discount = client.discounts.create(
                amount=0,
                type="flat",
            )
            print(discount.business_id)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/dodopayments/dodopayments-go\"\n\t\"github.com/dodopayments/dodopayments-go/option\"\n)\n\nfunc main() {\n\tclient := dodopayments.NewClient(\n\t\toption.WithBearerToken(\"My Bearer Token\"),\n\t)\n\tdiscount, err := client.Discounts.New(context.TODO(), dodopayments.DiscountNewParams{\n\t\tAmount: dodopayments.F(int64(0)),\n\t\tType:   dodopayments.F(dodopayments.DiscountTypeFlat),\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", discount.BusinessID)\n}\n"
        - lang: Java
          source: |-
            package com.dodopayments.api.example;

            import com.dodopayments.api.client.DodoPaymentsClient;
            import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient;
            import com.dodopayments.api.models.discounts.Discount;
            import com.dodopayments.api.models.discounts.DiscountCreateParams;
            import com.dodopayments.api.models.discounts.DiscountType;

            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    DodoPaymentsClient client = DodoPaymentsOkHttpClient.fromEnv();

                    DiscountCreateParams params = DiscountCreateParams.builder()
                        .amount(0)
                        .type(DiscountType.FLAT)
                        .build();
                    Discount discount = client.discounts().create(params);
                }
            }
        - lang: Kotlin
          source: |-
            package com.dodopayments.api.example

            import com.dodopayments.api.client.DodoPaymentsClient
            import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient
            import com.dodopayments.api.models.discounts.Discount
            import com.dodopayments.api.models.discounts.DiscountCreateParams
            import com.dodopayments.api.models.discounts.DiscountType

            fun main() {
                val client: DodoPaymentsClient = DodoPaymentsOkHttpClient.fromEnv()

                val params: DiscountCreateParams = DiscountCreateParams.builder()
                    .amount(0)
                    .type(DiscountType.FLAT)
                    .build()
                val discount: Discount = client.discounts().create(params)
            }
        - lang: Ruby
          source: |-
            require "dodopayments"

            dodo_payments = Dodopayments::Client.new(
              bearer_token: "My Bearer Token",
              environment: "test_mode" # defaults to "live_mode"
            )

            discount = dodo_payments.discounts.create(amount: 0, type: :flat)

            puts(discount)
        - lang: PHP
          source: |-
            <?php

            require_once dirname(__DIR__) . '/vendor/autoload.php';

            use Dodopayments\Client;
            use Dodopayments\Core\Exceptions\APIException;
            use Dodopayments\Discounts\DiscountType;
            use Dodopayments\Misc\Currency;

            $client = new Client(
              bearerToken: getenv('DODO_PAYMENTS_API_KEY') ?: 'My Bearer Token',
              environment: 'test_mode',
            );

            try {
              $discount = $client->discounts->create(
                amount: 0,
                type: DiscountType::FLAT,
                code: 'code',
                currencyOptions: [
                  [
                    'currency' => Currency::AED,
                    'isDefault' => true,
                    'maxAmountPossible' => 0,
                    'minimumSubtotal' => 0,
                  ],
                ],
                customerEligibility: 'any',
                expiresAt: new \DateTimeImmutable('2019-12-27T18:11:19.117Z'),
                metadata: ['foo' => 'string'],
                name: 'name',
                perCustomerUsageLimit: 0,
                preserveOnPlanChange: true,
                restrictedTo: ['string'],
                startsAt: new \DateTimeImmutable('2019-12-27T18:11:19.117Z'),
                subscriptionCycles: 0,
                usageLimit: 0,
              );

              var_dump($discount);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: C#
          source: |-
            using System;
            using DodoPayments.Client;
            using DodoPayments.Client.Models.Discounts;

            DodoPaymentsClient client = new();

            DiscountCreateParams parameters = new()
            {
                Amount = 0,
                Type = DiscountType.Flat,
            };

            var discount = await client.Discounts.Create(parameters);

            Console.WriteLine(discount);
        - lang: Rust
          source: |-
            use dodopayments::Client;

            #[tokio::main]
            async fn main() -> dodopayments::Result<()> {
                let client = Client::from_env()?;
                let result = client
                    .discounts()
                    .create()
                    .body(dodopayments::models::DiscountsCreateParams {
                            amount: Some(0),
                            r#type: Some(Box::new(dodopayments::models::DiscountType::Flat)),
                            ..Default::default()
                        })
                    .await?;
                println!("{result:?}");
                Ok(())
            }
components:
  schemas:
    CreateDiscountRequest:
      type: object
      description: |-
        Request body for creating a discount.

        `code` is optional; if not provided, we generate a random 16-char code.
      required:
        - type
        - amount
      properties:
        amount:
          type: integer
          format: int32
          description: >-
            The discount amount in **basis points** (e.g. `540` means `5.4%`,
            `10000` means `100%`).


            Must be at least 1.
        code:
          type:
            - string
            - 'null'
          description: |-
            Optionally supply a code (will be uppercased).
            - Must be at least 3 characters if provided.
            - If omitted, a random 16-character code is generated.
        currency_options:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/CurrencyOptionRequest'
          description: >-
            Per-currency options (flat deduction / percentage cap + minimum
            subtotal).

            Required for `flat` codes (must include a resolvable default);
            optional

            per-currency caps for `percentage` codes. Per-row invariants are
            checked

            in `normalize_currency_options`, not via `#[validate(nested)]`.
        customer_eligibility:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/CustomerEligibility'
              description: >-
                Who may redeem this discount code. Defaults to `any`
                (unrestricted).

                `specific` starts with zero attached customers (fails closed)
                until

                customers are attached via `POST /discounts/{id}/customers`.
        expires_at:
          type:
            - string
            - 'null'
          format: date-time
          description: When the discount expires, if ever.
        metadata:
          $ref: '#/components/schemas/Metadata'
          description: Additional metadata for the discount
        name:
          type:
            - string
            - 'null'
        per_customer_usage_limit:
          type:
            - integer
            - 'null'
          format: int32
          description: |-
            Maximum number of times a single customer may redeem this discount.
            Must be `<= usage_limit` when both are set.
        preserve_on_plan_change:
          type: boolean
          description: >-
            Whether this discount should be preserved when a subscription
            changes plans.

            Default: false (discount is removed on plan change)
        restricted_to:
          type:
            - array
            - 'null'
          items:
            type: string
          description: List of product IDs to restrict usage (if any).
        starts_at:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            When the discount becomes active, if scheduled for the future.

            NULL = active immediately. Must be strictly before `expires_at` when
            both are set.
        subscription_cycles:
          type:
            - integer
            - 'null'
          format: int32
          description: |-
            Number of subscription billing cycles this discount is valid for.
            If not provided, the discount will be applied indefinitely to
            all recurring payments related to the subscription.
        type:
          $ref: '#/components/schemas/DiscountType'
          description: >-
            The discount type: `percentage` or `flat` (`flat_per_unit` stays
            blocked).
        usage_limit:
          type:
            - integer
            - 'null'
          format: int32
          description: |-
            How many times this discount can be used (if any).
            Must be >= 1 if provided.
    DiscountResponse:
      type: object
      required:
        - discount_id
        - business_id
        - type
        - code
        - amount
        - times_used
        - restricted_to
        - created_at
        - preserve_on_plan_change
        - customer_eligibility
        - metadata
      properties:
        amount:
          type: integer
          format: int32
          description: The discount amount in **basis points** (e.g., 540 => 5.4%).
        business_id:
          type: string
          description: The business this discount belongs to.
        code:
          type: string
          description: The discount code (up to 16 chars).
        created_at:
          type: string
          format: date-time
          description: Timestamp when the discount is created
        currency_options:
          type: array
          items:
            $ref: '#/components/schemas/CurrencyOptionResponse'
          description: >-
            Per-currency options (flat deduction / percentage cap + minimum
            subtotal).

            Empty for discounts without any configured currency options.
        customer_eligibility:
          $ref: '#/components/schemas/CustomerEligibility'
          description: Who may redeem this discount code.
        discount_id:
          type: string
          description: The unique discount ID
        expires_at:
          type:
            - string
            - 'null'
          format: date-time
          description: Optional date/time after which discount is expired.
        metadata:
          $ref: '#/components/schemas/Metadata'
        name:
          type:
            - string
            - 'null'
          description: Name for the Discount
        per_customer_usage_limit:
          type:
            - integer
            - 'null'
          format: int32
          description: >-
            Maximum number of times a single customer may redeem this discount,
            if any.
        preserve_on_plan_change:
          type: boolean
          description: >-
            Whether this discount should be preserved when a subscription
            changes plans.

            Default: false (discount is removed on plan change)
        restricted_to:
          type: array
          items:
            type: string
          description: List of product IDs to which this discount is restricted.
        starts_at:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            Optional date/time before which the discount is not yet active. NULL
            = active immediately.
        subscription_cycles:
          type:
            - integer
            - 'null'
          format: int32
          description: |-
            Number of subscription billing cycles this discount is valid for.
            If not provided, the discount will be applied indefinitely to
            all recurring payments related to the subscription.
        times_used:
          type: integer
          format: int32
          description: How many times this discount has been used.
        type:
          $ref: '#/components/schemas/DiscountType'
          description: The type of discount (`percentage` or `flat`).
        usage_limit:
          type:
            - integer
            - 'null'
          format: int32
          description: Usage limit for this discount, if any.
    CurrencyOptionRequest:
      type: object
      description: >-
        A per-currency discount option (request shape).


        `max_amount_possible` is the most this code discounts in this currency —
        the

        flat deduction for `flat` codes, or the max-discount cap for
        `percentage`

        codes. Maps to the DB column of the same name.
      required:
        - currency
      properties:
        currency:
          $ref: '#/components/schemas/Currency'
          description: The currency this option applies to.
        is_default:
          type: boolean
          description: |-
            Whether this row is the default to convert from for unconfigured
            currencies. At most one row per discount may be default.
        max_amount_possible:
          type:
            - integer
            - 'null'
          format: int32
          description: >-
            The most this code discounts in this currency's subunits. For `flat`
            codes

            this is the deduction; for `percentage` codes it is the max-discount
            cap.

            Must be > 0 if provided.
        minimum_subtotal:
          type: integer
          format: int32
          description: >-
            Eligible-cart threshold in this currency's subunits (0 = no
            minimum).
    CustomerEligibility:
      type: string
      description: >-
        Who may redeem a discount code. Mirrors the Postgres enum

        `discount_customer_eligibility` (migration
        `20260714063329_discount_expansion`).
      enum:
        - any
        - first_time
        - existing
        - specific
    Metadata:
      type: object
      title: Metadata
      description: >-
        Arbitrary key-value metadata. Values can be string, integer, number, or
        boolean.
      additionalProperties:
        oneOf:
          - type: string
            title: String
          - type: integer
            title: Integer
            format: int64
          - type: number
            title: Number
            format: double
          - type: boolean
            title: Boolean
        title: Metadata Value
        description: Metadata value can be a string, integer, number, or boolean
    DiscountType:
      type: string
      enum:
        - flat
        - percentage
    CurrencyOptionResponse:
      type: object
      description: |-
        A per-currency discount option (response shape). `max_amount_possible`
        mirrors the DB column of the same name.
      required:
        - currency
        - minimum_subtotal
        - is_default
      properties:
        currency:
          $ref: '#/components/schemas/Currency'
          description: The currency this option applies to.
        is_default:
          type: boolean
          description: Whether this is the default row FX conversions pivot from.
        max_amount_possible:
          type:
            - integer
            - 'null'
          format: int32
          description: >-
            The most this code discounts in this currency's subunits (flat
            deduction

            or percentage cap).
        minimum_subtotal:
          type: integer
          format: int32
          description: >-
            Eligible-cart threshold in this currency's subunits (0 = no
            minimum).
    Currency:
      type: string
      enum:
        - AED
        - ALL
        - AMD
        - ANG
        - AOA
        - ARS
        - AUD
        - AWG
        - AZN
        - BAM
        - BBD
        - BDT
        - BGN
        - BHD
        - BIF
        - BMD
        - BND
        - BOB
        - BRL
        - BSD
        - BWP
        - BYN
        - BZD
        - CAD
        - CHF
        - CLP
        - CNY
        - COP
        - CRC
        - CUP
        - CVE
        - CZK
        - DJF
        - DKK
        - DOP
        - DZD
        - EGP
        - ETB
        - EUR
        - FJD
        - FKP
        - GBP
        - GEL
        - GHS
        - GIP
        - GMD
        - GNF
        - GTQ
        - GYD
        - HKD
        - HNL
        - HRK
        - HTG
        - HUF
        - IDR
        - ILS
        - INR
        - IQD
        - JMD
        - JOD
        - JPY
        - KES
        - KGS
        - KHR
        - KMF
        - KRW
        - KWD
        - KYD
        - KZT
        - LAK
        - LBP
        - LKR
        - LRD
        - LSL
        - LYD
        - MAD
        - MDL
        - MGA
        - MKD
        - MMK
        - MNT
        - MOP
        - MRU
        - MUR
        - MVR
        - MWK
        - MXN
        - MYR
        - MZN
        - NAD
        - NGN
        - NIO
        - NOK
        - NPR
        - NZD
        - OMR
        - PAB
        - PEN
        - PGK
        - PHP
        - PKR
        - PLN
        - PYG
        - QAR
        - RON
        - RSD
        - RUB
        - RWF
        - SAR
        - SBD
        - SCR
        - SEK
        - SGD
        - SHP
        - SLE
        - SLL
        - SOS
        - SRD
        - SSP
        - STN
        - SVC
        - SZL
        - THB
        - TND
        - TOP
        - TRY
        - TTD
        - TWD
        - TZS
        - UAH
        - UGX
        - USD
        - UYU
        - UZS
        - VES
        - VND
        - VUV
        - WST
        - XAF
        - XCD
        - XOF
        - XPF
        - YER
        - ZAR
        - ZMW
  securitySchemes:
    API_KEY:
      type: http
      scheme: bearer

````