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 discountAutomaticBasicCreate($automaticBasicDiscount: DiscountAutomaticBasicInput!) { discountAutomaticBasicCreate(automaticBasicDiscount: $automaticBasicDiscount) { automaticDiscountNode { id automaticDiscount { ... on DiscountAutomaticBasic { startsAt endsAt minimumRequirement { ... on DiscountMinimumSubtotal { greaterThanOrEqualToSubtotal { amount currencyCode } } } customerGets { value { ... on DiscountAmount { amount { amount currencyCode } appliesOnEachItem } } items { ... on AllDiscountItems { allItems } } } } } } userErrors { field code message } } }\",\n \"variables\": {\n \"automaticBasicDiscount\": {\n \"title\": \"$50 off all orders over $200 during the summer of 2022\",\n \"startsAt\": \"2022-06-21T00:00:00Z\",\n \"endsAt\": \"2022-09-21T00:00:00Z\",\n \"minimumRequirement\": {\n \"subtotal\": {\n \"greaterThanOrEqualToSubtotal\": 200\n }\n },\n \"customerGets\": {\n \"value\": {\n \"discountAmount\": {\n \"amount\": 50,\n \"appliesOnEachItem\": false\n }\n },\n \"items\": {\n \"all\": true\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 discountAutomaticBasicCreate($automaticBasicDiscount: DiscountAutomaticBasicInput!) {\n discountAutomaticBasicCreate(automaticBasicDiscount: $automaticBasicDiscount) {\n automaticDiscountNode {\n id\n automaticDiscount {\n ... on DiscountAutomaticBasic {\n startsAt\n endsAt\n minimumRequirement {\n ... on DiscountMinimumSubtotal {\n greaterThanOrEqualToSubtotal {\n amount\n currencyCode\n }\n }\n }\n customerGets {\n value {\n ... on DiscountAmount {\n amount {\n amount\n currencyCode\n }\n appliesOnEachItem\n }\n }\n items {\n ... on AllDiscountItems {\n allItems\n }\n }\n }\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n }`,\n \"variables\": {\n \"automaticBasicDiscount\": {\n \"title\": \"$50 off all orders over $200 during the summer of 2022\",\n \"startsAt\": \"2022-06-21T00:00:00Z\",\n \"endsAt\": \"2022-09-21T00:00:00Z\",\n \"minimumRequirement\": {\n \"subtotal\": {\n \"greaterThanOrEqualToSubtotal\": 200\n }\n },\n \"customerGets\": {\n \"value\": {\n \"discountAmount\": {\n \"amount\": 50,\n \"appliesOnEachItem\": false\n }\n },\n \"items\": {\n \"all\": true\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 discountAutomaticBasicCreate($automaticBasicDiscount: DiscountAutomaticBasicInput!) {\n discountAutomaticBasicCreate(automaticBasicDiscount: $automaticBasicDiscount) {\n automaticDiscountNode {\n id\n automaticDiscount {\n ... on DiscountAutomaticBasic {\n startsAt\n endsAt\n minimumRequirement {\n ... on DiscountMinimumSubtotal {\n greaterThanOrEqualToSubtotal {\n amount\n currencyCode\n }\n }\n }\n customerGets {\n value {\n ... on DiscountAmount {\n amount {\n amount\n currencyCode\n }\n appliesOnEachItem\n }\n }\n items {\n ... on AllDiscountItems {\n allItems\n }\n }\n }\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"automaticBasicDiscount\": {\n \"title\": \"$50 off all orders over $200 during the summer of 2022\",\n \"startsAt\": \"2022-06-21T00:00:00Z\",\n \"endsAt\": \"2022-09-21T00:00:00Z\",\n \"minimumRequirement\": {\n \"subtotal\": {\n \"greaterThanOrEqualToSubtotal\": 200\n }\n },\n \"customerGets\": {\n \"value\": {\n \"discountAmount\": {\n \"amount\": 50,\n \"appliesOnEachItem\": false\n }\n },\n \"items\": {\n \"all\": true\n }\n }\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 = <<<QUERY\n mutation discountAutomaticBasicCreate($automaticBasicDiscount: DiscountAutomaticBasicInput!) {\n discountAutomaticBasicCreate(automaticBasicDiscount: $automaticBasicDiscount) {\n automaticDiscountNode {\n id\n automaticDiscount {\n ... on DiscountAutomaticBasic {\n startsAt\n endsAt\n minimumRequirement {\n ... on DiscountMinimumSubtotal {\n greaterThanOrEqualToSubtotal {\n amount\n currencyCode\n }\n }\n }\n customerGets {\n value {\n ... on DiscountAmount {\n amount {\n amount\n currencyCode\n }\n appliesOnEachItem\n }\n }\n items {\n ... on AllDiscountItems {\n allItems\n }\n }\n }\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n }\nQUERY;\n\n$variables = [\n \"automaticBasicDiscount\" => [\n \"title\" => \"$50 off all orders over $200 during the summer of 2022\",\n \"startsAt\" => \"2022-06-21T00:00:00Z\",\n \"endsAt\" => \"2022-09-21T00:00:00Z\",\n \"minimumRequirement\" => [\n \"subtotal\" => [\n \"greaterThanOrEqualToSubtotal\" => 200,\n ],\n ],\n \"customerGets\" => [\n \"value\" => [\n \"discountAmount\" => [\n \"amount\" => 50,\n \"appliesOnEachItem\" => false,\n ],\n ],\n \"items\" => [\n \"all\" => true,\n ],\n ],\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 discountAutomaticBasicCreate($automaticBasicDiscount: DiscountAutomaticBasicInput!) {\n discountAutomaticBasicCreate(automaticBasicDiscount: $automaticBasicDiscount) {\n automaticDiscountNode {\n id\n automaticDiscount {\n ... on DiscountAutomaticBasic {\n startsAt\n endsAt\n minimumRequirement {\n ... on DiscountMinimumSubtotal {\n greaterThanOrEqualToSubtotal {\n amount\n currencyCode\n }\n }\n }\n customerGets {\n value {\n ... on DiscountAmount {\n amount {\n amount\n currencyCode\n }\n appliesOnEachItem\n }\n }\n items {\n ... on AllDiscountItems {\n allItems\n }\n }\n }\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n }`,\n {\n variables: {\n \"automaticBasicDiscount\": {\n \"title\": \"$50 off all orders over $200 during the summer of 2022\",\n \"startsAt\": \"2022-06-21T00:00:00Z\",\n \"endsAt\": \"2022-09-21T00:00:00Z\",\n \"minimumRequirement\": {\n \"subtotal\": {\n \"greaterThanOrEqualToSubtotal\": 200\n }\n },\n \"customerGets\": {\n \"value\": {\n \"discountAmount\": {\n \"amount\": 50,\n \"appliesOnEachItem\": false\n }\n },\n \"items\": {\n \"all\": true\n }\n }\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation discountAutomaticBasicCreate($automaticBasicDiscount: DiscountAutomaticBasicInput!) {\n discountAutomaticBasicCreate(automaticBasicDiscount: $automaticBasicDiscount) {\n automaticDiscountNode {\n id\n automaticDiscount {\n ... on DiscountAutomaticBasic {\n startsAt\n endsAt\n minimumRequirement {\n ... on DiscountMinimumSubtotal {\n greaterThanOrEqualToSubtotal {\n amount\n currencyCode\n }\n }\n }\n customerGets {\n value {\n ... on DiscountAmount {\n amount {\n amount\n currencyCode\n }\n appliesOnEachItem\n }\n }\n items {\n ... on AllDiscountItems {\n allItems\n }\n }\n }\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n}"
input: { "automaticBasicDiscount": { "title": "$50 off all orders over $200 during the summer of 2022", "startsAt": "2022-06-21T00:00:00Z", "endsAt": "2022-09-21T00:00:00Z", "minimumRequirement": { "subtotal": { "greaterThanOrEqualToSubtotal": 200 } }, "customerGets": { "value": { "discountAmount": { "amount": 50, "appliesOnEachItem": false } }, "items": { "all": true } } } }
response: { "data": { "discountAutomaticBasicCreate": { "automaticDiscountNode": { "id": "gid://shopify/DiscountAutomaticNode/1057371197", "automaticDiscount": { "startsAt": "2022-06-21T00:00:00Z", "endsAt": "2022-09-21T00:00:00Z", "minimumRequirement": { "greaterThanOrEqualToSubtotal": { "amount": "200.0", "currencyCode": "USD" } }, "customerGets": { "value": { "amount": { "amount": "50.0", "currencyCode": "USD" }, "appliesOnEachItem": false }, "items": { "allItems": true } } } }, "userErrors": [] } } }