discount Code Bxgy Createmutation
mutation
2024-10latest
Requires Apps must have write
access scope.
Creates a Buy X get Y (BXGY) code discount.
Arguments
The input data used to create the code discount.
Was this section helpful?
DiscountCodeBxgyCreatePayload returns
The created code discount.
The list of errors that occurred from executing the mutation.
Was this section helpful?
Code examples for MUTATION: discountCodeBxgyCreate
Query Reference for MUTATION: discountCodeBxgyCreate
"mutation discountCodeBxgyCreate($bxgyCodeDiscount: DiscountCodeBxgyInput!) {\n discountCodeBxgyCreate(bxgyCodeDiscount: $bxgyCodeDiscount) {\n codeDiscountNode {\n # DiscountCodeNode fields\n }\n userErrors {\n field\n message\n }\n }\n}"
Input Reference for MUTATION: discountCodeBxgyCreate
"{\n \"bxgyCodeDiscount\": {\n \"appliesOncePerCustomer\": true,\n \"code\": \"<your-code>\",\n \"combinesWith\": {\n \"orderDiscounts\": true,\n \"productDiscounts\": true,\n \"shippingDiscounts\": true\n },\n \"customerBuys\": {\n \"items\": {\n \"all\": true,\n \"collections\": {\n \"add\": [\n \"gid://shopify/<objectName>/10079785100\"\n ],\n \"remove\": [\n \"gid://shopify/<objectName>/10079785100\"\n ]\n },\n \"products\": {\n \"productVariantsToAdd\": [\n \"gid://shopify/<objectName>/10079785100\"\n ],\n \"productVariantsToRemove\": [\n \"gid://shopify/<objectName>/10079785100\"\n ],\n \"productsToAdd\": [\n \"gid://shopify/<objectName>/10079785100\"\n ],\n \"productsToRemove\": [\n \"gid://shopify/<objectName>/10079785100\"\n ]\n }\n },\n \"value\": {\n \"amount\": \"29.99\",\n \"quantity\": \"50\"\n }\n },\n \"customerGets\": {\n \"appliesOnOneTimePurchase\": true,\n \"appliesOnSubscription\": true,\n \"items\": {\n \"all\": true,\n \"collections\": {\n \"add\": [\n \"gid://shopify/<objectName>/10079785100\"\n ],\n \"remove\": [\n \"gid://shopify/<objectName>/10079785100\"\n ]\n },\n \"products\": {\n \"productVariantsToAdd\": [\n \"gid://shopify/<objectName>/10079785100\"\n ],\n \"productVariantsToRemove\": [\n \"gid://shopify/<objectName>/10079785100\"\n ],\n \"productsToAdd\": [\n \"gid://shopify/<objectName>/10079785100\"\n ],\n \"productsToRemove\": [\n \"gid://shopify/<objectName>/10079785100\"\n ]\n }\n },\n \"value\": {\n \"discountAmount\": {\n \"amount\": \"29.99\",\n \"appliesOnEachItem\": true\n },\n \"discountOnQuantity\": {\n \"effect\": {\n \"amount\": \"29.99\",\n \"percentage\": 1.1\n },\n \"quantity\": \"50\"\n },\n \"percentage\": 1.1\n }\n },\n \"customerSelection\": {\n \"all\": true,\n \"customerSegments\": {\n \"add\": [\n \"gid://shopify/<objectName>/10079785100\"\n ],\n \"remove\": [\n \"gid://shopify/<objectName>/10079785100\"\n ]\n },\n \"customers\": {\n \"add\": [\n \"gid://shopify/<objectName>/10079785100\"\n ],\n \"remove\": [\n \"gid://shopify/<objectName>/10079785100\"\n ]\n }\n },\n \"endsAt\": \"2019-09-07T15:50:00Z\",\n \"startsAt\": \"2019-09-07T15:50:00Z\",\n \"title\": \"<your-title>\",\n \"usageLimit\": 1,\n \"usesPerOrderLimit\": 1\n }\n}"
Schema Reference for MUTATION: discountCodeBxgyCreate
"input DiscountCodeBxgyInput {\n appliesOncePerCustomer: Boolean\n code: String\n combinesWith: DiscountCombinesWithInput\n customerBuys: DiscountCustomerBuysInput\n customerGets: DiscountCustomerGetsInput\n customerSelection: DiscountCustomerSelectionInput\n endsAt: DateTime\n startsAt: DateTime\n title: String\n usageLimit: Int\n usesPerOrderLimit: Int\n}\n\ninput DiscountCombinesWithInput {\n orderDiscounts: Boolean\n productDiscounts: Boolean\n shippingDiscounts: Boolean\n}\n\ninput DiscountCustomerBuysInput {\n items: DiscountItemsInput\n value: DiscountCustomerBuysValueInput\n}\n\ninput DiscountCustomerGetsInput {\n appliesOnOneTimePurchase: Boolean\n appliesOnSubscription: Boolean\n items: DiscountItemsInput\n value: DiscountCustomerGetsValueInput\n}\n\ninput DiscountCustomerSelectionInput {\n all: Boolean\n customerSegments: DiscountCustomerSegmentsInput\n customers: DiscountCustomersInput\n}\n"
Display Examples for MUTATION: discountCodeBxgyCreate
[ { "example": { "type_name": "discountcodebxgycreate", "title": "Create a basic Buy X get Y (BXGY) discount", "description": "Create a code discount that offers a 20% discount on up to two snowboards that are on sale\nto all customers when they buy three featured snowboards. The code discount is valid during\nthe summer months and can be used a maximum of three times per order.\n", "query_string": "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}", "variables": { "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": [] } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/pricing/test/unit/graph_api/admin/mutations/discount_code_bxgy_create_test.rb", "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 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", "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", "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", "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", "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" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "bxgyCodeDiscount", "description": "The input data used to create the code discount.", "type": { "kind": "INPUT_OBJECT", "name": "DiscountCodeBxgyInput", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "DiscountCodeBxgyInput!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "bxgyCodeDiscount", "argValue": " {\"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}", "typeKind": "MUTATION" } ] } ]