Version: unstable
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/unstable/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation discountCodeBasicCreate($basicCodeDiscount: DiscountCodeBasicInput!) { discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) { codeDiscountNode { codeDiscount { ... on DiscountCodeBasic { title codes(first: 10) { nodes { code } } startsAt endsAt customerSelection { ... on DiscountCustomerAll { allCustomers } } customerGets { value { ... on DiscountPercentage { percentage } } items { ... on AllDiscountItems { allItems } } } appliesOncePerCustomer } } } userErrors { field code message } } }\",\n \"variables\": {\n \"basicCodeDiscount\": {\n \"title\": \"20% off all items during the summer of 2022\",\n \"code\": \"SUMMER20\",\n \"startsAt\": \"2022-06-21T00:00:00Z\",\n \"endsAt\": \"2022-09-21T00:00:00Z\",\n \"customerSelection\": {\n \"all\": true\n },\n \"customerGets\": {\n \"value\": {\n \"percentage\": 0.2\n },\n \"items\": {\n \"all\": true\n }\n },\n \"appliesOncePerCustomer\": true\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation discountCodeBasicCreate($basicCodeDiscount: DiscountCodeBasicInput!) {\n discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) {\n codeDiscountNode {\n codeDiscount {\n ... on DiscountCodeBasic {\n title\n codes(first: 10) {\n nodes {\n code\n }\n }\n startsAt\n endsAt\n customerSelection {\n ... on DiscountCustomerAll {\n allCustomers\n }\n }\n customerGets {\n value {\n ... on DiscountPercentage {\n percentage\n }\n }\n items {\n ... on AllDiscountItems {\n allItems\n }\n }\n }\n appliesOncePerCustomer\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n }`,\n \"variables\": {\n \"basicCodeDiscount\": {\n \"title\": \"20% off all items during the summer of 2022\",\n \"code\": \"SUMMER20\",\n \"startsAt\": \"2022-06-21T00:00:00Z\",\n \"endsAt\": \"2022-09-21T00:00:00Z\",\n \"customerSelection\": {\n \"all\": true\n },\n \"customerGets\": {\n \"value\": {\n \"percentage\": 0.2\n },\n \"items\": {\n \"all\": true\n }\n },\n \"appliesOncePerCustomer\": true\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 discountCodeBasicCreate($basicCodeDiscount: DiscountCodeBasicInput!) {\n discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) {\n codeDiscountNode {\n codeDiscount {\n ... on DiscountCodeBasic {\n title\n codes(first: 10) {\n nodes {\n code\n }\n }\n startsAt\n endsAt\n customerSelection {\n ... on DiscountCustomerAll {\n allCustomers\n }\n }\n customerGets {\n value {\n ... on DiscountPercentage {\n percentage\n }\n }\n items {\n ... on AllDiscountItems {\n allItems\n }\n }\n }\n appliesOncePerCustomer\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"basicCodeDiscount\": {\n \"title\": \"20% off all items during the summer of 2022\",\n \"code\": \"SUMMER20\",\n \"startsAt\": \"2022-06-21T00:00:00Z\",\n \"endsAt\": \"2022-09-21T00:00:00Z\",\n \"customerSelection\": {\n \"all\": true\n },\n \"customerGets\": {\n \"value\": {\n \"percentage\": 0.2\n },\n \"items\": {\n \"all\": true\n }\n },\n \"appliesOncePerCustomer\": true\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\" => \"20% off all items during the summer of 2022\",\n \"code\" => \"SUMMER20\",\n \"startsAt\" => \"2022-06-21T00:00:00Z\",\n \"endsAt\" => \"2022-09-21T00:00:00Z\",\n \"customerSelection\" => [\n \"all\" => true,\n ],\n \"customerGets\" => [\n \"value\" => [\n \"percentage\" => 0.2,\n ],\n \"items\" => [\n \"all\" => true,\n ],\n ],\n \"appliesOncePerCustomer\" => true,\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 discountCodeBasicCreate($basicCodeDiscount: DiscountCodeBasicInput!) {\n discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) {\n codeDiscountNode {\n codeDiscount {\n ... on DiscountCodeBasic {\n title\n codes(first: 10) {\n nodes {\n code\n }\n }\n startsAt\n endsAt\n customerSelection {\n ... on DiscountCustomerAll {\n allCustomers\n }\n }\n customerGets {\n value {\n ... on DiscountPercentage {\n percentage\n }\n }\n items {\n ... on AllDiscountItems {\n allItems\n }\n }\n }\n appliesOncePerCustomer\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n }`,\n {\n variables: {\n \"basicCodeDiscount\": {\n \"title\": \"20% off all items during the summer of 2022\",\n \"code\": \"SUMMER20\",\n \"startsAt\": \"2022-06-21T00:00:00Z\",\n \"endsAt\": \"2022-09-21T00:00:00Z\",\n \"customerSelection\": {\n \"all\": true\n },\n \"customerGets\": {\n \"value\": {\n \"percentage\": 0.2\n },\n \"items\": {\n \"all\": true\n }\n },\n \"appliesOncePerCustomer\": true\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation discountCodeBasicCreate($basicCodeDiscount: DiscountCodeBasicInput!) {\n discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) {\n codeDiscountNode {\n codeDiscount {\n ... on DiscountCodeBasic {\n title\n codes(first: 10) {\n nodes {\n code\n }\n }\n startsAt\n endsAt\n customerSelection {\n ... on DiscountCustomerAll {\n allCustomers\n }\n }\n customerGets {\n value {\n ... on DiscountPercentage {\n percentage\n }\n }\n items {\n ... on AllDiscountItems {\n allItems\n }\n }\n }\n appliesOncePerCustomer\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n}"
input: { "basicCodeDiscount": { "title": "20% off all items during the summer of 2022", "code": "SUMMER20", "startsAt": "2022-06-21T00:00:00Z", "endsAt": "2022-09-21T00:00:00Z", "customerSelection": { "all": true }, "customerGets": { "value": { "percentage": 0.2 }, "items": { "all": true } }, "appliesOncePerCustomer": true } }
response: { "data": { "discountCodeBasicCreate": { "codeDiscountNode": { "codeDiscount": { "title": "20% off all items during the summer of 2022", "codes": { "nodes": [ { "code": "SUMMER20" } ] }, "startsAt": "2022-06-21T00:00:00Z", "endsAt": "2022-09-21T00:00:00Z", "customerSelection": { "allCustomers": true }, "customerGets": { "value": { "percentage": 0.2 }, "items": { "allItems": true } }, "appliesOncePerCustomer": true } }, "userErrors": [] } } }