Discussing APIs and development related to customers, discounts, and order management.
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.
Solved! Go to the solution
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!
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!