Version: 2024-07
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-07/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation discountCodeBxgyCreate($bxgyCodeDiscount: DiscountCodeBxgyInput!) { discountCodeBxgyCreate(bxgyCodeDiscount: $bxgyCodeDiscount) { codeDiscountNode { codeDiscount { ... on DiscountCodeBxgy { title codes(first: 10) { nodes { code } } startsAt endsAt customerBuys { items { ...collectionsFragment } value { ... on DiscountQuantity { quantity } } } customerGets { appliesOnOneTimePurchase appliesOnSubscription value { ... on DiscountOnQuantity { effect { ... on DiscountPercentage { percentage } } quantity { quantity } } } items { ...collectionsFragment } } customerSelection { ... on DiscountCustomerAll { allCustomers } } appliesOncePerCustomer usesPerOrderLimit } } } userErrors { field code message } } } fragment collectionsFragment on DiscountCollections { collections(first: 10) { nodes { id title } } }\",\n \"variables\": {\n \"bxgyCodeDiscount\": {\n \"code\": \"SUMMERSALE\",\n \"customerBuys\": {\n \"items\": {\n \"collections\": {\n \"add\": [\n \"gid://shopify/Collection/1007901140\"\n ]\n }\n },\n \"value\": {\n \"quantity\": \"3\"\n }\n },\n \"customerGets\": {\n \"items\": {\n \"collections\": {\n \"add\": [\n \"gid://shopify/Collection/711838235\"\n ]\n }\n },\n \"value\": {\n \"discountOnQuantity\": {\n \"effect\": {\n \"percentage\": 0.2\n },\n \"quantity\": \"2\"\n }\n }\n },\n \"customerSelection\": {\n \"all\": true\n },\n \"endsAt\": \"2022-09-21T00:00:00Z\",\n \"startsAt\": \"2022-06-21T00:00:00Z\",\n \"title\": \"20% off up to two snowboards that are on sale for every three featured snowboards you buy.\",\n \"usesPerOrderLimit\": 3\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation discountCodeBxgyCreate($bxgyCodeDiscount: DiscountCodeBxgyInput!) {\n discountCodeBxgyCreate(bxgyCodeDiscount: $bxgyCodeDiscount) {\n codeDiscountNode {\n codeDiscount {\n ... on DiscountCodeBxgy {\n title\n codes(first: 10) {\n nodes {\n code\n }\n }\n startsAt\n endsAt\n customerBuys {\n items {\n ...collectionsFragment\n }\n value {\n ... on DiscountQuantity {\n quantity\n }\n }\n }\n customerGets {\n appliesOnOneTimePurchase\n appliesOnSubscription\n value {\n ... on DiscountOnQuantity {\n effect {\n ... on DiscountPercentage {\n percentage\n }\n }\n quantity {\n quantity\n }\n }\n }\n items {\n ...collectionsFragment\n }\n }\n customerSelection {\n ... on DiscountCustomerAll {\n allCustomers\n }\n }\n appliesOncePerCustomer\n usesPerOrderLimit\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n }\n \n fragment collectionsFragment on DiscountCollections {\n collections(first: 10) {\n nodes {\n id\n title\n }\n }\n }`,\n \"variables\": {\n \"bxgyCodeDiscount\": {\n \"code\": \"SUMMERSALE\",\n \"customerBuys\": {\n \"items\": {\n \"collections\": {\n \"add\": [\n \"gid://shopify/Collection/1007901140\"\n ]\n }\n },\n \"value\": {\n \"quantity\": \"3\"\n }\n },\n \"customerGets\": {\n \"items\": {\n \"collections\": {\n \"add\": [\n \"gid://shopify/Collection/711838235\"\n ]\n }\n },\n \"value\": {\n \"discountOnQuantity\": {\n \"effect\": {\n \"percentage\": 0.2\n },\n \"quantity\": \"2\"\n }\n }\n },\n \"customerSelection\": {\n \"all\": true\n },\n \"endsAt\": \"2022-09-21T00:00:00Z\",\n \"startsAt\": \"2022-06-21T00:00:00Z\",\n \"title\": \"20% off up to two snowboards that are on sale for every three featured snowboards you buy.\",\n \"usesPerOrderLimit\": 3\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 discountCodeBxgyCreate($bxgyCodeDiscount: DiscountCodeBxgyInput!) {\n discountCodeBxgyCreate(bxgyCodeDiscount: $bxgyCodeDiscount) {\n codeDiscountNode {\n codeDiscount {\n ... on DiscountCodeBxgy {\n title\n codes(first: 10) {\n nodes {\n code\n }\n }\n startsAt\n endsAt\n customerBuys {\n items {\n ...collectionsFragment\n }\n value {\n ... on DiscountQuantity {\n quantity\n }\n }\n }\n customerGets {\n appliesOnOneTimePurchase\n appliesOnSubscription\n value {\n ... on DiscountOnQuantity {\n effect {\n ... on DiscountPercentage {\n percentage\n }\n }\n quantity {\n quantity\n }\n }\n }\n items {\n ...collectionsFragment\n }\n }\n customerSelection {\n ... on DiscountCustomerAll {\n allCustomers\n }\n }\n appliesOncePerCustomer\n usesPerOrderLimit\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n }\n \n fragment collectionsFragment on DiscountCollections {\n collections(first: 10) {\n nodes {\n id\n title\n }\n }\n }\nQUERY\n\nvariables = {\n \"bxgyCodeDiscount\": {\n \"code\": \"SUMMERSALE\",\n \"customerBuys\": {\n \"items\": {\n \"collections\": {\n \"add\": [\"gid://shopify/Collection/1007901140\"]\n }\n },\n \"value\": {\n \"quantity\": \"3\"\n }\n },\n \"customerGets\": {\n \"items\": {\n \"collections\": {\n \"add\": [\"gid://shopify/Collection/711838235\"]\n }\n },\n \"value\": {\n \"discountOnQuantity\": {\n \"effect\": {\n \"percentage\": 0.2\n },\n \"quantity\": \"2\"\n }\n }\n },\n \"customerSelection\": {\n \"all\": true\n },\n \"endsAt\": \"2022-09-21T00:00:00Z\",\n \"startsAt\": \"2022-06-21T00:00:00Z\",\n \"title\": \"20% off up to two snowboards that are on sale for every three featured snowboards you buy.\",\n \"usesPerOrderLimit\": 3\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 discountCodeBxgyCreate($bxgyCodeDiscount: DiscountCodeBxgyInput!) {\n discountCodeBxgyCreate(bxgyCodeDiscount: $bxgyCodeDiscount) {\n codeDiscountNode {\n codeDiscount {\n ... on DiscountCodeBxgy {\n title\n codes(first: 10) {\n nodes {\n code\n }\n }\n startsAt\n endsAt\n customerBuys {\n items {\n ...collectionsFragment\n }\n value {\n ... on DiscountQuantity {\n quantity\n }\n }\n }\n customerGets {\n appliesOnOneTimePurchase\n appliesOnSubscription\n value {\n ... on DiscountOnQuantity {\n effect {\n ... on DiscountPercentage {\n percentage\n }\n }\n quantity {\n quantity\n }\n }\n }\n items {\n ...collectionsFragment\n }\n }\n customerSelection {\n ... on DiscountCustomerAll {\n allCustomers\n }\n }\n appliesOncePerCustomer\n usesPerOrderLimit\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n }\n \n fragment collectionsFragment on DiscountCollections {\n collections(first: 10) {\n nodes {\n id\n title\n }\n }\n }\nQUERY;\n\n$variables = [\n \"bxgyCodeDiscount\" => [\n \"code\" => \"SUMMERSALE\",\n \"customerBuys\" => [\n \"items\" => [\n \"collections\" => [\n \"add\" => [\"gid://shopify/Collection/1007901140\"],\n ],\n ],\n \"value\" => [\n \"quantity\" => \"3\",\n ],\n ],\n \"customerGets\" => [\n \"items\" => [\n \"collections\" => [\n \"add\" => [\"gid://shopify/Collection/711838235\"],\n ],\n ],\n \"value\" => [\n \"discountOnQuantity\" => [\n \"effect\" => [\n \"percentage\" => 0.2,\n ],\n \"quantity\" => \"2\",\n ],\n ],\n ],\n \"customerSelection\" => [\n \"all\" => true,\n ],\n \"endsAt\" => \"2022-09-21T00:00:00Z\",\n \"startsAt\" => \"2022-06-21T00:00:00Z\",\n \"title\" => \"20% off up to two snowboards that are on sale for every three featured snowboards you buy.\",\n \"usesPerOrderLimit\" => 3,\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 discountCodeBxgyCreate($bxgyCodeDiscount: DiscountCodeBxgyInput!) {\n discountCodeBxgyCreate(bxgyCodeDiscount: $bxgyCodeDiscount) {\n codeDiscountNode {\n codeDiscount {\n ... on DiscountCodeBxgy {\n title\n codes(first: 10) {\n nodes {\n code\n }\n }\n startsAt\n endsAt\n customerBuys {\n items {\n ...collectionsFragment\n }\n value {\n ... on DiscountQuantity {\n quantity\n }\n }\n }\n customerGets {\n appliesOnOneTimePurchase\n appliesOnSubscription\n value {\n ... on DiscountOnQuantity {\n effect {\n ... on DiscountPercentage {\n percentage\n }\n }\n quantity {\n quantity\n }\n }\n }\n items {\n ...collectionsFragment\n }\n }\n customerSelection {\n ... on DiscountCustomerAll {\n allCustomers\n }\n }\n appliesOncePerCustomer\n usesPerOrderLimit\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n }\n \n fragment collectionsFragment on DiscountCollections {\n collections(first: 10) {\n nodes {\n id\n title\n }\n }\n }`,\n {\n variables: {\n \"bxgyCodeDiscount\": {\n \"code\": \"SUMMERSALE\",\n \"customerBuys\": {\n \"items\": {\n \"collections\": {\n \"add\": [\n \"gid://shopify/Collection/1007901140\"\n ]\n }\n },\n \"value\": {\n \"quantity\": \"3\"\n }\n },\n \"customerGets\": {\n \"items\": {\n \"collections\": {\n \"add\": [\n \"gid://shopify/Collection/711838235\"\n ]\n }\n },\n \"value\": {\n \"discountOnQuantity\": {\n \"effect\": {\n \"percentage\": 0.2\n },\n \"quantity\": \"2\"\n }\n }\n },\n \"customerSelection\": {\n \"all\": true\n },\n \"endsAt\": \"2022-09-21T00:00:00Z\",\n \"startsAt\": \"2022-06-21T00:00:00Z\",\n \"title\": \"20% off up to two snowboards that are on sale for every three featured snowboards you buy.\",\n \"usesPerOrderLimit\": 3\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation discountCodeBxgyCreate($bxgyCodeDiscount: DiscountCodeBxgyInput!) {\n discountCodeBxgyCreate(bxgyCodeDiscount: $bxgyCodeDiscount) {\n codeDiscountNode {\n codeDiscount {\n ... on DiscountCodeBxgy {\n title\n codes(first: 10) {\n nodes {\n code\n }\n }\n startsAt\n endsAt\n customerBuys {\n items {\n ...collectionsFragment\n }\n value {\n ... on DiscountQuantity {\n quantity\n }\n }\n }\n customerGets {\n appliesOnOneTimePurchase\n appliesOnSubscription\n value {\n ... on DiscountOnQuantity {\n effect {\n ... on DiscountPercentage {\n percentage\n }\n }\n quantity {\n quantity\n }\n }\n }\n items {\n ...collectionsFragment\n }\n }\n customerSelection {\n ... on DiscountCustomerAll {\n allCustomers\n }\n }\n appliesOncePerCustomer\n usesPerOrderLimit\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n}\n\nfragment collectionsFragment on DiscountCollections {\n collections(first: 10) {\n nodes {\n id\n title\n }\n }\n}"
input: { "bxgyCodeDiscount": { "code": "SUMMERSALE", "customerBuys": { "items": { "collections": { "add": [ "gid://shopify/Collection/1007901140" ] } }, "value": { "quantity": "3" } }, "customerGets": { "items": { "collections": { "add": [ "gid://shopify/Collection/711838235" ] } }, "value": { "discountOnQuantity": { "effect": { "percentage": 0.2 }, "quantity": "2" } } }, "customerSelection": { "all": true }, "endsAt": "2022-09-21T00:00:00Z", "startsAt": "2022-06-21T00:00:00Z", "title": "20% off up to two snowboards that are on sale for every three featured snowboards you buy.", "usesPerOrderLimit": 3 } }
response: { "data": { "discountCodeBxgyCreate": { "codeDiscountNode": { "codeDiscount": { "title": "20% off up to two snowboards that are on sale for every three featured snowboards you buy.", "codes": { "nodes": [ { "code": "SUMMERSALE" } ] }, "startsAt": "2022-06-21T00:00:00Z", "endsAt": "2022-09-21T00:00:00Z", "customerBuys": { "items": { "collections": { "nodes": [ { "id": "gid://shopify/Collection/1007901140", "title": "Featured items" } ] } }, "value": { "quantity": "3" } }, "customerGets": { "appliesOnOneTimePurchase": true, "appliesOnSubscription": false, "value": { "effect": { "percentage": 0.2 }, "quantity": { "quantity": "2" } }, "items": { "collections": { "nodes": [ { "id": "gid://shopify/Collection/711838235", "title": "On Sale!" } ] } } }, "customerSelection": { "allCustomers": true }, "appliesOncePerCustomer": false, "usesPerOrderLimit": 3 } }, "userErrors": [] } } }