> ## 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.105.0
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
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:
            'percentage' });


            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="percentage",
            )
            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.DiscountTypePercentage),\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.PERCENTAGE)
                        .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.PERCENTAGE)
                    .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:
            :percentage)


            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;

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

            try {
              $discount = $client->discounts->create(
                amount: 0,
                type: DiscountType::PERCENTAGE,
                code: 'code',
                expiresAt: new \DateTimeImmutable('2019-12-27T18:11:19.117Z'),
                metadata: ['foo' => 'string'],
                name: 'name',
                preserveOnPlanChange: true,
                restrictedTo: ['string'],
                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.Percentage,
            };

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

            Console.WriteLine(discount);
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.
        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'
        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).
        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. Currently only `percentage` is supported.
        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
        - 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
        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
        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.
        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. Currently only `percentage` is supported.
        usage_limit:
          type:
            - integer
            - 'null'
          format: int32
          description: Usage limit for this discount, if any.
    Metadata:
      type: object
      additionalProperties:
        type: string
      propertyNames:
        type: string
    DiscountType:
      type: string
      enum:
        - percentage
      x-stainless-const: true
  securitySchemes:
    API_KEY:
      type: http
      scheme: bearer

````