Version: 2024-10
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" 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" 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" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<[\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" 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" 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}"
input: { "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 } } }