Create a Discount

POST

/v1/discounts

Create a discount.


Attributes

name

The name of the discount.

code

The discount code that can be used at checkout. Uppercase letters and numbers are allowed. Must be between 3 and 256 characters.

amount

The amount of discount to apply to the order. Either a fixed amount in cents or a percentage depending on the value of amount_type.

  • 1000 means $10 when amount_type is fixed.
  • 10 means 10% when amount_type is percent.

amount_type

The type of the amount. Either percent or fixed.

is_limited_to_products

Set this to true if the discount should only be applied to certain products/variants. See details in the Relationships section below.

is_limited_redemptions

Set this to true if the discount should only be redeemed a limited number of times. See max_redemptions below.

max_redemptions

If is_limited_redemptions is true, this is the maximum number of redemptions.

starts_at

An ISO 8601 formatted date-time string indicating when the discount is valid from. Can omitted or null if no start date is specified.

expires_at

An ISO 8601 formatted date-time string indicating when the discount expires. Can omitted or null if the discount is perpetual.

duration

If the discount is applied to a subscription, this specifies how often the discount should be applied. One of

  • once - The discount will be applied to the initial payment only.
  • repeating - The discount will be applied to a certain number of payments (use in combination with duration_in_months.
  • forever - The discount will apply to all payments.

Defaults to once if omitted.

duration_in_months

If duration is repeating, this specifies how many months the discount should apply. Defaults to 1 if omitted.

test_mode

Set this to true if the discount should only be applied to test mode orders.


Relationships

store

The store this discount belongs to.

variants

If is_limited_to_products is true, the variant(s) the discount belongs to (this is not required otherwise).

curl -X "POST" "https://api.lemonsqueezy.com/v1/discounts" \
  -H "Accept: application/vnd.api+json" \
  -H "Content-Type: application/vnd.api+json" \
  -H "Authorization: Bearer {api_key}" \
  -d '{
    "data": {
      "type": "discounts",
      "attributes": {
        "name": "10% Off",
        "code": "10PERCENT",
        "amount": 10,
        "amount_type": "percent"
      },
      "relationships": {
        "store": {
          "data": {
            "type": "stores",
            "id": "1"
          }
        }
      }
    }
  }'

An example limiting the discount to certain variants:

curl -X "POST" "https://api.lemonsqueezy.com/v1/discounts" \
  -H "Accept: application/vnd.api+json" \
  -H "Content-Type: application/vnd.api+json" \
  -H "Authorization: Bearer {api_key}" \
  -d '{
    "data": {
      "type": "discounts",
      "attributes": {
        "name": "10% Off",
        "code": "10PERCENT",
        "amount": 10,
        "amount_type": "percent",
        "is_limited_to_products": true
      },
      "relationships": {
        "store": {
          "data": {
            "type": "stores",
            "id": "1"
          }
        },
        "variants": {
          "data": [
            {
              "type": "variants",
              "id": "3"
            },
            {
              "type": "variants",
              "id": "4"
            }
          ]
        }
      }
    }
  }'

Returns

Returns a Discount object.

{
  "jsonapi": {
    "version": "1.0"
  },
  "links": {
    "self": "https://api.lemonsqueezy.com/v1/discounts/1"
  },
  "data": {
    "type": "discounts",
    "id": "1",
    "attributes": {
      "store_id": 1,
      "name": "10% Off",
      "code": "10PERCENT",
      "amount": 10,
      "amount_type": "percent",
      "is_limited_to_products": false,
      "is_limited_redemptions": false,
      "max_redemptions": 0,
      "starts_at": null,
      "expires_at": null,
      "duration": "once",
      "duration_in_months": 1,
      "status": "published",
      "status_formatted": "Published",
      "created_at": "2021-05-24T14:15:06.000000Z",
      "updated_at": "2021-05-24T14:15:06.000000Z",
      "test_mode": false
    },
    "relationships": {
      "store": {
        "links": {
          "related": "https://api.lemonsqueezy.com/v1/discounts/1/store",
          "self": "https://api.lemonsqueezy.com/v1/discounts/1/relationships/store"
        }
      },
      "variants": {
        "links": {
          "related": "https://api.lemonsqueezy.com/v1/discounts/1/variants",
          "self": "https://api.lemonsqueezy.com/v1/discounts/1/relationships/variants"
        }
      },
      "discount-redemptions": {
        "links": {
          "related": "https://api.lemonsqueezy.com/v1/discounts/1/discount-redemptions",
          "self": "https://api.lemonsqueezy.com/v1/discounts/1/relationships/discount-redemptions"
        }
      }
    },
    "links": {
      "self": "https://api.lemonsqueezy.com/v1/discounts/1"
    }
  }
}

Was this page helpful?