> ## Documentation Index
> Fetch the complete documentation index at: https://dodopayments-mintlify-external-integration-datafast-autosen.mintlify.site/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.61.5
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: Licenses
  - name: Discounts
  - name: Meters
  - 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: 'My Bearer Token',
            });


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


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

            client = DodoPayments(
                bearer_token="My Bearer Token",
            )
            discount = client.discounts.create(
                amount=0,
                type="percentage",
            )
            print(discount.business_id)
        - lang: Go
          source: |
            package main

            import (
              "context"
              "fmt"

              "github.com/dodopayments/dodopayments-go"
              "github.com/dodopayments/dodopayments-go/option"
            )

            func main() {
              client := dodopayments.NewClient(
                option.WithBearerToken("My Bearer Token"),
              )
              discount, err := client.Discounts.New(context.TODO(), dodopayments.DiscountNewParams{
                Amount: dodopayments.F(int64(0)),
                Type: dodopayments.F(dodopayments.DiscountTypePercentage),
              })
              if err != nil {
                panic(err.Error())
              }
              fmt.Printf("%+v\n", discount.BusinessID)
            }
        - 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)
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.


            - If `discount_type` is **not** `percentage`, `amount` is in **USD
            cents**. For example, `100` means `$1.00`.
              Only USD is allowed.
            - If `discount_type` **is** `percentage`, `amount` is in **basis
            points**. For example, `540` means `5.4%`.


            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.
        name:
          type:
            - string
            - 'null'
        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 (e.g. `percentage`, `flat`, or `flat_per_unit`).
        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
      properties:
        amount:
          type: integer
          format: int32
          description: |-
            The discount amount.

            - If `discount_type` is `percentage`, this is in **basis points**
              (e.g., 540 => 5.4%).
            - Otherwise, this is **USD cents** (e.g., 100 => `$1.00`).
        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.
        name:
          type:
            - string
            - 'null'
          description: Name for the Discount
        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, e.g. `percentage`, `flat`, or `flat_per_unit`.
        usage_limit:
          type:
            - integer
            - 'null'
          format: int32
          description: Usage limit for this discount, if any.
    DiscountType:
      type: string
      enum:
        - percentage
  securitySchemes:
    API_KEY:
      type: http
      scheme: bearer

````