--- title: discountAutomaticAppCreate - GraphQL Admin description: |- Creates an automatic discount that's managed by an app. Use this mutation with [Shopify Functions](https://shopify.dev/docs/apps/build/functions) when you need advanced, custom, or dynamic discount capabilities that aren't supported by [Shopify's native discount types](https://help.shopify.com/manual/discounts/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](https://shopify.dev/docs/apps/build/discounts/build-discount-function). > Note: > To create code discounts with custom logic, use the [`discountCodeAppCreate`](https://shopify.dev/docs/api/admin-graphql/latest/mutations/discountCodeAppCreate) mutation. api_version: 2025-10 api_name: admin type: mutation api_type: graphql source_url: html: https://shopify.dev/docs/api/admin-graphql/latest/mutations/discountAutomaticAppCreate md: https://shopify.dev/docs/api/admin-graphql/latest/mutations/discountAutomaticAppCreate.md --- # discount​Automatic​App​Create mutation Requires `write_discounts` access scope. Creates an automatic discount that's managed by an app. Use this mutation with [Shopify Functions](https://shopify.dev/docs/apps/build/functions) when you need advanced, custom, or dynamic discount capabilities that aren't supported by [Shopify's native discount types](https://help.shopify.com/manual/discounts/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](https://shopify.dev/docs/apps/build/discounts/build-discount-function). *** Note To create code discounts with custom logic, use the [`discountCodeAppCreate`](https://shopify.dev/docs/api/admin-graphql/latest/mutations/discountCodeAppCreate) mutation. *** ## Arguments * automatic​App​Discount [Discount​Automatic​App​Input!](https://shopify.dev/docs/api/admin-graphql/latest/input-objects/DiscountAutomaticAppInput) required The input data used to create the automatic discount. *** ## Discount​Automatic​App​Create​Payload returns * automatic​App​Discount [Discount​Automatic​App](https://shopify.dev/docs/api/admin-graphql/latest/objects/DiscountAutomaticApp) The automatic discount that the app manages. * user​Errors [\[Discount​User​Error!\]!](https://shopify.dev/docs/api/admin-graphql/latest/objects/DiscountUserError) non-null The list of errors that occurred from executing the mutation. *** ## Examples * ### Create a non-combinable automatic order discount that's managed by an app #### Description Create an automatic discount that's managed by an app using \[Shopify Functions]\(https\://shopify.dev/docs/apps/build/functions). This example shows how to create an automatic discount that takes $5 off the order subtotal and can't be \[combined]\(https\://help.shopify.com/manual/discounts/combining-discounts/discount-combinations) with other discounts. #### Query ```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 ```json { "automaticAppDiscount": { "title": "$5 discount", "functionId": "a3cdef66-d84a-4254-9216-b6dd723005ad", "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}" } ] } } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2025-10/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": "a3cdef66-d84a-4254-9216-b6dd723005ad", "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}" } ] } } }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { 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": "a3cdef66-d84a-4254-9216-b6dd723005ad", "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 json = await response.json(); return json.data; } ``` #### Ruby ```ruby 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": "a3cdef66-d84a-4254-9216-b6dd723005ad", "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) ``` #### Node.js ```javascript 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": "a3cdef66-d84a-4254-9216-b6dd723005ad", "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 ```json { "discountAutomaticAppCreate": { "userErrors": [], "automaticAppDiscount": { "discountId": "gid://shopify/DiscountAutomaticNode/1057856655", "title": "$5 discount", "startsAt": "2025-02-02T17:09:21Z", "endsAt": "2025-02-02T17:09:21Z", "status": "EXPIRED", "appDiscountType": { "appKey": "shopify-web", "functionId": "13d358d1-2a5b-4a39-a6f9-8f53394e440d" }, "combinesWith": { "orderDiscounts": false, "productDiscounts": false, "shippingDiscounts": false } } } } ``` * ### Create an automatic app product discount for a customer segment #### Description Create an automatic discount that's managed by an app using \[Shopify Functions]\(https\://shopify.dev/docs/apps/build/functions). This example shows how to create an automatic discount that takes $10 off a specific product and applies only to a specific customer segment. #### Query ```graphql mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) { discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) { userErrors { field message } automaticAppDiscount { discountId title startsAt endsAt status context { ... on DiscountCustomerSegments { segments { id } } } appDiscountType { appKey functionId } } } } ``` #### Variables ```json { "automaticAppDiscount": { "title": "Product discount $10 off", "functionId": "6bb26213-4a3c-4e83-94bf-98599b4b6648", "startsAt": "2025-07-25T19:52:03-04:00", "context": { "customerSegments": { "add": [ "gid://shopify/Segment/8961721" ] } }, "metafields": [ { "namespace": "default", "key": "function-configuration", "type": "json", "value": "{\n \"discounts\": [{\n \"value\": {\"fixedAmount\": {\"amount\": 10}},\n \"targets\": [{\"productVariant\": {\"id\": \"gid://shopify/ProductVariant/12345\"}}]\n }],\n \"discountApplicationStrategy\": \"FIRST\"\n}" } ] } } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2025-10/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 context { ... on DiscountCustomerSegments { segments { id } } } appDiscountType { appKey functionId } } } }", "variables": { "automaticAppDiscount": { "title": "Product discount $10 off", "functionId": "6bb26213-4a3c-4e83-94bf-98599b4b6648", "startsAt": "2025-07-25T19:52:03-04:00", "context": { "customerSegments": { "add": [ "gid://shopify/Segment/8961721" ] } }, "metafields": [ { "namespace": "default", "key": "function-configuration", "type": "json", "value": "{\n \"discounts\": [{\n \"value\": {\"fixedAmount\": {\"amount\": 10}},\n \"targets\": [{\"productVariant\": {\"id\": \"gid://shopify/ProductVariant/12345\"}}]\n }],\n \"discountApplicationStrategy\": \"FIRST\"\n}" } ] } } }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { 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 context { ... on DiscountCustomerSegments { segments { id } } } appDiscountType { appKey functionId } } } }`, { variables: { "automaticAppDiscount": { "title": "Product discount $10 off", "functionId": "6bb26213-4a3c-4e83-94bf-98599b4b6648", "startsAt": "2025-07-25T19:52:03-04:00", "context": { "customerSegments": { "add": [ "gid://shopify/Segment/8961721" ] } }, "metafields": [ { "namespace": "default", "key": "function-configuration", "type": "json", "value": "{\n \"discounts\": [{\n \"value\": {\"fixedAmount\": {\"amount\": 10}},\n \"targets\": [{\"productVariant\": {\"id\": \"gid://shopify/ProductVariant/12345\"}}]\n }],\n \"discountApplicationStrategy\": \"FIRST\"\n}" } ] } }, }, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby 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 context { ... on DiscountCustomerSegments { segments { id } } } appDiscountType { appKey functionId } } } } QUERY variables = { "automaticAppDiscount": { "title": "Product discount $10 off", "functionId": "6bb26213-4a3c-4e83-94bf-98599b4b6648", "startsAt": "2025-07-25T19:52:03-04:00", "context": { "customerSegments": { "add": [ "gid://shopify/Segment/8961721" ] } }, "metafields": [ { "namespace": "default", "key": "function-configuration", "type": "json", "value": "{\n \"discounts\": [{\n \"value\": {\"fixedAmount\": {\"amount\": 10}},\n \"targets\": [{\"productVariant\": {\"id\": \"gid://shopify/ProductVariant/12345\"}}]\n }],\n \"discountApplicationStrategy\": \"FIRST\"\n}" } ] } } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript 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 context { ... on DiscountCustomerSegments { segments { id } } } appDiscountType { appKey functionId } } } }`, "variables": { "automaticAppDiscount": { "title": "Product discount $10 off", "functionId": "6bb26213-4a3c-4e83-94bf-98599b4b6648", "startsAt": "2025-07-25T19:52:03-04:00", "context": { "customerSegments": { "add": [ "gid://shopify/Segment/8961721" ] } }, "metafields": [ { "namespace": "default", "key": "function-configuration", "type": "json", "value": "{\n \"discounts\": [{\n \"value\": {\"fixedAmount\": {\"amount\": 10}},\n \"targets\": [{\"productVariant\": {\"id\": \"gid://shopify/ProductVariant/12345\"}}]\n }],\n \"discountApplicationStrategy\": \"FIRST\"\n}" } ] } }, }, }); ``` #### Response ```json { "discountAutomaticAppCreate": { "userErrors": [], "automaticAppDiscount": { "discountId": "gid://shopify/DiscountAutomaticNode/1057856656", "title": "Product discount $10 off", "startsAt": "2025-07-25T23:52:03Z", "endsAt": null, "status": "ACTIVE", "context": { "segments": [ { "id": "gid://shopify/Segment/8961721" } ] }, "appDiscountType": { "appKey": "shopify-web", "functionId": "6bb26213-4a3c-4e83-94bf-98599b4b6648" } } } } ``` * ### Create an automatic product discount that's managed by an app #### Description Create an automatic discount that's managed by an app using \[Shopify Functions]\(https\://shopify.dev/docs/apps/build/functions). This example shows how to create an automatic discount that takes $10 off a specific product. #### Query ```graphql mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) { discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) { userErrors { field message } automaticAppDiscount { discountId title startsAt endsAt status appDiscountType { appKey functionId } } } } ``` #### Variables ```json { "automaticAppDiscount": { "title": "Product discount $10 off", "functionId": "677bc937-7dce-4fe4-8e8d-076c391d3e53", "startsAt": "2025-01-01T00:00:00Z", "endsAt": "2025-12-31T23:59:59Z", "metafields": [ { "namespace": "default", "key": "function-configuration", "type": "json", "value": "{\n \"discounts\": [{\n \"value\": {\"fixedAmount\": {\"amount\": 10}},\n \"targets\": [{\"productVariant\": {\"id\": \"gid://shopify/ProductVariant/12345\"}}]\n }],\n \"discountApplicationStrategy\": \"FIRST\"\n}" } ] } } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2025-10/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 } } } }", "variables": { "automaticAppDiscount": { "title": "Product discount $10 off", "functionId": "677bc937-7dce-4fe4-8e8d-076c391d3e53", "startsAt": "2025-01-01T00:00:00Z", "endsAt": "2025-12-31T23:59:59Z", "metafields": [ { "namespace": "default", "key": "function-configuration", "type": "json", "value": "{\n \"discounts\": [{\n \"value\": {\"fixedAmount\": {\"amount\": 10}},\n \"targets\": [{\"productVariant\": {\"id\": \"gid://shopify/ProductVariant/12345\"}}]\n }],\n \"discountApplicationStrategy\": \"FIRST\"\n}" } ] } } }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { 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 } } } }`, { variables: { "automaticAppDiscount": { "title": "Product discount $10 off", "functionId": "677bc937-7dce-4fe4-8e8d-076c391d3e53", "startsAt": "2025-01-01T00:00:00Z", "endsAt": "2025-12-31T23:59:59Z", "metafields": [ { "namespace": "default", "key": "function-configuration", "type": "json", "value": "{\n \"discounts\": [{\n \"value\": {\"fixedAmount\": {\"amount\": 10}},\n \"targets\": [{\"productVariant\": {\"id\": \"gid://shopify/ProductVariant/12345\"}}]\n }],\n \"discountApplicationStrategy\": \"FIRST\"\n}" } ] } }, }, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby 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 } } } } QUERY variables = { "automaticAppDiscount": { "title": "Product discount $10 off", "functionId": "677bc937-7dce-4fe4-8e8d-076c391d3e53", "startsAt": "2025-01-01T00:00:00Z", "endsAt": "2025-12-31T23:59:59Z", "metafields": [ { "namespace": "default", "key": "function-configuration", "type": "json", "value": "{\n \"discounts\": [{\n \"value\": {\"fixedAmount\": {\"amount\": 10}},\n \"targets\": [{\"productVariant\": {\"id\": \"gid://shopify/ProductVariant/12345\"}}]\n }],\n \"discountApplicationStrategy\": \"FIRST\"\n}" } ] } } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript 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 } } } }`, "variables": { "automaticAppDiscount": { "title": "Product discount $10 off", "functionId": "677bc937-7dce-4fe4-8e8d-076c391d3e53", "startsAt": "2025-01-01T00:00:00Z", "endsAt": "2025-12-31T23:59:59Z", "metafields": [ { "namespace": "default", "key": "function-configuration", "type": "json", "value": "{\n \"discounts\": [{\n \"value\": {\"fixedAmount\": {\"amount\": 10}},\n \"targets\": [{\"productVariant\": {\"id\": \"gid://shopify/ProductVariant/12345\"}}]\n }],\n \"discountApplicationStrategy\": \"FIRST\"\n}" } ] } }, }, }); ``` #### Response ```json { "discountAutomaticAppCreate": { "userErrors": [], "automaticAppDiscount": { "discountId": "gid://shopify/DiscountAutomaticNode/1057856654", "title": "Product discount $10 off", "startsAt": "2025-01-01T00:00:00Z", "endsAt": "2025-12-31T23:59:59Z", "status": "ACTIVE", "appDiscountType": { "appKey": "shopify-web", "functionId": "677bc937-7dce-4fe4-8e8d-076c391d3e53" } } } } ``` * ### discountAutomaticAppCreate reference [Open in GraphiQL](http://localhost:3457/graphiql?query=mutation%20discountAutomaticAppCreate\(%24automaticAppDiscount%3A%20DiscountAutomaticAppInput!\)%20%7B%0A%20%20discountAutomaticAppCreate\(automaticAppDiscount%3A%20%24automaticAppDiscount\)%20%7B%0A%20%20%20%20userErrors%20%7B%0A%20%20%20%20%20%20field%0A%20%20%20%20%20%20message%0A%20%20%20%20%7D%0A%20%20%20%20automaticAppDiscount%20%7B%0A%20%20%20%20%20%20discountId%0A%20%20%20%20%20%20title%0A%20%20%20%20%20%20startsAt%0A%20%20%20%20%20%20endsAt%0A%20%20%20%20%20%20status%0A%20%20%20%20%20%20appDiscountType%20%7B%0A%20%20%20%20%20%20%20%20appKey%0A%20%20%20%20%20%20%20%20functionId%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20combinesWith%20%7B%0A%20%20%20%20%20%20%20%20orderDiscounts%0A%20%20%20%20%20%20%20%20productDiscounts%0A%20%20%20%20%20%20%20%20shippingDiscounts%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D\&variables=%7B%0A%20%20%22automaticAppDiscount%22%3A%20%7B%0A%20%20%20%20%22title%22%3A%20%22%245%20discount%22%2C%0A%20%20%20%20%22functionId%22%3A%20%22a3cdef66-d84a-4254-9216-b6dd723005ad%22%2C%0A%20%20%20%20%22startsAt%22%3A%20%222025-02-02T17%3A09%3A21Z%22%2C%0A%20%20%20%20%22endsAt%22%3A%20%222025-02-02T17%3A09%3A21Z%22%2C%0A%20%20%20%20%22combinesWith%22%3A%20%7B%0A%20%20%20%20%20%20%22orderDiscounts%22%3A%20false%2C%0A%20%20%20%20%20%20%22productDiscounts%22%3A%20false%2C%0A%20%20%20%20%20%20%22shippingDiscounts%22%3A%20false%0A%20%20%20%20%7D%2C%0A%20%20%20%20%22metafields%22%3A%20%5B%0A%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22namespace%22%3A%20%22default%22%2C%0A%20%20%20%20%20%20%20%20%22key%22%3A%20%22function-configuration%22%2C%0A%20%20%20%20%20%20%20%20%22type%22%3A%20%22json%22%2C%0A%20%20%20%20%20%20%20%20%22value%22%3A%20%22%7B%5Cn%20%20%5C%22discounts%5C%22%3A%20%5B%7B%5Cn%20%20%20%20%5C%22value%5C%22%3A%20%7B%5C%22fixedAmount%5C%22%3A%20%7B%5C%22amount%5C%22%3A%205%7D%7D%2C%5Cn%20%20%20%20%5C%22targets%5C%22%3A%20%5B%7B%5C%22orderSubtotal%5C%22%3A%20%7B%5C%22excludedVariantIds%5C%22%3A%20%5B%5D%7D%7D%5D%5Cn%20%20%7D%5D%2C%5Cn%20%20%5C%22discountApplicationStrategy%5C%22%3A%20%5C%22FIRST%5C%22%5Cn%7D%22%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%5D%0A%20%20%7D%0A%7D) ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { 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": "a3cdef66-d84a-4254-9216-b6dd723005ad", "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 json = await response.json(); return json.data; } ``` ## Input variables JSON ```json { "automaticAppDiscount": { "title": "$5 discount", "functionId": "a3cdef66-d84a-4254-9216-b6dd723005ad", "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 JSON ```json { "discountAutomaticAppCreate": { "userErrors": [], "automaticAppDiscount": { "discountId": "gid://shopify/DiscountAutomaticNode/1057856655", "title": "$5 discount", "startsAt": "2025-02-02T17:09:21Z", "endsAt": "2025-02-02T17:09:21Z", "status": "EXPIRED", "appDiscountType": { "appKey": "shopify-web", "functionId": "13d358d1-2a5b-4a39-a6f9-8f53394e440d" }, "combinesWith": { "orderDiscounts": false, "productDiscounts": false, "shippingDiscounts": false } } } } ```