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
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",
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/2024-04/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
JSON{
"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",
Response
JSON{
"discountAutomaticBxgyCreate": {
"automaticDiscountNode": {
"id": "gid://shopify/DiscountAutomaticNode/1057371440",
"automaticDiscount": {
"title": "Buy first product, get second product free",
"startsAt": "2025-01-01T00:00:00Z",
"endsAt": "2025-12-31T23:59:59Z"
}
},
"userErrors": []
}
}