Anchor to discountAutomaticAppUpdatediscount
discount Automatic App Update
mutation
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.
Anchor to Arguments
Arguments
- Anchor to automaticAppDiscountautomatic•
App Discount DiscountAutomatic App Input!required The input fields required to update the automatic discount.
- •ID!required
The ID of the automatic discount to update.
Was this section helpful?
- Anchor to automaticAppDiscountautomatic•
App Discount The updated automatic discount that the app provides.
- Anchor to userErrorsuser•
Errors [DiscountUser Error!]!non-null The list of errors that occurred from executing the mutation.
Was this section helpful?
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation discountAutomaticAppUpdate($automaticAppDiscount: DiscountAutomaticAppInput!, $id: ID!) {6 discountAutomaticAppUpdate(automaticAppDiscount: $automaticAppDiscount, id: $id) {7 automaticAppDiscount {8 title9 status10 appDiscountType {11 appKey12 functionId13 }14 }15 userErrors {16 field17 message18 }19 }20 }`,21 {22 variables: {23 "id": "gid://shopify/DiscountAutomaticNode/159339796",24 "automaticAppDiscount": {25 "title": "$5 discount"26 }27 },28 },29);3031const data = await response.json();32
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/2025-01/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)
Input variables
JSON1{2 "id": "gid://shopify/DiscountAutomaticNode/159339796",3 "automaticAppDiscount": {4 "title": "$5 discount"5 }6}
Response
JSON1{2 "discountAutomaticAppUpdate": {3 "automaticAppDiscount": {4 "title": "$5 discount",5 "status": "EXPIRED",6 "appDiscountType": {7 "appKey": "shopify-vm-test-app",8 "functionId": "135222cd-678c-47a9-880d-a59dba77d975"9 }10 },11 "userErrors": []12 }13}