discountCodeAppCreate
Requires access scope.
Creates a code discount. The discount type must be provided by an app extension that uses Shopify Functions. Functions can implement order, product, or shipping discount functions. Use this mutation with Shopify Functions when you need custom logic beyond Shopify's native discount types.
For example, use this mutation to create a code 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 codeAppDiscountcode•
App Discount DiscountCode requiredApp Input! The input data used to create the discount.
Anchor to DiscountCodeAppCreatePayload returnsDiscountCodeAppCreatePayload returns
- Anchor to codeAppDiscountcode•
App Discount The discount that the app provides.
- Anchor to userErrorsuser•
Errors [DiscountUser non-nullError!]! The list of errors that occurred from executing the mutation.
- Create a combinable code discount that's managed by an app
- Create a product-based code discount that's managed by an app
- discountCodeAppCreate reference
Examples
mutation discountCodeAppCreate($codeAppDiscount: DiscountCodeAppInput!) {
discountCodeAppCreate(codeAppDiscount: $codeAppDiscount) {
codeAppDiscount {
discountId
title
appDiscountType {
description
functionId
}
combinesWith {
orderDiscounts
productDiscounts
shippingDiscounts
}
codes(first: 100) {
nodes {
code
}
}
status
usageLimit
}
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 discountCodeAppCreate($codeAppDiscount: DiscountCodeAppInput!) { discountCodeAppCreate(codeAppDiscount: $codeAppDiscount) { codeAppDiscount { discountId title appDiscountType { description functionId } combinesWith { orderDiscounts productDiscounts shippingDiscounts } codes(first: 100) { nodes { code } } status usageLimit } userErrors { field message } } }",
"variables": {
"codeAppDiscount": {
"code": "APP_DISCOUNT",
"title": "Take 5$ from order discount",
"functionId": "241d1090-ce51-4c0e-8b87-a6fa14fe580a",
"appliesOncePerCustomer": true,
"combinesWith": {
"orderDiscounts": true,
"productDiscounts": true,
"shippingDiscounts": true
},
"startsAt": "2021-02-02T17:09:21Z",
"endsAt": "2022-02-02T17:09:21Z",
"usageLimit": 1,
"metafields": [
{
"namespace": "default",
"key": "function-configuration",
"type": "json",
"value": "{\"discounts\":[{\"value\":{\"fixedAmount\":{\"amount\":5}},\"targets\":\n [{\"orderSubtotal\":{\"excludedVariantIds\":[]}}]}],\"discountApplicationStrategy\":\"FIRST\"}"
}
]
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation discountCodeAppCreate($codeAppDiscount: DiscountCodeAppInput!) {
discountCodeAppCreate(codeAppDiscount: $codeAppDiscount) {
codeAppDiscount {
discountId
title
appDiscountType {
description
functionId
}
combinesWith {
orderDiscounts
productDiscounts
shippingDiscounts
}
codes(first: 100) {
nodes {
code
}
}
status
usageLimit
}
userErrors {
field
message
}
}
}`,
{
variables: {
"codeAppDiscount": {
"code": "APP_DISCOUNT",
"title": "Take 5$ from order discount",
"functionId": "241d1090-ce51-4c0e-8b87-a6fa14fe580a",
"appliesOncePerCustomer": true,
"combinesWith": {
"orderDiscounts": true,
"productDiscounts": true,
"shippingDiscounts": true
},
"startsAt": "2021-02-02T17:09:21Z",
"endsAt": "2022-02-02T17:09:21Z",
"usageLimit": 1,
"metafields": [
{
"namespace": "default",
"key": "function-configuration",
"type": "json",
"value": "{\"discounts\":[{\"value\":{\"fixedAmount\":{\"amount\":5}},\"targets\":\n [{\"orderSubtotal\":{\"excludedVariantIds\":[]}}]}],\"discountApplicationStrategy\":\"FIRST\"}"
}
]
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation discountCodeAppCreate($codeAppDiscount: DiscountCodeAppInput!) {
discountCodeAppCreate(codeAppDiscount: $codeAppDiscount) {
codeAppDiscount {
discountId
title
appDiscountType {
description
functionId
}
combinesWith {
orderDiscounts
productDiscounts
shippingDiscounts
}
codes(first: 100) {
nodes {
code
}
}
status
usageLimit
}
userErrors {
field
message
}
}
}`,
"variables": {
"codeAppDiscount": {
"code": "APP_DISCOUNT",
"title": "Take 5$ from order discount",
"functionId": "241d1090-ce51-4c0e-8b87-a6fa14fe580a",
"appliesOncePerCustomer": true,
"combinesWith": {
"orderDiscounts": true,
"productDiscounts": true,
"shippingDiscounts": true
},
"startsAt": "2021-02-02T17:09:21Z",
"endsAt": "2022-02-02T17:09:21Z",
"usageLimit": 1,
"metafields": [
{
"namespace": "default",
"key": "function-configuration",
"type": "json",
"value": "{\"discounts\":[{\"value\":{\"fixedAmount\":{\"amount\":5}},\"targets\":\n [{\"orderSubtotal\":{\"excludedVariantIds\":[]}}]}],\"discountApplicationStrategy\":\"FIRST\"}"
}
]
}
},
},
});
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 discountCodeAppCreate($codeAppDiscount: DiscountCodeAppInput!) {
discountCodeAppCreate(codeAppDiscount: $codeAppDiscount) {
codeAppDiscount {
discountId
title
appDiscountType {
description
functionId
}
combinesWith {
orderDiscounts
productDiscounts
shippingDiscounts
}
codes(first: 100) {
nodes {
code
}
}
status
usageLimit
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"codeAppDiscount": {
"code": "APP_DISCOUNT",
"title": "Take 5$ from order discount",
"functionId": "241d1090-ce51-4c0e-8b87-a6fa14fe580a",
"appliesOncePerCustomer": true,
"combinesWith": {
"orderDiscounts": true,
"productDiscounts": true,
"shippingDiscounts": true
},
"startsAt": "2021-02-02T17:09:21Z",
"endsAt": "2022-02-02T17:09:21Z",
"usageLimit": 1,
"metafields": [{"namespace"=>"default", "key"=>"function-configuration", "type"=>"json", "value"=>"{\"discounts\":[{\"value\":{\"fixedAmount\":{\"amount\":5}},\"targets\":\n [{\"orderSubtotal\":{\"excludedVariantIds\":[]}}]}],\"discountApplicationStrategy\":\"FIRST\"}"}]
}
}
response = client.query(query: query, variables: variables)