# discountCodeBasicCreate - admin-graphql - MUTATION Version: 2024-10 ## 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. ### Access Scopes Apps must have `write_discounts` access scope. ## Arguments * [basicCodeDiscount](/docs/api/admin-graphql/2024-10/input-objects/DiscountCodeBasicInput): DiscountCodeBasicInput! - The input data used to create the discount code. ## Returns * [codeDiscountNode](/docs/api/admin-graphql/2024-10/objects/DiscountCodeNode): DiscountCodeNode The discount code that was created. * [userErrors](/docs/api/admin-graphql/2024-10/objects/DiscountUserError): DiscountUserError! The list of errors that occurred from executing the mutation. ## Examples ### Create a discount with a minimum purchase 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 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 } } }\",\n \"variables\": {\n \"basicCodeDiscount\": {\n \"title\": \"10% off selected items\",\n \"code\": \"10FORYOU\",\n \"startsAt\": \"2025-01-01T00:00:00Z\",\n \"endsAt\": \"2025-12-31T23:59:59Z\",\n \"customerSelection\": {\n \"customers\": {\n \"add\": [\n \"gid://shopify/Customer/624407574\"\n ]\n }\n },\n \"customerGets\": {\n \"value\": {\n \"percentage\": 0.1\n },\n \"items\": {\n \"all\": true\n }\n },\n \"minimumRequirement\": {\n \"subtotal\": {\n \"greaterThanOrEqualToSubtotal\": \"50.0\"\n }\n },\n \"usageLimit\": 100,\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 CreateDiscountCode($basicCodeDiscount: DiscountCodeBasicInput!) {\n discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) {\n codeDiscountNode {\n id\n codeDiscount {\n ... on DiscountCodeBasic {\n title\n startsAt\n endsAt\n customerSelection {\n ... on DiscountCustomers {\n customers {\n id\n }\n }\n }\n customerGets {\n value {\n ... on DiscountPercentage {\n percentage\n }\n }\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"basicCodeDiscount\": {\n \"title\": \"10% off selected items\",\n \"code\": \"10FORYOU\",\n \"startsAt\": \"2025-01-01T00:00:00Z\",\n \"endsAt\": \"2025-12-31T23:59:59Z\",\n \"customerSelection\": {\n \"customers\": {\n \"add\": [\n \"gid://shopify/Customer/624407574\"\n ]\n }\n },\n \"customerGets\": {\n \"value\": {\n \"percentage\": 0.1\n },\n \"items\": {\n \"all\": true\n }\n },\n \"minimumRequirement\": {\n \"subtotal\": {\n \"greaterThanOrEqualToSubtotal\": \"50.0\"\n }\n },\n \"usageLimit\": 100,\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 CreateDiscountCode($basicCodeDiscount: DiscountCodeBasicInput!) {\n discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) {\n codeDiscountNode {\n id\n codeDiscount {\n ... on DiscountCodeBasic {\n title\n startsAt\n endsAt\n customerSelection {\n ... on DiscountCustomers {\n customers {\n id\n }\n }\n }\n customerGets {\n value {\n ... on DiscountPercentage {\n percentage\n }\n }\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"basicCodeDiscount\": {\n \"title\": \"10% off selected items\",\n \"code\": \"10FORYOU\",\n \"startsAt\": \"2025-01-01T00:00:00Z\",\n \"endsAt\": \"2025-12-31T23:59:59Z\",\n \"customerSelection\": {\n \"customers\": {\n \"add\": [\"gid://shopify/Customer/624407574\"]\n }\n },\n \"customerGets\": {\n \"value\": {\n \"percentage\": 0.1\n },\n \"items\": {\n \"all\": true\n }\n },\n \"minimumRequirement\": {\n \"subtotal\": {\n \"greaterThanOrEqualToSubtotal\": \"50.0\"\n }\n },\n \"usageLimit\": 100,\n \"appliesOncePerCustomer\": true\n }\n}\n\nresponse = 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 CreateDiscountCode($basicCodeDiscount: DiscountCodeBasicInput!) {\n discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) {\n codeDiscountNode {\n id\n codeDiscount {\n ... on DiscountCodeBasic {\n title\n startsAt\n endsAt\n customerSelection {\n ... on DiscountCustomers {\n customers {\n id\n }\n }\n }\n customerGets {\n value {\n ... on DiscountPercentage {\n percentage\n }\n }\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"basicCodeDiscount\": {\n \"title\": \"10% off selected items\",\n \"code\": \"10FORYOU\",\n \"startsAt\": \"2025-01-01T00:00:00Z\",\n \"endsAt\": \"2025-12-31T23:59:59Z\",\n \"customerSelection\": {\n \"customers\": {\n \"add\": [\n \"gid://shopify/Customer/624407574\"\n ]\n }\n },\n \"customerGets\": {\n \"value\": {\n \"percentage\": 0.1\n },\n \"items\": {\n \"all\": true\n }\n },\n \"minimumRequirement\": {\n \"subtotal\": {\n \"greaterThanOrEqualToSubtotal\": \"50.0\"\n }\n },\n \"usageLimit\": 100,\n \"appliesOncePerCustomer\": true\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation CreateDiscountCode($basicCodeDiscount: DiscountCodeBasicInput!) {\n discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) {\n codeDiscountNode {\n id\n codeDiscount {\n ... on DiscountCodeBasic {\n title\n startsAt\n endsAt\n customerSelection {\n ... on DiscountCustomers {\n customers {\n id\n }\n }\n }\n customerGets {\n value {\n ... on DiscountPercentage {\n percentage\n }\n }\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n}" #### Graphql Input { "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 } } #### Graphql Response { "data": { "discountCodeBasicCreate": { "codeDiscountNode": { "id": "gid://shopify/DiscountCodeNode/1057371591", "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 a limited time discount 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 CreateSummerDiscount($input: DiscountCodeBasicInput!) { discountCodeBasicCreate(basicCodeDiscount: $input) { codeDiscountNode { id codeDiscount { ... on DiscountCodeBasic { title codes(first: 10) { nodes { code } } startsAt endsAt } } } userErrors { field message } } }\",\n \"variables\": {\n \"input\": {\n \"title\": \"Limited time discount off all items\",\n \"code\": \"BUYNOW20\",\n \"startsAt\": \"2024-06-21T00:00:00Z\",\n \"endsAt\": \"2024-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 CreateSummerDiscount($input: DiscountCodeBasicInput!) {\n discountCodeBasicCreate(basicCodeDiscount: $input) {\n codeDiscountNode {\n id\n codeDiscount {\n ... on DiscountCodeBasic {\n title\n codes(first: 10) {\n nodes {\n code\n }\n }\n startsAt\n endsAt\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"title\": \"Limited time discount off all items\",\n \"code\": \"BUYNOW20\",\n \"startsAt\": \"2024-06-21T00:00:00Z\",\n \"endsAt\": \"2024-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 CreateSummerDiscount($input: DiscountCodeBasicInput!) {\n discountCodeBasicCreate(basicCodeDiscount: $input) {\n codeDiscountNode {\n id\n codeDiscount {\n ... on DiscountCodeBasic {\n title\n codes(first: 10) {\n nodes {\n code\n }\n }\n startsAt\n endsAt\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"title\": \"Limited time discount off all items\",\n \"code\": \"BUYNOW20\",\n \"startsAt\": \"2024-06-21T00:00:00Z\",\n \"endsAt\": \"2024-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" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation CreateSummerDiscount($input: DiscountCodeBasicInput!) {\n discountCodeBasicCreate(basicCodeDiscount: $input) {\n codeDiscountNode {\n id\n codeDiscount {\n ... on DiscountCodeBasic {\n title\n codes(first: 10) {\n nodes {\n code\n }\n }\n startsAt\n endsAt\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"title\": \"Limited time discount off all items\",\n \"code\": \"BUYNOW20\",\n \"startsAt\": \"2024-06-21T00:00:00Z\",\n \"endsAt\": \"2024-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 CreateSummerDiscount($input: DiscountCodeBasicInput!) {\n discountCodeBasicCreate(basicCodeDiscount: $input) {\n codeDiscountNode {\n id\n codeDiscount {\n ... on DiscountCodeBasic {\n title\n codes(first: 10) {\n nodes {\n code\n }\n }\n startsAt\n endsAt\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n}" #### Graphql Input { "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": { "percentage": 0.2 }, "items": { "all": true } }, "appliesOncePerCustomer": true } } #### Graphql Response { "data": { "discountCodeBasicCreate": { "codeDiscountNode": { "id": "gid://shopify/DiscountCodeNode/1057371606", "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": [] } } }