Is there a way to apply a pre-existing DiscountCode when creating an Order/DraftOrder using the API?
For example, I would expect to pass an id of an existing DiscountCode into an Order/DraftOrder and have it apply to the order based on the associated PriceRule. Just like we do with variant_id for lineItems. We are not forced to construct all the variant details when adding as a LineItem. Correct? What gives with DiscountCodes?
It appears we have to construct the all discount and price rule details as a custom object in the order every time. Tell me it ain't so! What good are DiscountCodes if they can't be pre-defined AND applied to orders with a simple reference to the DiscountCode. Am I missing something here?
Hi @Bill6 ,
That being said, what you are describing sounds like a use case for automatic discounts. You can check our examples here, if you're seeking a more automated approach this may be a better solution for your needs.
Hope this helps.
We do not want automatic discounts. That simply paints us into another corner. But thanks for confirming.
Just FYI, we want to simply create orders with the API that use pre-built discounts and have the discount usage tracked. So, you can see that the bigger problem is tracking the discount usage. You cant use "single-use" discounts or get any accurate metrics on discount usage. There is no way around this. Hopefully the Shopify API developers will recognize this as a design flaw and improve.
I expect that I am not the only API consumer that would like to create orders with the admin API and have the discount codes applied and tracked. This seems like a must have for anyone.
did you find any alternative to this problem, as I also want to apply discount codes when creating the order through api.
Hey @Bill6 and @Skylitech , thanks so much for these observations and feedback.
In the case of draft orders, the functionality will emulate what's available in the admin when creating draft orders where you can only apply a discount to the order, not a discount code. For tracking purposes, you may want to use an order attribute or tag to specify an equivalent discount code.
If you're importing orders through the REST api, you can reference the discount code that was used for the order (for tracking purposes) but you will still need to specify the amount and type in the transaction fields. The reason for that is you can specify any discount code that was used, it doesn't need to be an active code (important when importing orders from different sales channels or when migration from a different platform). The only time the discount code is calculated using the shops current active discount codes and price rules is when the order passes through checkout.
You can use the GraphQL cart or checkout endpoints through the Storefront API to apply a discount to an order so that they will be applied and calculated properly when the customer checks out.
Hope that helps clarify the limitations with discounts.
- Kyle G.
I'm a customer service manager and our company recently transitioned to Shopify. I'd like my agents to be able to use Draft Orders to take client orders over the phone as this would be much quicker than placing them on the front end of the site and we can easily associate them with client accounts this way. Clients could just provide the code they have to our agents over the phone and then the agent could enter this code into the draft order.
I'm trying to parse the above but what I think I've read is that there is not a way to apply an existing discount code to a draft order? We also need this for tracking purposes as well as removing manual error potential by entering an incorrect discount amount. Is there a plug in or app that you know of that would allow us to do this?
Hey @ffgamba7 thanks for sharing that additional context. The best solution here if you're on a Plus plan would be to look in to our B2B features as you can set up specific catalog and pricing for individual clients, eliminating the need for discount codes at all for them. https://help.shopify.com/en/manual/b2b
As for apps, searching for wholesale or b2b will return apps that are tailored to custom solutions for specific clients and pricing.
Hope that helps.
- Kyle G.