Anchor to discountAutomaticBxgyUpdatediscount
discountAutomaticBxgyUpdate
mutation
Requires Apps must have access scope.
Updates an existing buy X get Y discount (BXGY) that's automatically applied on a cart and at checkout.
Anchor to Arguments
Arguments
- Anchor to automaticBxgyDiscountautomatic•
Bxgy Discount DiscountAutomatic requiredBxgy Input! The input data used to update the automatic BXGY discount.
- •ID!required
The ID of the automatic BXGY discount to update.
Was this section helpful?
Anchor to DiscountAutomaticBxgyUpdatePayload returnsDiscountAutomaticBxgyUpdatePayload returns
- Anchor to automaticDiscountNodeautomatic•
Discount Node The automatic discount that was updated.
- Anchor to userErrorsuser•
Errors [DiscountUser non-nullError!]! The list of errors that occurred from executing the mutation.
Was this section helpful?
- Update an automatic buy X get Y (BXGY) discount
- Updating a BXGY discount with invalid input returns an error
- discountAutomaticBxgyUpdate reference
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation UpdateBxgyDiscount($id: ID!, $automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {6 discountAutomaticBxgyUpdate(id: $id, 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 "id": "gid://shopify/DiscountAutomaticBxgy/198286294",26 "automaticBxgyDiscount": {27 "title": "Buy first product, get second product free",28 "startsAt": "2025-01-01T00:00:00Z",29 "endsAt": "2025-12-31T23:59:59Z",30 "customerBuys": {31 "items": {32 "products": {33 "productsToAdd": [34 "gid://shopify/Product/108828309"35 ]36 }37 },38 "value": {39 "quantity": "1"40 }41 },42 "customerGets": {43 "items": {44 "products": {45 "productsToAdd": [46 "gid://shopify/Product/20995642"47 ]48 }49 },50 "value": {51 "discountOnQuantity": {52 "quantity": "1",53 "effect": {54 "percentage": 1.055 }56 }57 }58 },59 "usesPerOrderLimit": "1"60 }61 },62 },63);6465const data = await response.json();66
mutation UpdateBxgyDiscount($id: ID!, $automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {
discountAutomaticBxgyUpdate(id: $id, 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 UpdateBxgyDiscount($id: ID!, $automaticBxgyDiscount: DiscountAutomaticBxgyInput!) { discountAutomaticBxgyUpdate(id: $id, automaticBxgyDiscount: $automaticBxgyDiscount) { automaticDiscountNode { id automaticDiscount { ... on DiscountAutomaticBxgy { title startsAt endsAt } } } userErrors { field message } } }",
"variables": {
"id": "gid://shopify/DiscountAutomaticBxgy/198286294",
"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 UpdateBxgyDiscount($id: ID!, $automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {
discountAutomaticBxgyUpdate(id: $id, automaticBxgyDiscount: $automaticBxgyDiscount) {
automaticDiscountNode {
id
automaticDiscount {
... on DiscountAutomaticBxgy {
title
startsAt
endsAt
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"id": "gid://shopify/DiscountAutomaticBxgy/198286294",
"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 UpdateBxgyDiscount($id: ID!, $automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {
discountAutomaticBxgyUpdate(id: $id, automaticBxgyDiscount: $automaticBxgyDiscount) {
automaticDiscountNode {
id
automaticDiscount {
... on DiscountAutomaticBxgy {
title
startsAt
endsAt
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"id": "gid://shopify/DiscountAutomaticBxgy/198286294",
"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 UpdateBxgyDiscount($id: ID!, $automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {
discountAutomaticBxgyUpdate(id: $id, automaticBxgyDiscount: $automaticBxgyDiscount) {
automaticDiscountNode {
id
automaticDiscount {
... on DiscountAutomaticBxgy {
title
startsAt
endsAt
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"id": "gid://shopify/DiscountAutomaticBxgy/198286294",
"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 "id": "gid://shopify/DiscountAutomaticBxgy/198286294",3 "automaticBxgyDiscount": {4 "title": "Buy first product, get second product free",5 "startsAt": "2025-01-01T00:00:00Z",6 "endsAt": "2025-12-31T23:59:59Z",7 "customerBuys": {8 "items": {9 "products": {10 "productsToAdd": [11 "gid://shopify/Product/108828309"12 ]13 }14 },15 "value": {16 "quantity": "1"17 }18 },19 "customerGets": {20 "items": {21 "products": {22 "productsToAdd": [23 "gid://shopify/Product/20995642"24 ]25 }26 },27 "value": {28 "discountOnQuantity": {29 "quantity": "1",30 "effect": {31 "percentage": 132 }33 }34 }35 },36 "usesPerOrderLimit": "1"37 }38}
Response
JSON1{2 "discountAutomaticBxgyUpdate": {3 "automaticDiscountNode": {4 "id": "gid://shopify/DiscountAutomaticNode/198286294",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}