Create code discounts
You can create a discount that includes a unique code. Customers can redeem specific discounts by applying the code during checkout. This guide shows you how to create different types of code discounts using the GraphQL Admin API.
Requirements
Anchor link to section titled "Requirements"- Your app can make authenticated requests to the GraphQL Admin API.
- Your app has the
write_discounts
access scope. - You've configured shipping zones for the shop.
- You've created customer segments for the shop.
Step 1: Create a Buy X Get Y or Spend X Get Y code discount
Anchor link to section titled "Step 1: Create a Buy X Get Y or Spend X Get Y code discount"A Buy X Get Y or Spend X Get Y are code discounts that offers customer discounts on select products if they add a specific product to their order. You can use the discountCodeBxgyCreate
to create a Buy X Get Y or Spend X Get Y code discount.
The following example shows how to create a Spend $100 Get One discount that requires the customer to enter a code at checkout. In this case, it lets all customers use this code, and offers a Spend $100 Get One discount on the same product.
The discount displays in the Discounts section of the Shopify admin:
Step 2: Create a percentage or fixed-amount discount code
Anchor link to section titled "Step 2: Create a percentage or fixed-amount discount code"You can use the discountCodeBasicCreate
mutation to create a percentage or fixed-amount discount code.
The following example shows how to associate a flat percentage or fixed-amount discount with a code that the customer can use at checkout. The GraphQL mutation is similar in format to creating a Buy One Get One discount, but in this case, you'll create a $1.00 off discount for a specific product.
The discount displays in the Discounts section of the Shopify admin:
Step 3: Create a free shipping code discount
Anchor link to section titled "Step 3: Create a free shipping code discount"You can use the discountCodeFreeShippingCreate
mutation to create a free shipping code discount.
The following example shows how to associate a free shipping discount with a code that will grant the customer free shipping when they use it. In this example, the discount applies to a segment of customers in customerSelection.customerSegments
if the customers are from Canada.
The discount displays in the Discounts section of the Shopify admin:
- Create a discount that's automatically applied to a cart if prerequisites are met.
- Manage and make changes to existing discounts.