A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hi,
Currently, all discount codes created via Discount APIs are working only for one-time purchases https://shopify.dev/api/admin/rest/reference/discounts
There is an option on Shopify Admin to change to "Both" - it means discount codes will work on subscriptions too.
I want to do this via API, but I cannot find the purchase type property on the PriceRule resource https://shopify.dev/api/admin/rest/reference/discounts/pricerule
It is possible to create a discount code via API which will work for one-time purchases and subscriptions too?
Solved! Go to the solution
This is an accepted solution.
Hi @falex28 and @Conjured_Char
It is possible to create discount codes which apply to subscriptions using the GraphQL API. If you're not yet familiar with the GraphQL API guide we have a helpful Getting Started guide
I was able to create a discount code which applies to both subscription orders and regular products using the following mutation:
mutation discountCodeBasicCreate($basicCodeDiscount: DiscountCodeBasicInput!) {
discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) {
codeDiscountNode {
id
}
userErrors {
code
extraInfo
field
message
}
}
}
with variables:
{
"basicCodeDiscount": {
"code": "TESTCODE",
"title": "testing subscription code creation",
"startsAt": "2021-07-03T20:47:55Z",
"customerSelection": {"all": true},
"customerGets": {
"items": { "collections":
{ "collectionIds": "gid:\/\/shopify\/Collection\/1234567890" }
},
"appliesOnSubscription": true,
"appliesOnOneTimePurchase": true,
"value": {
"discountAmount": {
"amount": 100,
"appliesOnEachItem": true
}
}
}
}
}
You can also check out the examples here - https://shopify.dev/api/examples/discounts You can add the "appliesOnSubscription" and "appliesOnOneTimePurchase" fields to the "customerGets" object shown in the example.
Here are the documentation pages relevant to the request:
DiscountCodeBasic - https://shopify.dev/api/admin/graphql/reference/discounts-and-marketing/discountcodebasic
discountCodeBasicCreate - https://shopify.dev/api/admin/graphql/reference/discounts-and-marketing/discountcodebasiccreate
DiscountCustomerGetsInput - https://shopify.dev/api/admin/graphql/reference/discounts-and-marketing/discountcustomergetsinput
To learn more visit the Shopify Help Center or the Community Blog.
I have the same problem/question and would love an answer. We've posted to the partner Slack and contacted Shopify support and were told to post here instead, but it looks like Shopify hasn't replied to any of the topics started with this question yet (over the last few months).
This is an accepted solution.
Hi @falex28 and @Conjured_Char
It is possible to create discount codes which apply to subscriptions using the GraphQL API. If you're not yet familiar with the GraphQL API guide we have a helpful Getting Started guide
I was able to create a discount code which applies to both subscription orders and regular products using the following mutation:
mutation discountCodeBasicCreate($basicCodeDiscount: DiscountCodeBasicInput!) {
discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) {
codeDiscountNode {
id
}
userErrors {
code
extraInfo
field
message
}
}
}
with variables:
{
"basicCodeDiscount": {
"code": "TESTCODE",
"title": "testing subscription code creation",
"startsAt": "2021-07-03T20:47:55Z",
"customerSelection": {"all": true},
"customerGets": {
"items": { "collections":
{ "collectionIds": "gid:\/\/shopify\/Collection\/1234567890" }
},
"appliesOnSubscription": true,
"appliesOnOneTimePurchase": true,
"value": {
"discountAmount": {
"amount": 100,
"appliesOnEachItem": true
}
}
}
}
}
You can also check out the examples here - https://shopify.dev/api/examples/discounts You can add the "appliesOnSubscription" and "appliesOnOneTimePurchase" fields to the "customerGets" object shown in the example.
Here are the documentation pages relevant to the request:
DiscountCodeBasic - https://shopify.dev/api/admin/graphql/reference/discounts-and-marketing/discountcodebasic
discountCodeBasicCreate - https://shopify.dev/api/admin/graphql/reference/discounts-and-marketing/discountcodebasiccreate
DiscountCustomerGetsInput - https://shopify.dev/api/admin/graphql/reference/discounts-and-marketing/discountcustomergetsinput
To learn more visit the Shopify Help Center or the Community Blog.
@csam Amazing, thanks so much for the reply! Is this an undocumented way of doing it? I don't see appliesOnSubscription listed on the basicCodeDiscount page you listed (https://shopify.dev/api/admin/graphql/reference/discounts-and-marketing/discountcodebasic)
Removed - figured it out!
It is documented, just a little tricky to find! The last link in the list shows DiscountCustomerGetsInput which has the fields that go in the customerGets section of discountCodeBasicCreate. appliesOnSubscription is one of the fields for DiscountCustomerGetsInput.
To learn more visit the Shopify Help Center or the Community Blog.
This doesn't work for me. I used to use the PriceRule API, but it doesn't work with Subscriptions. So I've switched to the Discount API, but:
https://community.shopify.com/c/shopify-apis-and-sdks/discount-api-problems/m-p/1403465#M74968