Anchor to discountAutomaticBxgyCreatediscount
discountAutomaticBxgyCreate
mutation
Requires Apps must have access scope.
Anchor to Arguments
Arguments
- Anchor to automaticBxgyDiscountautomatic•
Bxgy Discount DiscountAutomatic requiredBxgy Input! The input data used to create the automatic BXGY discount.
Was this section helpful?
Anchor to DiscountAutomaticBxgyCreatePayload returnsDiscountAutomaticBxgyCreatePayload returns
- Anchor to automaticDiscountNodeautomatic•
Discount Node The automatic discount that was created.
- Anchor to userErrorsuser•
Errors [DiscountUser non-nullError!]! The list of errors that occurred from executing the mutation.
Was this section helpful?
- Create an automatic buy X get Y (BXGY) discount for different products
- Create an automatic buy X get Y (BXGY) discount for the same product
- discountAutomaticBxgyCreate reference
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation CreateBxgyDiscount($automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {6 discountAutomaticBxgyCreate(automaticBxgyDiscount: $automaticBxgyDiscount) {7 automaticDiscountNode {8 id9 automaticDiscount {10 ... on DiscountAutomaticBxgy {11 title12 startsAt13 endsAt14 }15 }16 }17 userErrors {18 field19 message20 }21 }22 }`,23 {24 variables: {25 "automaticBxgyDiscount": {26 "title": "Buy first product, get second product free",27 "startsAt": "2025-01-01T00:00:00Z",28 "endsAt": "2025-12-31T23:59:59Z",29 "customerBuys": {30 "items": {31 "products": {32 "productsToAdd": [33 "gid://shopify/Product/108828309"34 ]35 }36 },37 "value": {38 "quantity": "1"39 }40 },41 "customerGets": {42 "items": {43 "products": {44 "productsToAdd": [45 "gid://shopify/Product/20995642"46 ]47 }48 },49 "value": {50 "discountOnQuantity": {51 "quantity": "1",52 "effect": {53 "percentage": 1.054 }55 }56 }57 },58 "usesPerOrderLimit": "1"59 }60 },61 },62);6364const data = await response.json();65
mutation CreateBxgyDiscount($automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {
discountAutomaticBxgyCreate(automaticBxgyDiscount: $automaticBxgyDiscount) {
automaticDiscountNode {
id
automaticDiscount {
... on DiscountAutomaticBxgy {
title
startsAt
endsAt
}
}
}
userErrors {
field
message
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation CreateBxgyDiscount($automaticBxgyDiscount: DiscountAutomaticBxgyInput!) { discountAutomaticBxgyCreate(automaticBxgyDiscount: $automaticBxgyDiscount) { automaticDiscountNode { id automaticDiscount { ... on DiscountAutomaticBxgy { title startsAt endsAt } } } userErrors { field message } } }",
"variables": {
"automaticBxgyDiscount": {
"title": "Buy first product, get second product free",
"startsAt": "2025-01-01T00:00:00Z",
"endsAt": "2025-12-31T23:59:59Z",
"customerBuys": {
"items": {
"products": {
"productsToAdd": [
"gid://shopify/Product/108828309"
]
}
},
"value": {
"quantity": "1"
}
},
"customerGets": {
"items": {
"products": {
"productsToAdd": [
"gid://shopify/Product/20995642"
]
}
},
"value": {
"discountOnQuantity": {
"quantity": "1",
"effect": {
"percentage": 1.0
}
}
}
},
"usesPerOrderLimit": "1"
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CreateBxgyDiscount($automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {
discountAutomaticBxgyCreate(automaticBxgyDiscount: $automaticBxgyDiscount) {
automaticDiscountNode {
id
automaticDiscount {
... on DiscountAutomaticBxgy {
title
startsAt
endsAt
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"automaticBxgyDiscount": {
"title": "Buy first product, get second product free",
"startsAt": "2025-01-01T00:00:00Z",
"endsAt": "2025-12-31T23:59:59Z",
"customerBuys": {
"items": {
"products": {
"productsToAdd": [
"gid://shopify/Product/108828309"
]
}
},
"value": {
"quantity": "1"
}
},
"customerGets": {
"items": {
"products": {
"productsToAdd": [
"gid://shopify/Product/20995642"
]
}
},
"value": {
"discountOnQuantity": {
"quantity": "1",
"effect": {
"percentage": 1.0
}
}
}
},
"usesPerOrderLimit": "1"
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation CreateBxgyDiscount($automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {
discountAutomaticBxgyCreate(automaticBxgyDiscount: $automaticBxgyDiscount) {
automaticDiscountNode {
id
automaticDiscount {
... on DiscountAutomaticBxgy {
title
startsAt
endsAt
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"automaticBxgyDiscount": {
"title": "Buy first product, get second product free",
"startsAt": "2025-01-01T00:00:00Z",
"endsAt": "2025-12-31T23:59:59Z",
"customerBuys": {
"items": {
"products": {
"productsToAdd": [
"gid://shopify/Product/108828309"
]
}
},
"value": {
"quantity": "1"
}
},
"customerGets": {
"items": {
"products": {
"productsToAdd": [
"gid://shopify/Product/20995642"
]
}
},
"value": {
"discountOnQuantity": {
"quantity": "1",
"effect": {
"percentage": 1.0
}
}
}
},
"usesPerOrderLimit": "1"
}
},
},
});
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
mutation CreateBxgyDiscount($automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {
discountAutomaticBxgyCreate(automaticBxgyDiscount: $automaticBxgyDiscount) {
automaticDiscountNode {
id
automaticDiscount {
... on DiscountAutomaticBxgy {
title
startsAt
endsAt
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"automaticBxgyDiscount": {
"title": "Buy first product, get second product free",
"startsAt": "2025-01-01T00:00:00Z",
"endsAt": "2025-12-31T23:59:59Z",
"customerBuys": {
"items": {
"products": {
"productsToAdd": ["gid://shopify/Product/108828309"]
}
},
"value": {
"quantity": "1"
}
},
"customerGets": {
"items": {
"products": {
"productsToAdd": ["gid://shopify/Product/20995642"]
}
},
"value": {
"discountOnQuantity": {
"quantity": "1",
"effect": {
"percentage": 1.0
}
}
}
},
"usesPerOrderLimit": "1"
}
}
response = client.query(query: query, variables: variables)
Input variables
JSON1{2 "automaticBxgyDiscount": {3 "title": "Buy first product, get second product free",4 "startsAt": "2025-01-01T00:00:00Z",5 "endsAt": "2025-12-31T23:59:59Z",6 "customerBuys": {7 "items": {8 "products": {9 "productsToAdd": [10 "gid://shopify/Product/108828309"11 ]12 }13 },14 "value": {15 "quantity": "1"16 }17 },18 "customerGets": {19 "items": {20 "products": {21 "productsToAdd": [22 "gid://shopify/Product/20995642"23 ]24 }25 },26 "value": {27 "discountOnQuantity": {28 "quantity": "1",29 "effect": {30 "percentage": 131 }32 }33 }34 },35 "usesPerOrderLimit": "1"36 }37}
Response
JSON1{2 "discountAutomaticBxgyCreate": {3 "automaticDiscountNode": {4 "id": "gid://shopify/DiscountAutomaticNode/1057371440",5 "automaticDiscount": {6 "title": "Buy first product, get second product free",7 "startsAt": "2025-01-01T00:00:00Z",8 "endsAt": "2025-12-31T23:59:59Z"9 }10 },11 "userErrors": []12 }13}