Hi Shopify Support,
I need to create orders programmatically with Buy X Get Y (BXGY) discount codes using the GraphQL Admin API.
Questions:
-
Does the
orderCreatemutation support BXGY discount codes natively? -
If yes, what is the correct input syntax to apply BXGY discounts?
-
If no, what is the recommended approach for programmatically creating orders with BXGY discounts?
Current Issue:
I’m using the orderCreate mutation to create cash orders. When I try to apply a BXGY discount, it doesn’t evaluate the “Buy X to unlock Get Y” logic correctly.
My Current Code (createCashOrder.ts):
TypeScript
// GraphQL mutation I'm using
const orderCreateMutation = `
mutation orderCreate($order: OrderCreateOrderInput!) {
**orderCreate(order: $order) {**
**order {**
**id**
**name**
**totalPriceSet {**
**shopMoney {**
**amount**
**currencyCode**
**}**
**}**
**lineItems(first: 50) {**
**edges {**
**node {**
**id**
**title**
**quantity**
**originalUnitPriceSet {**
**shopMoney {**
**amount**
**currencyCode**
**}**
**}**
**discountAllocations {**
**allocatedAmountSet {**
**shopMoney {**
**amount**
**currencyCode**
**}**
**}**
**}**
**}**
**}**
**}**
**}**
**userErrors {**
**field**
**message**
**}**
**}**
}
`;
// Line items input
const lineItemsInput = lineItemsArray.map((item: any) => ({
variantId: `gid://shopify/ProductVariant/${item.variantId}`,
quantity: parseInt(item.quantity) || 1,
priceSet: {
**shopMoney: {**
**amount: priceWithTax.*toFixed*(2),**
**currencyCode: 'INR'**
}
}
}));
// Order input with BXGY discount attempt
const orderInput = {
lineItems: lineItemsInput,
shippingAddress: shippingAddressInput,
billingAddress: billingAddressInput,
//
PROBLEM: How do I apply BXGY discount here?
// I only see these options:
itemPercentageDiscountCode: {
**code: "BUYXGETY50",**
**percentage: 50 *// But this applies to ALL items, not just "Get Y" items***
}
//
These don’t exist:
// bxgyDiscountCode: ???
// buyXgetYDiscountCode: ???
};
const response = await shopify.graphql(orderCreateMutation, { order: orderInput });
What Happens:
-
If I use
itemPercentageDiscountCode, it applies 50% to ALL line items (wrong!) -
I cannot find a way to tell Shopify: “Apply 50% discount ONLY to Powder item, ONLY IF Fresh item is purchased”
Example BXGY Discount:
-
Code: BUYXGETY50
-
Type: Buy X Get Y
-
Customer Buys: 1 quantity of “Fresh” product
-
Customer Gets: 50% off “Powder” product
This works correctly on the storefront checkout, but I need to replicate this in my backend POS system.
Workaround I’m Considering:
Should I manually calculate the BXGY discount in my application and send pre-discounted prices in the lineItems.priceSet? Or is there a proper way to apply BXGY discount codes via the API?
API Version: 2025-07
Thank you for your help!
Best regards,
Vedant Naik