Development discussions around Shopify APIs
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
CS | API Support @ 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
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
CS | API Support @ 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
@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.
CS | API Support @ 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 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
User | RANK |
---|---|
10 | |
5 | |
3 | |
3 | |
3 |
Photo by Marco Verch Sales channels on Shopify are various platforms where you can sell...
By Ollie May 25, 2023Summary of EventsBeginning in January of 2023, some merchants reported seeing a large amo...
By Trevor May 15, 2023With 2-Factor Authentication being required to use Shopify Payments, we’re here to help yo...
By Imogen Apr 26, 2023