Anchor to discountCodeBasicCreatediscount
discountCodeBasicCreate
mutation
Requires Apps must have access scope.
Creates an amount off discount 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.
Anchor to Arguments
Arguments
- Anchor to basicCodeDiscountbasic•
Code Discount DiscountCode requiredBasic Input! The input data used to create the discount code.
Was this section helpful?
Anchor to DiscountCodeBasicCreatePayload returnsDiscountCodeBasicCreatePayload returns
- Anchor to codeDiscountNodecode•
Discount Node The discount code that was created.
- Anchor to userErrorsuser•
Errors [DiscountUser non-nullError!]! The list of errors that occurred from executing the mutation.
Was this section helpful?
- Create a discount with a minimum purchase
- Create a limited time discount
- discountCodeBasicCreate reference
Examples
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 {
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
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-01/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
}
}
}'
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();
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
}
},
},
});
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)
Input 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
}
Response
JSON{
"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": []
}
}