# discountAutomaticAppCreate - admin-graphql - MUTATION Version: 2025-01 ## 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. ### Access Scopes `write_discounts` access scope. ## Arguments * [automaticAppDiscount](/docs/api/admin-graphql/2025-01/input-objects/DiscountAutomaticAppInput): DiscountAutomaticAppInput! - The input data used to create the automatic discount. ## Returns * [automaticAppDiscount](/docs/api/admin-graphql/2025-01/objects/DiscountAutomaticApp): DiscountAutomaticApp The automatic discount that the app manages. * [userErrors](/docs/api/admin-graphql/2025-01/objects/DiscountUserError): DiscountUserError! The list of errors that occurred from executing the mutation. ## Examples ### Create a non-combinable automatic discount that's managed by an app Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) { discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) { userErrors { field message } automaticAppDiscount { discountId title startsAt endsAt status appDiscountType { appKey functionId } combinesWith { orderDiscounts productDiscounts shippingDiscounts } } } }\",\n \"variables\": {\n \"automaticAppDiscount\": {\n \"title\": \"$5 discount\",\n \"functionId\": \"de7a6b74-5ac7-432f-8d5b-98dd14fb8af5\",\n \"startsAt\": \"2025-02-02T17:09:21Z\",\n \"endsAt\": \"2025-02-02T17:09:21Z\",\n \"combinesWith\": {\n \"orderDiscounts\": false,\n \"productDiscounts\": false,\n \"shippingDiscounts\": false\n },\n \"metafields\": [\n {\n \"namespace\": \"default\",\n \"key\": \"function-configuration\",\n \"type\": \"json\",\n \"value\": \"{\\n \\\"discounts\\\": [{\\n \\\"value\\\": {\\\"fixedAmount\\\": {\\\"amount\\\": 5}},\\n \\\"targets\\\": [{\\\"orderSubtotal\\\": {\\\"excludedVariantIds\\\": []}}]\\n }],\\n \\\"discountApplicationStrategy\\\": \\\"FIRST\\\"\\n}\"\n }\n ]\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) {\n discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) {\n userErrors {\n field\n message\n }\n automaticAppDiscount {\n discountId\n title\n startsAt\n endsAt\n status\n appDiscountType {\n appKey\n functionId\n }\n combinesWith {\n orderDiscounts\n productDiscounts\n shippingDiscounts\n }\n }\n }\n }`,\n \"variables\": {\n \"automaticAppDiscount\": {\n \"title\": \"$5 discount\",\n \"functionId\": \"de7a6b74-5ac7-432f-8d5b-98dd14fb8af5\",\n \"startsAt\": \"2025-02-02T17:09:21Z\",\n \"endsAt\": \"2025-02-02T17:09:21Z\",\n \"combinesWith\": {\n \"orderDiscounts\": false,\n \"productDiscounts\": false,\n \"shippingDiscounts\": false\n },\n \"metafields\": [\n {\n \"namespace\": \"default\",\n \"key\": \"function-configuration\",\n \"type\": \"json\",\n \"value\": \"{\\n \\\"discounts\\\": [{\\n \\\"value\\\": {\\\"fixedAmount\\\": {\\\"amount\\\": 5}},\\n \\\"targets\\\": [{\\\"orderSubtotal\\\": {\\\"excludedVariantIds\\\": []}}]\\n }],\\n \\\"discountApplicationStrategy\\\": \\\"FIRST\\\"\\n}\"\n }\n ]\n }\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) {\n discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) {\n userErrors {\n field\n message\n }\n automaticAppDiscount {\n discountId\n title\n startsAt\n endsAt\n status\n appDiscountType {\n appKey\n functionId\n }\n combinesWith {\n orderDiscounts\n productDiscounts\n shippingDiscounts\n }\n }\n }\n }\nQUERY\n\nvariables = {\n \"automaticAppDiscount\": {\n \"title\": \"$5 discount\",\n \"functionId\": \"de7a6b74-5ac7-432f-8d5b-98dd14fb8af5\",\n \"startsAt\": \"2025-02-02T17:09:21Z\",\n \"endsAt\": \"2025-02-02T17:09:21Z\",\n \"combinesWith\": {\n \"orderDiscounts\": false,\n \"productDiscounts\": false,\n \"shippingDiscounts\": false\n },\n \"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}\"}]\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) {\n discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) {\n userErrors {\n field\n message\n }\n automaticAppDiscount {\n discountId\n title\n startsAt\n endsAt\n status\n appDiscountType {\n appKey\n functionId\n }\n combinesWith {\n orderDiscounts\n productDiscounts\n shippingDiscounts\n }\n }\n }\n }`,\n {\n variables: {\n \"automaticAppDiscount\": {\n \"title\": \"$5 discount\",\n \"functionId\": \"de7a6b74-5ac7-432f-8d5b-98dd14fb8af5\",\n \"startsAt\": \"2025-02-02T17:09:21Z\",\n \"endsAt\": \"2025-02-02T17:09:21Z\",\n \"combinesWith\": {\n \"orderDiscounts\": false,\n \"productDiscounts\": false,\n \"shippingDiscounts\": false\n },\n \"metafields\": [\n {\n \"namespace\": \"default\",\n \"key\": \"function-configuration\",\n \"type\": \"json\",\n \"value\": \"{\\n \\\"discounts\\\": [{\\n \\\"value\\\": {\\\"fixedAmount\\\": {\\\"amount\\\": 5}},\\n \\\"targets\\\": [{\\\"orderSubtotal\\\": {\\\"excludedVariantIds\\\": []}}]\\n }],\\n \\\"discountApplicationStrategy\\\": \\\"FIRST\\\"\\n}\"\n }\n ]\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) {\n discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) {\n userErrors {\n field\n message\n }\n automaticAppDiscount {\n discountId\n title\n startsAt\n endsAt\n status\n appDiscountType {\n appKey\n functionId\n }\n combinesWith {\n orderDiscounts\n productDiscounts\n shippingDiscounts\n }\n }\n }\n}" #### Graphql Input { "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}" } ] } } #### Graphql Response { "data": { "discountAutomaticAppCreate": { "userErrors": [], "automaticAppDiscount": { "discountId": "gid://shopify/DiscountAutomaticNode/1057371215", "title": "$5 discount", "startsAt": "2025-02-02T17:09:21Z", "endsAt": "2025-02-02T17:09:21Z", "status": "SCHEDULED", "appDiscountType": { "appKey": "shopify-web", "functionId": "f14c0c43-7660-44bf-9c5e-78c2ad0defe7" }, "combinesWith": { "orderDiscounts": false, "productDiscounts": false, "shippingDiscounts": false } } } } } ### Create an automatic product discount that's managed by an app Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) { discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) { userErrors { field message } automaticAppDiscount { discountId title startsAt endsAt status appDiscountType { appKey functionId } } } }\",\n \"variables\": {\n \"automaticAppDiscount\": {\n \"title\": \"Product discount $10 off\",\n \"functionId\": \"0490cd8a-7bba-48f4-8987-0240b0a2ddbe\",\n \"startsAt\": \"2025-01-01T00:00:00Z\",\n \"endsAt\": \"2025-12-31T23:59:59Z\",\n \"metafields\": [\n {\n \"namespace\": \"default\",\n \"key\": \"function-configuration\",\n \"type\": \"json\",\n \"value\": \"{\\n \\\"discounts\\\": [{\\n \\\"value\\\": {\\\"fixedAmount\\\": {\\\"amount\\\": 10}},\\n \\\"targets\\\": [{\\\"productVariant\\\": {\\\"id\\\": \\\"gid://shopify/ProductVariant/12345\\\"}}]\\n }],\\n \\\"discountApplicationStrategy\\\": \\\"FIRST\\\"\\n}\"\n }\n ]\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) {\n discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) {\n userErrors {\n field\n message\n }\n automaticAppDiscount {\n discountId\n title\n startsAt\n endsAt\n status\n appDiscountType {\n appKey\n functionId\n }\n }\n }\n }`,\n \"variables\": {\n \"automaticAppDiscount\": {\n \"title\": \"Product discount $10 off\",\n \"functionId\": \"0490cd8a-7bba-48f4-8987-0240b0a2ddbe\",\n \"startsAt\": \"2025-01-01T00:00:00Z\",\n \"endsAt\": \"2025-12-31T23:59:59Z\",\n \"metafields\": [\n {\n \"namespace\": \"default\",\n \"key\": \"function-configuration\",\n \"type\": \"json\",\n \"value\": \"{\\n \\\"discounts\\\": [{\\n \\\"value\\\": {\\\"fixedAmount\\\": {\\\"amount\\\": 10}},\\n \\\"targets\\\": [{\\\"productVariant\\\": {\\\"id\\\": \\\"gid://shopify/ProductVariant/12345\\\"}}]\\n }],\\n \\\"discountApplicationStrategy\\\": \\\"FIRST\\\"\\n}\"\n }\n ]\n }\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) {\n discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) {\n userErrors {\n field\n message\n }\n automaticAppDiscount {\n discountId\n title\n startsAt\n endsAt\n status\n appDiscountType {\n appKey\n functionId\n }\n }\n }\n }\nQUERY\n\nvariables = {\n \"automaticAppDiscount\": {\n \"title\": \"Product discount $10 off\",\n \"functionId\": \"0490cd8a-7bba-48f4-8987-0240b0a2ddbe\",\n \"startsAt\": \"2025-01-01T00:00:00Z\",\n \"endsAt\": \"2025-12-31T23:59:59Z\",\n \"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}\"}]\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) {\n discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) {\n userErrors {\n field\n message\n }\n automaticAppDiscount {\n discountId\n title\n startsAt\n endsAt\n status\n appDiscountType {\n appKey\n functionId\n }\n }\n }\n }`,\n {\n variables: {\n \"automaticAppDiscount\": {\n \"title\": \"Product discount $10 off\",\n \"functionId\": \"0490cd8a-7bba-48f4-8987-0240b0a2ddbe\",\n \"startsAt\": \"2025-01-01T00:00:00Z\",\n \"endsAt\": \"2025-12-31T23:59:59Z\",\n \"metafields\": [\n {\n \"namespace\": \"default\",\n \"key\": \"function-configuration\",\n \"type\": \"json\",\n \"value\": \"{\\n \\\"discounts\\\": [{\\n \\\"value\\\": {\\\"fixedAmount\\\": {\\\"amount\\\": 10}},\\n \\\"targets\\\": [{\\\"productVariant\\\": {\\\"id\\\": \\\"gid://shopify/ProductVariant/12345\\\"}}]\\n }],\\n \\\"discountApplicationStrategy\\\": \\\"FIRST\\\"\\n}\"\n }\n ]\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) {\n discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) {\n userErrors {\n field\n message\n }\n automaticAppDiscount {\n discountId\n title\n startsAt\n endsAt\n status\n appDiscountType {\n appKey\n functionId\n }\n }\n }\n}" #### Graphql Input { "automaticAppDiscount": { "title": "Product discount $10 off", "functionId": "0490cd8a-7bba-48f4-8987-0240b0a2ddbe", "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}" } ] } } #### Graphql Response { "data": { "discountAutomaticAppCreate": { "userErrors": [], "automaticAppDiscount": { "discountId": "gid://shopify/DiscountAutomaticNode/1057371216", "title": "Product discount $10 off", "startsAt": "2025-01-01T00:00:00Z", "endsAt": "2025-12-31T23:59:59Z", "status": "ACTIVE", "appDiscountType": { "appKey": "shopify-web", "functionId": "0490cd8a-7bba-48f4-8987-0240b0a2ddbe" } } } } }