discount Code Basic Createmutation
mutation
2024-10latest
Requires Apps must have write
access scope.
Creates a basic code discount.
Arguments
The input data used to create the code discount.
Was this section helpful?
DiscountCodeBasicCreatePayload returns
The created code discount.
The list of errors that occurred from executing the mutation.
Was this section helpful?
Code examples for MUTATION: discountCodeBasicCreate
Query Reference for MUTATION: discountCodeBasicCreate
"mutation discountCodeBasicCreate($basicCodeDiscount: DiscountCodeBasicInput!) {\n discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) {\n codeDiscountNode {\n # DiscountCodeNode fields\n }\n userErrors {\n field\n message\n }\n }\n}"
Input Reference for MUTATION: discountCodeBasicCreate
"{\n \"basicCodeDiscount\": {\n \"appliesOncePerCustomer\": true,\n \"code\": \"<your-code>\",\n \"combinesWith\": {\n \"orderDiscounts\": true,\n \"productDiscounts\": true,\n \"shippingDiscounts\": true\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 \"minimumRequirement\": {\n \"quantity\": {\n \"greaterThanOrEqualToQuantity\": \"50\"\n },\n \"subtotal\": {\n \"greaterThanOrEqualToSubtotal\": \"29.99\"\n }\n },\n \"recurringCycleLimit\": 1,\n \"startsAt\": \"2019-09-07T15:50:00Z\",\n \"title\": \"<your-title>\",\n \"usageLimit\": 1\n }\n}"
Schema Reference for MUTATION: discountCodeBasicCreate
"input DiscountCodeBasicInput {\n appliesOncePerCustomer: Boolean\n code: String\n combinesWith: DiscountCombinesWithInput\n customerGets: DiscountCustomerGetsInput\n customerSelection: DiscountCustomerSelectionInput\n endsAt: DateTime\n minimumRequirement: DiscountMinimumRequirementInput\n recurringCycleLimit: Int\n startsAt: DateTime\n title: String\n usageLimit: Int\n}\n\ninput DiscountCombinesWithInput {\n orderDiscounts: Boolean\n productDiscounts: Boolean\n shippingDiscounts: Boolean\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\ninput DiscountMinimumRequirementInput {\n quantity: DiscountMinimumQuantityInput\n subtotal: DiscountMinimumSubtotalInput\n}\n"
Display Examples for MUTATION: discountCodeBasicCreate
[ { "example": { "type_name": "discountcodebasiccreate", "title": "Create a basic code discount", "description": "Create a code discount that offers a 20% discount off to all customers on all items during the summer months (limit one use per customer).", "query_string": "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}", "variables": { "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": [] } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/pricing/test/unit/graph_api/admin/mutations/discount_code_basic_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 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", "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", "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", "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", "php_example": "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<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\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$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "basicCodeDiscount", "description": "The input data used to create the code discount.", "type": { "kind": "INPUT_OBJECT", "name": "DiscountCodeBasicInput", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "DiscountCodeBasicInput!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "basicCodeDiscount", "argValue": " {\"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}", "typeKind": "MUTATION" } ] } ]