A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Solved! Go to the solution
This is an accepted solution.
Hi Rajith,
I was able to get something very similar to work with this mutation - you should be able to adjust it for your purpose:
mutation CreateDiscountCode {
discountCodeBasicCreate(
basicCodeDiscount: {
title: "20% off all products",
code: "DISCOUNT20",
startsAt: "2023-10-01T00:00:00Z",
endsAt: "2023-12-31T23:59:59Z",
customerSelection: {
customers: {
add: ["gid://shopify/Customer/12345678"]
}
},
customerGets: {
value: {
percentage: 0.2
},
items: {
all: true
}
},
appliesOncePerCustomer: true
}
) {
codeDiscountNode {
codeDiscount {
... on DiscountCodeBasic {
title
codes(first: 10) {
nodes {
code
}
}
startsAt
endsAt
customerSelection {
... on DiscountCustomers {
customers {
id
}
}
}
customerGets {
value {
... on DiscountPercentage {
percentage
}
}
items {
... on AllDiscountItems {
allItems
}
}
}
appliesOncePerCustomer
}
}
}
userErrors {
field
code
message
}
}
}
You just need to replace `gid://shopify/Customer/12345678` with `gid://shopify/Customer/81044372851254` and it should work.
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
This is an accepted solution.
Hi Rajith,
I was able to get something very similar to work with this mutation - you should be able to adjust it for your purpose:
mutation CreateDiscountCode {
discountCodeBasicCreate(
basicCodeDiscount: {
title: "20% off all products",
code: "DISCOUNT20",
startsAt: "2023-10-01T00:00:00Z",
endsAt: "2023-12-31T23:59:59Z",
customerSelection: {
customers: {
add: ["gid://shopify/Customer/12345678"]
}
},
customerGets: {
value: {
percentage: 0.2
},
items: {
all: true
}
},
appliesOncePerCustomer: true
}
) {
codeDiscountNode {
codeDiscount {
... on DiscountCodeBasic {
title
codes(first: 10) {
nodes {
code
}
}
startsAt
endsAt
customerSelection {
... on DiscountCustomers {
customers {
id
}
}
}
customerGets {
value {
... on DiscountPercentage {
percentage
}
}
items {
... on AllDiscountItems {
allItems
}
}
}
appliesOncePerCustomer
}
}
}
userErrors {
field
code
message
}
}
}
You just need to replace `gid://shopify/Customer/12345678` with `gid://shopify/Customer/81044372851254` and it should work.
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Thanks a lot brother. It worked for me.