discountAutomaticAppCreate
Requires access scope.
Creates an automatic discount that's managed by an app. Use this mutation with Shopify Functions 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 create an automatic discount using an app's "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 data used to create the automatic discount.
Anchor to DiscountAutomaticAppCreatePayload returnsDiscountAutomaticAppCreatePayload returns
- Anchor to automaticAppDiscountautomatic•
App Discount The automatic discount that the app manages.
- Anchor to userErrorsuser•
Errors [DiscountUser non-nullError!]! The list of errors that occurred from executing the mutation.
- Create a non-combinable automatic discount that's managed by an app
- Create an automatic product discount that's managed by an app
- discountAutomaticAppCreate reference
Examples
mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) {
discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) {
userErrors {
field
message
}
automaticAppDiscount {
discountId
title
startsAt
endsAt
status
appDiscountType {
appKey
functionId
}
combinesWith {
orderDiscounts
productDiscounts
shippingDiscounts
}
}
}
}
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 discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) { discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) { userErrors { field message } automaticAppDiscount { discountId title startsAt endsAt status appDiscountType { appKey functionId } combinesWith { orderDiscounts productDiscounts shippingDiscounts } } } }",
"variables": {
"automaticAppDiscount": {
"title": "$5 discount",
"functionId": "de7a6b74-5ac7-432f-8d5b-98dd14fb8af5",
"startsAt": "2025-02-02T17:09:21Z",
"endsAt": "2025-02-02T17:09:21Z",
"combinesWith": {
"orderDiscounts": false,
"productDiscounts": false,
"shippingDiscounts": false
},
"metafields": [
{
"namespace": "default",
"key": "function-configuration",
"type": "json",
"value": "{\n \"discounts\": [{\n \"value\": {\"fixedAmount\": {\"amount\": 5}},\n \"targets\": [{\"orderSubtotal\": {\"excludedVariantIds\": []}}]\n }],\n \"discountApplicationStrategy\": \"FIRST\"\n}"
}
]
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) {
discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) {
userErrors {
field
message
}
automaticAppDiscount {
discountId
title
startsAt
endsAt
status
appDiscountType {
appKey
functionId
}
combinesWith {
orderDiscounts
productDiscounts
shippingDiscounts
}
}
}
}`,
{
variables: {
"automaticAppDiscount": {
"title": "$5 discount",
"functionId": "de7a6b74-5ac7-432f-8d5b-98dd14fb8af5",
"startsAt": "2025-02-02T17:09:21Z",
"endsAt": "2025-02-02T17:09:21Z",
"combinesWith": {
"orderDiscounts": false,
"productDiscounts": false,
"shippingDiscounts": false
},
"metafields": [
{
"namespace": "default",
"key": "function-configuration",
"type": "json",
"value": "{\n \"discounts\": [{\n \"value\": {\"fixedAmount\": {\"amount\": 5}},\n \"targets\": [{\"orderSubtotal\": {\"excludedVariantIds\": []}}]\n }],\n \"discountApplicationStrategy\": \"FIRST\"\n}"
}
]
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) {
discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) {
userErrors {
field
message
}
automaticAppDiscount {
discountId
title
startsAt
endsAt
status
appDiscountType {
appKey
functionId
}
combinesWith {
orderDiscounts
productDiscounts
shippingDiscounts
}
}
}
}`,
"variables": {
"automaticAppDiscount": {
"title": "$5 discount",
"functionId": "de7a6b74-5ac7-432f-8d5b-98dd14fb8af5",
"startsAt": "2025-02-02T17:09:21Z",
"endsAt": "2025-02-02T17:09:21Z",
"combinesWith": {
"orderDiscounts": false,
"productDiscounts": false,
"shippingDiscounts": false
},
"metafields": [
{
"namespace": "default",
"key": "function-configuration",
"type": "json",
"value": "{\n \"discounts\": [{\n \"value\": {\"fixedAmount\": {\"amount\": 5}},\n \"targets\": [{\"orderSubtotal\": {\"excludedVariantIds\": []}}]\n }],\n \"discountApplicationStrategy\": \"FIRST\"\n}"
}
]
}
},
},
});
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 discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) {
discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) {
userErrors {
field
message
}
automaticAppDiscount {
discountId
title
startsAt
endsAt
status
appDiscountType {
appKey
functionId
}
combinesWith {
orderDiscounts
productDiscounts
shippingDiscounts
}
}
}
}
QUERY
variables = {
"automaticAppDiscount": {
"title": "$5 discount",
"functionId": "de7a6b74-5ac7-432f-8d5b-98dd14fb8af5",
"startsAt": "2025-02-02T17:09:21Z",
"endsAt": "2025-02-02T17:09:21Z",
"combinesWith": {
"orderDiscounts": false,
"productDiscounts": false,
"shippingDiscounts": false
},
"metafields": [{"namespace"=>"default", "key"=>"function-configuration", "type"=>"json", "value"=>"{\n \"discounts\": [{\n \"value\": {\"fixedAmount\": {\"amount\": 5}},\n \"targets\": [{\"orderSubtotal\": {\"excludedVariantIds\": []}}]\n }],\n \"discountApplicationStrategy\": \"FIRST\"\n}"}]
}
}
response = client.query(query: query, variables: variables)