Create and manage discounts with the Admin API
This guide describes how to create and retrieve discounts by using the GraphQL Admin API. It provides examples for two different types of discounts (automatic discounts and code discounts), and the recommended best practices for each type.
For a full list of the schema, see the GraphQL Admin API reference.
If you aren’t familiar with GraphQL, then refer to the Getting started with the GraphQL Admin and REST Admin APIs guide or The GraphQL Learning Kit to learn more.
- The mutations described here require the
- The queries described here require the
Creating automatic discounts
Automatic discounts refer to the set of objects and mutations in GraphQL that let you create and manage discounts that are automatically applied to a cart if prerequisites are met. This method is available only in the GraphQL Admin API.
The following examples show two different types of automatic discounts:
Buy X Get Y or Spend X Get Y automatic discount
This example shows how to create an automatic Buy One Get One discount that will be applied to a single product any time it’s included in a cart. In this case, it applies a 100% discount on the second item in a cart, as long as it’s the same product as the first item.
Based on that example, you can make a few different changes to offer specific types of discounts:
- If you want to change the discount amount, then edit
- If you want to apply the discount to a different item, then use
customerGets.items.products.productsToRemoveto update the entitlements.
- If you want to apply the discount to all items, then use
customerGets.items.allinstead of a specific product ID.
- If you want a customer to get a discount no matter which item they purchase, then set the