Discussing APIs and development related to customers, discounts, and order management.
API: 2023-07
Use graphql
Query
mutation discountAutomaticBxgyCreate($automaticBxgyDiscount: DiscountAutomaticBxgyInput!) { discountAutomaticBxgyCreate(automaticBxgyDiscount: $automaticBxgyDiscount) { automaticDiscountNode { id automaticDiscount { ... on DiscountAutomaticBxgy { id createdAt startsAt endsAt status summary title usesPerOrderLimit customerGets { items { ... on DiscountProducts { products(first: 2) { nodes { id } } } } value { ... on DiscountOnQuantity { quantity { quantity } } } } customerBuys { items { ... on AllDiscountItems { allItems } } value { ... on DiscountQuantity { quantity } } } } } } userErrors { field code message } } }
Variables
{ "automaticBxgyDiscount": { "usesPerOrderLimit": "1", "startsAt": "2023-06-08T04:52:53-04:00", "title": "Minium 2tr get 1 A auto", "customerGets": { "value": { "discountOnQuantity": { "quantity": "2", "effect": { "percentage": 1.0 } } }, "items": { "products": { "productVariantsToAdd": ["gid://shopify/ProductVariant/45002547069218"] } } }, "customerBuys": { "value": { "amount": "2000000" }, "items": { "all": true } } } }
Response
{ "data": { "discountAutomaticBxgyCreate": { "automaticDiscountNode": null, "userErrors": [ { "field": [ "automaticBxgyDiscount", "customerBuys", "items" ], "code": "BLANK", "message": "Items in 'customer buys' must be defined" } ] } }, "extensions": { "cost": { "requestedQueryCost": 22, "actualQueryCost": 10, "throttleStatus": { "maximumAvailable": 1000.0, "currentlyAvailable": 990, "restoreRate": 50.0 } } } }
Hi Nnthuanspf,
Thanks for flagging this - will get in touch with the product team and see if this is expected behaviour and what the best process would be. What is the exact use case you are trying to achieve here?
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
Hi, @Liam, thanks for your feedback
I want to create a discount that applies to all products (buy), if the minimum price is reached, the customer will get a discount for a special product.
Hi,
I was having the same problem. The documentation does make it look like this should work, but if you try and do it in the admin UI you will also see that this is not possible.
The workaround is to create an "all products" collection (use automatic collection and where price > 0 for example), and then use this id in the collection.add
items: {
all:false,
collections:{
add:["gid://shopify/Collection/ALL_COLLECTION_ID"]
}
}