Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Setting Discounts Combinations by API REST

Solved

Setting Discounts Combinations by API REST

send4
Shopify Partner
2 0 2

Hello!

 

I’m writing to inquire about REST API and set discounts combinations.

 

I'm working on a project to create a discount (fixed_amount) and a discount (free shipping) by API Rest, and those discounts has to be avaliable to use in the same order.

 

However, I looked in API documentation how do set the combination by API and I haven't found how to do it.

 

Can I set this combination by API or it's available just from the administrative panel?

 

Best regards.

Accepted Solution (1)

kdub49
Visitor
1 1 1

This is an accepted solution.

I was having the same problem. It turns out shopify only allow for combination changes thgrough GraphQL.

Here you can find all the docs (look for what interest you on the left panel): https://shopify.dev/docs/api/admin-graphql/2023-10/mutations/priceRuleDiscountCodeUpdate?language=cU...

I changed the combination in the existing price rule using a POST request, like this (you must provide your: {your-development-store}, {access_token} and {priceRuleID})
curl -X POST \
https://{your-development-store}.myshopify.com/admin/api/2023-10/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation updatePriceRuleCombinesWith($id: ID!, $combinesWith: DiscountCombinesWithInput!) { priceRuleUpdate(id: $id, priceRule: { combinesWith: $combinesWith }) { priceRule { id combinesWith { productDiscounts orderDiscounts shippingDiscounts } } userErrors { field message } } }",
"variables": {
"id": "gid://shopify/PriceRule/{priceRuleID}",
"combinesWith": {
"productDiscounts": true,
"orderDiscounts": false,
"shippingDiscounts": true
}
}
}'

Hope it helps!

View solution in original post

Reply 1 (1)

kdub49
Visitor
1 1 1

This is an accepted solution.

I was having the same problem. It turns out shopify only allow for combination changes thgrough GraphQL.

Here you can find all the docs (look for what interest you on the left panel): https://shopify.dev/docs/api/admin-graphql/2023-10/mutations/priceRuleDiscountCodeUpdate?language=cU...

I changed the combination in the existing price rule using a POST request, like this (you must provide your: {your-development-store}, {access_token} and {priceRuleID})
curl -X POST \
https://{your-development-store}.myshopify.com/admin/api/2023-10/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation updatePriceRuleCombinesWith($id: ID!, $combinesWith: DiscountCombinesWithInput!) { priceRuleUpdate(id: $id, priceRule: { combinesWith: $combinesWith }) { priceRule { id combinesWith { productDiscounts orderDiscounts shippingDiscounts } } userErrors { field message } } }",
"variables": {
"id": "gid://shopify/PriceRule/{priceRuleID}",
"combinesWith": {
"productDiscounts": true,
"orderDiscounts": false,
"shippingDiscounts": true
}
}
}'

Hope it helps!