--- title: discountCodeBasicCreate - GraphQL Admin description: >- Creates an [amount off discount](https://help.shopify.com/manual/discounts/discount-types/percentage-fixed-amount) that's applied on a cart and at checkout when a customer enters a code. Amount off discounts can be a percentage off or a fixed amount off. > Note: > To create discounts that are automatically applied on a cart and at checkout, use the [`discountAutomaticBasicCreate`](https://shopify.dev/docs/api/admin-graphql/latest/mutations/discountAutomaticBasicCreate) mutation. api_version: 2024-10 api_name: admin type: mutation api_type: graphql source_url: html: >- https://shopify.dev/docs/api/admin-graphql/2024-10/mutations/discountCodeBasicCreate md: >- https://shopify.dev/docs/api/admin-graphql/2024-10/mutations/discountCodeBasicCreate.txt --- # discount​Code​Basic​Create mutation Requires Apps must have `write_discounts` access scope. Creates an [amount off discount](https://help.shopify.com/manual/discounts/discount-types/percentage-fixed-amount) that's applied on a cart and at checkout when a customer enters a code. Amount off discounts can be a percentage off or a fixed amount off. *** Note To create discounts that are automatically applied on a cart and at checkout, use the [`discountAutomaticBasicCreate`](https://shopify.dev/docs/api/admin-graphql/latest/mutations/discountAutomaticBasicCreate) mutation. *** ## Arguments * basic​Code​Discount [Discount​Code​Basic​Input!](https://shopify.dev/docs/api/admin-graphql/2024-10/input-objects/DiscountCodeBasicInput) required The input data used to create the discount code. *** ## Discount​Code​Basic​Create​Payload returns * code​Discount​Node [Discount​Code​Node](https://shopify.dev/docs/api/admin-graphql/2024-10/objects/DiscountCodeNode) The discount code that was created. * user​Errors [\[Discount​User​Error!\]!](https://shopify.dev/docs/api/admin-graphql/2024-10/objects/DiscountUserError) non-null The list of errors that occurred from executing the mutation. *** ## Examples * ### Create a percentage off discount code with a minimum purchase requirement #### Description Create an \[amount off discount]\(https\://help.shopify.com/manual/discounts/discount-types/percentage-fixed-amount) that's applied on a cart and at checkout when customers enter a code. This example shows how to create a code that offers a 10% discount on all items to a customer after they spend $50. The discount is limited to one use for each customer. #### Query ```graphql mutation CreateDiscountCode($basicCodeDiscount: DiscountCodeBasicInput!) { discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) { codeDiscountNode { id codeDiscount { ... on DiscountCodeBasic { title startsAt endsAt customerSelection { ... on DiscountCustomers { customers { id } } } customerGets { value { ... on DiscountPercentage { percentage } } } } } } userErrors { field message } } } ``` #### Variables ```json { "basicCodeDiscount": { "title": "10% off selected items", "code": "10FORYOU", "startsAt": "2025-01-01T00:00:00Z", "endsAt": "2025-12-31T23:59:59Z", "customerSelection": { "customers": { "add": [ "gid://shopify/Customer/624407574" ] } }, "customerGets": { "value": { "percentage": 0.1 }, "items": { "all": true } }, "minimumRequirement": { "subtotal": { "greaterThanOrEqualToSubtotal": "50.0" } }, "usageLimit": 100, "appliesOncePerCustomer": true } } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "mutation CreateDiscountCode($basicCodeDiscount: DiscountCodeBasicInput!) { discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) { codeDiscountNode { id codeDiscount { ... on DiscountCodeBasic { title startsAt endsAt customerSelection { ... on DiscountCustomers { customers { id } } } customerGets { value { ... on DiscountPercentage { percentage } } } } } } userErrors { field message } } }", "variables": { "basicCodeDiscount": { "title": "10% off selected items", "code": "10FORYOU", "startsAt": "2025-01-01T00:00:00Z", "endsAt": "2025-12-31T23:59:59Z", "customerSelection": { "customers": { "add": [ "gid://shopify/Customer/624407574" ] } }, "customerGets": { "value": { "percentage": 0.1 }, "items": { "all": true } }, "minimumRequirement": { "subtotal": { "greaterThanOrEqualToSubtotal": "50.0" } }, "usageLimit": 100, "appliesOncePerCustomer": true } } }' ``` #### Remix ```javascript const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation CreateDiscountCode($basicCodeDiscount: DiscountCodeBasicInput!) { discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) { codeDiscountNode { id codeDiscount { ... on DiscountCodeBasic { title startsAt endsAt customerSelection { ... on DiscountCustomers { customers { id } } } customerGets { value { ... on DiscountPercentage { percentage } } } } } } userErrors { field message } } }`, { variables: { "basicCodeDiscount": { "title": "10% off selected items", "code": "10FORYOU", "startsAt": "2025-01-01T00:00:00Z", "endsAt": "2025-12-31T23:59:59Z", "customerSelection": { "customers": { "add": [ "gid://shopify/Customer/624407574" ] } }, "customerGets": { "value": { "percentage": 0.1 }, "items": { "all": true } }, "minimumRequirement": { "subtotal": { "greaterThanOrEqualToSubtotal": "50.0" } }, "usageLimit": 100, "appliesOncePerCustomer": true } }, }, ); const data = await response.json(); ``` #### Ruby ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY mutation CreateDiscountCode($basicCodeDiscount: DiscountCodeBasicInput!) { discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) { codeDiscountNode { id codeDiscount { ... on DiscountCodeBasic { title startsAt endsAt customerSelection { ... on DiscountCustomers { customers { id } } } customerGets { value { ... on DiscountPercentage { percentage } } } } } } userErrors { field message } } } QUERY variables = { "basicCodeDiscount": { "title": "10% off selected items", "code": "10FORYOU", "startsAt": "2025-01-01T00:00:00Z", "endsAt": "2025-12-31T23:59:59Z", "customerSelection": { "customers": { "add": [ "gid://shopify/Customer/624407574" ] } }, "customerGets": { "value": { "percentage": 0.1 }, "items": { "all": true } }, "minimumRequirement": { "subtotal": { "greaterThanOrEqualToSubtotal": "50.0" } }, "usageLimit": 100, "appliesOncePerCustomer": true } } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `mutation CreateDiscountCode($basicCodeDiscount: DiscountCodeBasicInput!) { discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) { codeDiscountNode { id codeDiscount { ... on DiscountCodeBasic { title startsAt endsAt customerSelection { ... on DiscountCustomers { customers { id } } } customerGets { value { ... on DiscountPercentage { percentage } } } } } } userErrors { field message } } }`, "variables": { "basicCodeDiscount": { "title": "10% off selected items", "code": "10FORYOU", "startsAt": "2025-01-01T00:00:00Z", "endsAt": "2025-12-31T23:59:59Z", "customerSelection": { "customers": { "add": [ "gid://shopify/Customer/624407574" ] } }, "customerGets": { "value": { "percentage": 0.1 }, "items": { "all": true } }, "minimumRequirement": { "subtotal": { "greaterThanOrEqualToSubtotal": "50.0" } }, "usageLimit": 100, "appliesOncePerCustomer": true } }, }, }); ``` #### Response ```json { "discountCodeBasicCreate": { "codeDiscountNode": { "id": "gid://shopify/DiscountCodeNode/1057856652", "codeDiscount": { "title": "10% off selected items", "startsAt": "2025-01-01T00:00:00Z", "endsAt": "2025-12-31T23:59:59Z", "customerSelection": { "customers": [ { "id": "gid://shopify/Customer/624407574" } ] }, "customerGets": { "value": { "percentage": 0.1 } } } }, "userErrors": [] } } ``` * ### Create an amount off discount code with an end date #### Description Create an \[amount off discount]\(https\://help.shopify.com/manual/discounts/discount-types/percentage-fixed-amount) that's applied on a cart and at checkout when customers enter a code. This example shows how to create a code that offers a $20 off discount on all items from June 21st to September 21st. The discount is limited to one use for each customer. #### Query ```graphql mutation CreateSummerDiscount($input: DiscountCodeBasicInput!) { discountCodeBasicCreate(basicCodeDiscount: $input) { codeDiscountNode { id codeDiscount { ... on DiscountCodeBasic { title codes(first: 10) { nodes { code } } startsAt endsAt } } } userErrors { field message } } } ``` #### Variables ```json { "input": { "title": "Limited time discount off all items", "code": "BUYNOW20", "startsAt": "2024-06-21T00:00:00Z", "endsAt": "2024-09-21T00:00:00Z", "customerSelection": { "all": true }, "customerGets": { "value": { "discountAmount": { "amount": 20, "appliesOnEachItem": false } }, "items": { "all": true } }, "appliesOncePerCustomer": true } } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "mutation CreateSummerDiscount($input: DiscountCodeBasicInput!) { discountCodeBasicCreate(basicCodeDiscount: $input) { codeDiscountNode { id codeDiscount { ... on DiscountCodeBasic { title codes(first: 10) { nodes { code } } startsAt endsAt } } } userErrors { field message } } }", "variables": { "input": { "title": "Limited time discount off all items", "code": "BUYNOW20", "startsAt": "2024-06-21T00:00:00Z", "endsAt": "2024-09-21T00:00:00Z", "customerSelection": { "all": true }, "customerGets": { "value": { "discountAmount": { "amount": 20, "appliesOnEachItem": false } }, "items": { "all": true } }, "appliesOncePerCustomer": true } } }' ``` #### Remix ```javascript const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation CreateSummerDiscount($input: DiscountCodeBasicInput!) { discountCodeBasicCreate(basicCodeDiscount: $input) { codeDiscountNode { id codeDiscount { ... on DiscountCodeBasic { title codes(first: 10) { nodes { code } } startsAt endsAt } } } userErrors { field message } } }`, { variables: { "input": { "title": "Limited time discount off all items", "code": "BUYNOW20", "startsAt": "2024-06-21T00:00:00Z", "endsAt": "2024-09-21T00:00:00Z", "customerSelection": { "all": true }, "customerGets": { "value": { "discountAmount": { "amount": 20, "appliesOnEachItem": false } }, "items": { "all": true } }, "appliesOncePerCustomer": true } }, }, ); const data = await response.json(); ``` #### Ruby ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY mutation CreateSummerDiscount($input: DiscountCodeBasicInput!) { discountCodeBasicCreate(basicCodeDiscount: $input) { codeDiscountNode { id codeDiscount { ... on DiscountCodeBasic { title codes(first: 10) { nodes { code } } startsAt endsAt } } } userErrors { field message } } } QUERY variables = { "input": { "title": "Limited time discount off all items", "code": "BUYNOW20", "startsAt": "2024-06-21T00:00:00Z", "endsAt": "2024-09-21T00:00:00Z", "customerSelection": { "all": true }, "customerGets": { "value": { "discountAmount": { "amount": 20, "appliesOnEachItem": false } }, "items": { "all": true } }, "appliesOncePerCustomer": true } } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `mutation CreateSummerDiscount($input: DiscountCodeBasicInput!) { discountCodeBasicCreate(basicCodeDiscount: $input) { codeDiscountNode { id codeDiscount { ... on DiscountCodeBasic { title codes(first: 10) { nodes { code } } startsAt endsAt } } } userErrors { field message } } }`, "variables": { "input": { "title": "Limited time discount off all items", "code": "BUYNOW20", "startsAt": "2024-06-21T00:00:00Z", "endsAt": "2024-09-21T00:00:00Z", "customerSelection": { "all": true }, "customerGets": { "value": { "discountAmount": { "amount": 20, "appliesOnEachItem": false } }, "items": { "all": true } }, "appliesOncePerCustomer": true } }, }, }); ``` #### Response ```json { "discountCodeBasicCreate": { "codeDiscountNode": { "id": "gid://shopify/DiscountCodeNode/1057856654", "codeDiscount": { "title": "Limited time discount off all items", "codes": { "nodes": [ { "code": "BUYNOW20" } ] }, "startsAt": "2024-06-21T00:00:00Z", "endsAt": "2024-09-21T00:00:00Z" } }, "userErrors": [] } } ``` * ### discountCodeBasicCreate reference [Open in GraphiQL](http://localhost:3457/graphiql?query=mutation%20CreateDiscountCode\(%24basicCodeDiscount%3A%20DiscountCodeBasicInput!\)%20%7B%0A%20%20discountCodeBasicCreate\(basicCodeDiscount%3A%20%24basicCodeDiscount\)%20%7B%0A%20%20%20%20codeDiscountNode%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20codeDiscount%20%7B%0A%20%20%20%20%20%20%20%20...%20on%20DiscountCodeBasic%20%7B%0A%20%20%20%20%20%20%20%20%20%20title%0A%20%20%20%20%20%20%20%20%20%20startsAt%0A%20%20%20%20%20%20%20%20%20%20endsAt%0A%20%20%20%20%20%20%20%20%20%20customerSelection%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20...%20on%20DiscountCustomers%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20customers%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20id%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20customerGets%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20value%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20...%20on%20DiscountPercentage%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20percentage%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20userErrors%20%7B%0A%20%20%20%20%20%20field%0A%20%20%20%20%20%20message%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D\&variables=%7B%0A%20%20%22basicCodeDiscount%22%3A%20%7B%0A%20%20%20%20%22title%22%3A%20%2210%25%20off%20selected%20items%22%2C%0A%20%20%20%20%22code%22%3A%20%2210FORYOU%22%2C%0A%20%20%20%20%22startsAt%22%3A%20%222025-01-01T00%3A00%3A00Z%22%2C%0A%20%20%20%20%22endsAt%22%3A%20%222025-12-31T23%3A59%3A59Z%22%2C%0A%20%20%20%20%22customerSelection%22%3A%20%7B%0A%20%20%20%20%20%20%22customers%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22add%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%22gid%3A%2F%2Fshopify%2FCustomer%2F624407574%22%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%22customerGets%22%3A%20%7B%0A%20%20%20%20%20%20%22value%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22percentage%22%3A%200.1%0A%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%22items%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22all%22%3A%20true%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%22minimumRequirement%22%3A%20%7B%0A%20%20%20%20%20%20%22subtotal%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22greaterThanOrEqualToSubtotal%22%3A%20%2250.0%22%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%22usageLimit%22%3A%20100%2C%0A%20%20%20%20%22appliesOncePerCustomer%22%3A%20true%0A%20%20%7D%0A%7D) ```javascript const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation CreateDiscountCode($basicCodeDiscount: DiscountCodeBasicInput!) { discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) { codeDiscountNode { id codeDiscount { ... on DiscountCodeBasic { title startsAt endsAt customerSelection { ... on DiscountCustomers { customers { id } } } customerGets { value { ... on DiscountPercentage { percentage } } } } } } userErrors { field message } } }`, { variables: { "basicCodeDiscount": { "title": "10% off selected items", "code": "10FORYOU", "startsAt": "2025-01-01T00:00:00Z", "endsAt": "2025-12-31T23:59:59Z", "customerSelection": { "customers": { "add": [ "gid://shopify/Customer/624407574" ] } }, "customerGets": { "value": { "percentage": 0.1 }, "items": { "all": true } }, "minimumRequirement": { "subtotal": { "greaterThanOrEqualToSubtotal": "50.0" } }, "usageLimit": 100, "appliesOncePerCustomer": true } }, }, ); const data = await response.json(); ``` ## Input variables JSON ```json { "basicCodeDiscount": { "title": "10% off selected items", "code": "10FORYOU", "startsAt": "2025-01-01T00:00:00Z", "endsAt": "2025-12-31T23:59:59Z", "customerSelection": { "customers": { "add": [ "gid://shopify/Customer/624407574" ] } }, "customerGets": { "value": { "percentage": 0.1 }, "items": { "all": true } }, "minimumRequirement": { "subtotal": { "greaterThanOrEqualToSubtotal": "50.0" } }, "usageLimit": 100, "appliesOncePerCustomer": true } } ``` ## Response JSON ```json { "discountCodeBasicCreate": { "codeDiscountNode": { "id": "gid://shopify/DiscountCodeNode/1057856652", "codeDiscount": { "title": "10% off selected items", "startsAt": "2025-01-01T00:00:00Z", "endsAt": "2025-12-31T23:59:59Z", "customerSelection": { "customers": [ { "id": "gid://shopify/Customer/624407574" } ] }, "customerGets": { "value": { "percentage": 0.1 } } } }, "userErrors": [] } } ```