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 discountCodeFreeShippingCreate($freeShippingCodeDiscount: DiscountCodeFreeShippingInput!) { discountCodeFreeShippingCreate(freeShippingCodeDiscount: $freeShippingCodeDiscount) { codeDiscountNode { id codeDiscount { ... on DiscountCodeFreeShipping { title startsAt endsAt maximumShippingPrice { amount } customerSelection { ... on DiscountCustomerAll { allCustomers } } destinationSelection { ... on DiscountCountryAll { allCountries } } minimumRequirement { ... on DiscountMinimumSubtotal { greaterThanOrEqualToSubtotal { amount } } } codes(first: 2) { nodes { code } } } } } userErrors { field code message } } }\",\n \"variables\": {\n \"freeShippingCodeDiscount\": {\n \"startsAt\": \"2022-06-22T21:12:07.000Z\",\n \"appliesOncePerCustomer\": false,\n \"title\": \"FreeShipping\",\n \"code\": \"FreeShipping\",\n \"minimumRequirement\": {\n \"subtotal\": {\n \"greaterThanOrEqualToSubtotal\": 20.0\n }\n },\n \"customerSelection\": {\n \"all\": true\n },\n \"destination\": {\n \"all\": true\n }\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation discountCodeFreeShippingCreate($freeShippingCodeDiscount: DiscountCodeFreeShippingInput!) {\n discountCodeFreeShippingCreate(freeShippingCodeDiscount: $freeShippingCodeDiscount) {\n codeDiscountNode {\n id\n codeDiscount {\n ... on DiscountCodeFreeShipping {\n title\n startsAt\n endsAt\n maximumShippingPrice {\n amount\n }\n customerSelection {\n ... on DiscountCustomerAll {\n allCustomers\n }\n }\n destinationSelection {\n ... on DiscountCountryAll {\n allCountries\n }\n }\n minimumRequirement {\n ... on DiscountMinimumSubtotal {\n greaterThanOrEqualToSubtotal {\n amount\n }\n }\n }\n codes(first: 2) {\n nodes {\n code\n }\n }\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n }`,\n \"variables\": {\n \"freeShippingCodeDiscount\": {\n \"startsAt\": \"2022-06-22T21:12:07.000Z\",\n \"appliesOncePerCustomer\": false,\n \"title\": \"FreeShipping\",\n \"code\": \"FreeShipping\",\n \"minimumRequirement\": {\n \"subtotal\": {\n \"greaterThanOrEqualToSubtotal\": 20.0\n }\n },\n \"customerSelection\": {\n \"all\": true\n },\n \"destination\": {\n \"all\": true\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 discountCodeFreeShippingCreate($freeShippingCodeDiscount: DiscountCodeFreeShippingInput!) {\n discountCodeFreeShippingCreate(freeShippingCodeDiscount: $freeShippingCodeDiscount) {\n codeDiscountNode {\n id\n codeDiscount {\n ... on DiscountCodeFreeShipping {\n title\n startsAt\n endsAt\n maximumShippingPrice {\n amount\n }\n customerSelection {\n ... on DiscountCustomerAll {\n allCustomers\n }\n }\n destinationSelection {\n ... on DiscountCountryAll {\n allCountries\n }\n }\n minimumRequirement {\n ... on DiscountMinimumSubtotal {\n greaterThanOrEqualToSubtotal {\n amount\n }\n }\n }\n codes(first: 2) {\n nodes {\n code\n }\n }\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"freeShippingCodeDiscount\": {\n \"startsAt\": \"2022-06-22T21:12:07.000Z\",\n \"appliesOncePerCustomer\": false,\n \"title\": \"FreeShipping\",\n \"code\": \"FreeShipping\",\n \"minimumRequirement\": {\n \"subtotal\": {\n \"greaterThanOrEqualToSubtotal\": 20.0\n }\n },\n \"customerSelection\": {\n \"all\": true\n },\n \"destination\": {\n \"all\": true\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 = <<[\n \"startsAt\" => \"2022-06-22T21:12:07.000Z\",\n \"appliesOncePerCustomer\" => false,\n \"title\" => \"FreeShipping\",\n \"code\" => \"FreeShipping\",\n \"minimumRequirement\" => [\n \"subtotal\" => [\n \"greaterThanOrEqualToSubtotal\" => 20.0,\n ],\n ],\n \"customerSelection\" => [\n \"all\" => true,\n ],\n \"destination\" => [\n \"all\" => true,\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 discountCodeFreeShippingCreate($freeShippingCodeDiscount: DiscountCodeFreeShippingInput!) {\n discountCodeFreeShippingCreate(freeShippingCodeDiscount: $freeShippingCodeDiscount) {\n codeDiscountNode {\n id\n codeDiscount {\n ... on DiscountCodeFreeShipping {\n title\n startsAt\n endsAt\n maximumShippingPrice {\n amount\n }\n customerSelection {\n ... on DiscountCustomerAll {\n allCustomers\n }\n }\n destinationSelection {\n ... on DiscountCountryAll {\n allCountries\n }\n }\n minimumRequirement {\n ... on DiscountMinimumSubtotal {\n greaterThanOrEqualToSubtotal {\n amount\n }\n }\n }\n codes(first: 2) {\n nodes {\n code\n }\n }\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n }`,\n {\n variables: {\n \"freeShippingCodeDiscount\": {\n \"startsAt\": \"2022-06-22T21:12:07.000Z\",\n \"appliesOncePerCustomer\": false,\n \"title\": \"FreeShipping\",\n \"code\": \"FreeShipping\",\n \"minimumRequirement\": {\n \"subtotal\": {\n \"greaterThanOrEqualToSubtotal\": 20.0\n }\n },\n \"customerSelection\": {\n \"all\": true\n },\n \"destination\": {\n \"all\": true\n }\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation discountCodeFreeShippingCreate($freeShippingCodeDiscount: DiscountCodeFreeShippingInput!) {\n discountCodeFreeShippingCreate(freeShippingCodeDiscount: $freeShippingCodeDiscount) {\n codeDiscountNode {\n id\n codeDiscount {\n ... on DiscountCodeFreeShipping {\n title\n startsAt\n endsAt\n maximumShippingPrice {\n amount\n }\n customerSelection {\n ... on DiscountCustomerAll {\n allCustomers\n }\n }\n destinationSelection {\n ... on DiscountCountryAll {\n allCountries\n }\n }\n minimumRequirement {\n ... on DiscountMinimumSubtotal {\n greaterThanOrEqualToSubtotal {\n amount\n }\n }\n }\n codes(first: 2) {\n nodes {\n code\n }\n }\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n}"
input: { "freeShippingCodeDiscount": { "startsAt": "2022-06-22T21:12:07.000Z", "appliesOncePerCustomer": false, "title": "FreeShipping", "code": "FreeShipping", "minimumRequirement": { "subtotal": { "greaterThanOrEqualToSubtotal": 20.0 } }, "customerSelection": { "all": true }, "destination": { "all": true } } }
response: { "data": { "discountCodeFreeShippingCreate": { "codeDiscountNode": { "id": "gid://shopify/DiscountCodeNode/1057371199", "codeDiscount": { "title": "FreeShipping", "startsAt": "2022-06-22T21:12:07Z", "endsAt": null, "maximumShippingPrice": null, "customerSelection": { "allCustomers": true }, "destinationSelection": { "allCountries": true }, "minimumRequirement": { "greaterThanOrEqualToSubtotal": { "amount": "20.0" } }, "codes": { "nodes": [ { "code": "FreeShipping" } ] } } }, "userErrors": [] } } }