discountAutomaticAppUpdate
Requires access scope.
Updates an existing automatic discount that's managed by an app using Shopify Functions. Use this mutation when you need advanced, custom, or dynamic discount capabilities that aren't supported by Shopify's native discount types.
For example, use this mutation to update a new "Volume" discount type that applies a percentage off when customers purchase more than the minimum quantity of a product. For an example implementation, refer to our tutorial.
Arguments
- Anchor to automaticAppDiscountautomatic•
App Discount DiscountAutomatic requiredApp Input! The input fields required to update the automatic discount.
- •ID!required
The ID of the automatic discount to update.
Anchor to DiscountAutomaticAppUpdatePayload returnsDiscountAutomaticAppUpdatePayload returns
- Anchor to automaticAppDiscountautomatic•
App Discount The updated automatic discount that the app provides.
- Anchor to userErrorsuser•
Errors [DiscountUser non-nullError!]! The list of errors that occurred from executing the mutation.
- Update an app-managed automatic discount title
- Update the date range of an app-managed automatic discount
- discountAutomaticAppUpdate reference
Examples
mutation discountAutomaticAppUpdate($automaticAppDiscount: DiscountAutomaticAppInput!, $id: ID!) {
discountAutomaticAppUpdate(automaticAppDiscount: $automaticAppDiscount, id: $id) {
automaticAppDiscount {
title
status
appDiscountType {
appKey
functionId
}
}
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 discountAutomaticAppUpdate($automaticAppDiscount: DiscountAutomaticAppInput!, $id: ID!) { discountAutomaticAppUpdate(automaticAppDiscount: $automaticAppDiscount, id: $id) { automaticAppDiscount { title status appDiscountType { appKey functionId } } userErrors { field message } } }",
"variables": {
"id": "gid://shopify/DiscountAutomaticNode/159339796",
"automaticAppDiscount": {
"title": "$5 discount"
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation discountAutomaticAppUpdate($automaticAppDiscount: DiscountAutomaticAppInput!, $id: ID!) {
discountAutomaticAppUpdate(automaticAppDiscount: $automaticAppDiscount, id: $id) {
automaticAppDiscount {
title
status
appDiscountType {
appKey
functionId
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"id": "gid://shopify/DiscountAutomaticNode/159339796",
"automaticAppDiscount": {
"title": "$5 discount"
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation discountAutomaticAppUpdate($automaticAppDiscount: DiscountAutomaticAppInput!, $id: ID!) {
discountAutomaticAppUpdate(automaticAppDiscount: $automaticAppDiscount, id: $id) {
automaticAppDiscount {
title
status
appDiscountType {
appKey
functionId
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"id": "gid://shopify/DiscountAutomaticNode/159339796",
"automaticAppDiscount": {
"title": "$5 discount"
}
},
},
});
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 discountAutomaticAppUpdate($automaticAppDiscount: DiscountAutomaticAppInput!, $id: ID!) {
discountAutomaticAppUpdate(automaticAppDiscount: $automaticAppDiscount, id: $id) {
automaticAppDiscount {
title
status
appDiscountType {
appKey
functionId
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"id": "gid://shopify/DiscountAutomaticNode/159339796",
"automaticAppDiscount": {
"title": "$5 discount"
}
}
response = client.query(query: query, variables: variables)