discount Automatic App Createmutation
mutation
2024-10latest
Requires write
access scope.
Creates an app discount.
Arguments
The input data used to create the app discount.
Was this section helpful?
DiscountAutomaticAppCreatePayload returns
The created app discount.
The list of errors that occurred from executing the mutation.
Was this section helpful?
Code examples for MUTATION: discountAutomaticAppCreate
Query Reference for MUTATION: discountAutomaticAppCreate
"mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) {\n discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) {\n automaticAppDiscount {\n # DiscountAutomaticApp fields\n }\n userErrors {\n field\n message\n }\n }\n}"
Input Reference for MUTATION: discountAutomaticAppCreate
"{\n \"automaticAppDiscount\": {\n \"appliesOnSubscription\": true,\n \"combinesWith\": {\n \"orderDiscounts\": true,\n \"productDiscounts\": true,\n \"shippingDiscounts\": true\n },\n \"endsAt\": \"2019-09-07T15:50:00Z\",\n \"functionId\": \"<your-functionId>\",\n \"metafields\": [\n {\n \"description\": \"<your-description>\",\n \"id\": \"gid://shopify/<objectName>/10079785100\",\n \"key\": \"<your-key>\",\n \"namespace\": \"<your-namespace>\",\n \"type\": \"<your-type>\",\n \"value\": \"<your-value>\"\n }\n ],\n \"recurringCycleLimit\": 1,\n \"startsAt\": \"2019-09-07T15:50:00Z\",\n \"title\": \"<your-title>\"\n }\n}"
Schema Reference for MUTATION: discountAutomaticAppCreate
"input DiscountAutomaticAppInput {\n appliesOnSubscription: Boolean\n combinesWith: DiscountCombinesWithInput\n endsAt: DateTime\n functionId: String\n metafields: [MetafieldInput!]\n recurringCycleLimit: Int\n startsAt: DateTime\n title: String\n}\n\ninput DiscountCombinesWithInput {\n orderDiscounts: Boolean\n productDiscounts: Boolean\n shippingDiscounts: Boolean\n}\n\ninput MetafieldInput {\n description: String\n id: ID\n key: String\n namespace: String\n type: String\n value: String\n}\n"
Display Examples for MUTATION: discountAutomaticAppCreate
[ { "example": { "type_name": "discountautomaticappcreate", "title": "Create an app automatic discount", "description": "This endpoint creates an app automatic discount. This is different from basic code discount creation\nas this endpoint creates a discount with the function id as input and\nthe function id is used to find the function to run. Depending on the function, we can create\norder, product or shipping discounts.\n", "query_string": "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}", "variables": { "automaticAppDiscount": { "title": "Take 5$ from discount", "functionId": "a28a1b8c-584c-40cd-a822-f53c8d01bb5f", "combinesWith": { "orderDiscounts": true, "productDiscounts": true, "shippingDiscounts": true }, "startsAt": "2021-02-02T17:09:21Z", "endsAt": "2022-02-02T17:09:21Z", "metafields": [ { "namespace": "default", "key": "function-configuration", "type": "json", "value": "{\"discounts\":[{\"value\":{\"fixedAmount\":{\"amount\":5}},\"targets\":\n [{\"orderSubtotal\":{\"excludedVariantIds\":[]}}]}],\"discountApplicationStrategy\":\"FIRST\"}" } ] } }, "response": { "data": { "discountAutomaticAppCreate": { "userErrors": [ { "field": [ "automaticAppDiscount" ], "message": "is not supported with these combines_with settings" } ], "automaticAppDiscount": null } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/pricing/test/unit/graph_api/admin/mutations/discount_automatic_app_create_test.rb", "curl_example": "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/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\": \"Take 5$ from discount\",\n \"functionId\": \"a28a1b8c-584c-40cd-a822-f53c8d01bb5f\",\n \"combinesWith\": {\n \"orderDiscounts\": true,\n \"productDiscounts\": true,\n \"shippingDiscounts\": true\n },\n \"startsAt\": \"2021-02-02T17:09:21Z\",\n \"endsAt\": \"2022-02-02T17:09:21Z\",\n \"metafields\": [\n {\n \"namespace\": \"default\",\n \"key\": \"function-configuration\",\n \"type\": \"json\",\n \"value\": \"{\\\"discounts\\\":[{\\\"value\\\":{\\\"fixedAmount\\\":{\\\"amount\\\":5}},\\\"targets\\\":\\n [{\\\"orderSubtotal\\\":{\\\"excludedVariantIds\\\":[]}}]}],\\\"discountApplicationStrategy\\\":\\\"FIRST\\\"}\"\n }\n ]\n }\n }\n}'\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\": \"Take 5$ from discount\",\n \"functionId\": \"a28a1b8c-584c-40cd-a822-f53c8d01bb5f\",\n \"combinesWith\": {\n \"orderDiscounts\": true,\n \"productDiscounts\": true,\n \"shippingDiscounts\": true\n },\n \"startsAt\": \"2021-02-02T17:09:21Z\",\n \"endsAt\": \"2022-02-02T17:09:21Z\",\n \"metafields\": [\n {\n \"namespace\": \"default\",\n \"key\": \"function-configuration\",\n \"type\": \"json\",\n \"value\": \"{\\\"discounts\\\":[{\\\"value\\\":{\\\"fixedAmount\\\":{\\\"amount\\\":5}},\\\"targets\\\":\\n [{\\\"orderSubtotal\\\":{\\\"excludedVariantIds\\\":[]}}]}],\\\"discountApplicationStrategy\\\":\\\"FIRST\\\"}\"\n }\n ]\n }\n },\n },\n);\n\nconst data = await response.json();\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\": \"Take 5$ from discount\",\n \"functionId\": \"a28a1b8c-584c-40cd-a822-f53c8d01bb5f\",\n \"combinesWith\": {\n \"orderDiscounts\": true,\n \"productDiscounts\": true,\n \"shippingDiscounts\": true\n },\n \"startsAt\": \"2021-02-02T17:09:21Z\",\n \"endsAt\": \"2022-02-02T17:09:21Z\",\n \"metafields\": [{\"namespace\"=>\"default\", \"key\"=>\"function-configuration\", \"type\"=>\"json\", \"value\"=>\"{\\\"discounts\\\":[{\\\"value\\\":{\\\"fixedAmount\\\":{\\\"amount\\\":5}},\\\"targets\\\":\\n [{\\\"orderSubtotal\\\":{\\\"excludedVariantIds\\\":[]}}]}],\\\"discountApplicationStrategy\\\":\\\"FIRST\\\"}\"}]\n }\n}\n\nresponse = client.query(query: query, variables: variables)\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\": \"Take 5$ from discount\",\n \"functionId\": \"a28a1b8c-584c-40cd-a822-f53c8d01bb5f\",\n \"combinesWith\": {\n \"orderDiscounts\": true,\n \"productDiscounts\": true,\n \"shippingDiscounts\": true\n },\n \"startsAt\": \"2021-02-02T17:09:21Z\",\n \"endsAt\": \"2022-02-02T17:09:21Z\",\n \"metafields\": [\n {\n \"namespace\": \"default\",\n \"key\": \"function-configuration\",\n \"type\": \"json\",\n \"value\": \"{\\\"discounts\\\":[{\\\"value\\\":{\\\"fixedAmount\\\":{\\\"amount\\\":5}},\\\"targets\\\":\\n [{\\\"orderSubtotal\\\":{\\\"excludedVariantIds\\\":[]}}]}],\\\"discountApplicationStrategy\\\":\\\"FIRST\\\"}\"\n }\n ]\n }\n },\n },\n});\n", "php_example": "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<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\n$variables = [\n \"automaticAppDiscount\" => [\n \"title\" => \"Take 5$ from discount\",\n \"functionId\" => \"a28a1b8c-584c-40cd-a822-f53c8d01bb5f\",\n \"combinesWith\" => [\n \"orderDiscounts\" => true,\n \"productDiscounts\" => true,\n \"shippingDiscounts\" => true,\n ],\n \"startsAt\" => \"2021-02-02T17:09:21Z\",\n \"endsAt\" => \"2022-02-02T17:09:21Z\",\n \"metafields\" => [{\"namespace\"=>\"default\", \"key\"=>\"function-configuration\", \"type\"=>\"json\", \"value\"=>\"{\\\"discounts\\\":[{\\\"value\\\":{\\\"fixedAmount\\\":{\\\"amount\\\":5}},\\\"targets\\\":\\n [{\\\"orderSubtotal\\\":{\\\"excludedVariantIds\\\":[]}}]}],\\\"discountApplicationStrategy\\\":\\\"FIRST\\\"}\"}],\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "automaticAppDiscount", "description": "The input data used to create the app discount.", "type": { "kind": "INPUT_OBJECT", "name": "DiscountAutomaticAppInput", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "DiscountAutomaticAppInput!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "automaticAppDiscount", "argValue": " {\"title\":\"Take 5$ from discount\",\"functionId\":\"a28a1b8c-584c-40cd-a822-f53c8d01bb5f\",\"combinesWith\":{\"orderDiscounts\":true,\"productDiscounts\":true,\"shippingDiscounts\":true},\"startsAt\":\"2021-02-02T17:09:21Z\",\"endsAt\":\"2022-02-02T17:09:21Z\",\"metafields\":[{\"namespace\":\"default\",\"key\":\"function-configuration\",\"type\":\"json\",\"value\":\"{\\\"discounts\\\":[{\\\"value\\\":{\\\"fixedAmount\\\":{\\\"amount\\\":5}},\\\"targets\\\":\\n [{\\\"orderSubtotal\\\":{\\\"excludedVariantIds\\\":[]}}]}],\\\"discountApplicationStrategy\\\":\\\"FIRST\\\"}\"}]}", "typeKind": "MUTATION" } ] } ]