Important Notice: New topic creation is now closed on this board, but you can still participate by replying to existing topics. For new topics, check out our newly refreshed Developer categories!

How do I apply line_item discount using REST Admin Order API

How do I apply line_item discount using REST Admin Order API

ikkifujiwara
Shopify Partner
4 0 2

Hi,

How can I apply discount on line_items when im create a new order using REST Admin Order API?

I've tried to set almost every possible keys available in the line_items. And my requirement must be an Order, not DraftOrder.

I've even tried to create first, then later update the line_items with discount but still no avail.

I'm open for GraphQL API solution as I'm using this package in my application >> https://github.com/MONEI/Shopify-api-node

Hope someone has done similar thing. Thanks

Replies 6 (6)

Luke_K
Shopify Staff
402 66 101

Hey there @ikkifujiwara 

I've looked into this and presently this is not possible using the Orders API. In Storefront API, (checkoutDiscountCodeApplyV2 mutation would apply an existing discount to a checkout) - that's seemingly the closest we've got to what you're looking for.

It's mentioned that Discounts can't be applied to specific items within an Order in the Orders CSV docs strangely enough, I'll look at getting this same mention into the API docs.

I've noted that there are other partners who are looking for the same functionality and I've made this known to the product team today. If there's any future updates, they'll be communicated via the Shopify Community forums and via our Developer Changelog. Hope that explains things at least!

| Shopify |
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
ikkifujiwara
Shopify Partner
4 0 2

@Luke_K 

thanks so much for your reply. i'm trying out your method and finger-crossed i can make it.

marnau
Shopify Partner
9 0 3

Hi @ikkifujiwara and @Luke_K . Thanks for exploring the possibilities.

I would appreciate if either of you could clarify how to go about creating and order and adding discounts to line items through APIs.

 

Would it be something like this?

1. Create an order through Admin API

2. Get its associated checkout id and apply discount codes through the Storefront API

 

My problem is that when I create an order, the checkout id is null, so I don't know how to do the second step.

 

Thanks a lot!

ShopifyDevSup
Shopify Staff
1453 238 501

Hi @marnau,

 

If you are importing completed orders with the REST Admin API directly into a store then there wouldn't be any checkout ID associated with it. 

If you are looking to use the Storefront API to build a customer's cart and apply discount codes, then your app should refer the customer to the checkout URL, where the Order will be created after their transaction is complete. 

 

The documentation on how to Create and update a cart with the Storefront API should help get started, then you would also need to use the cartDiscountCodesUpdate mutation before redirecting the customer.

 

All the best,

 

- James

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

marnau
Shopify Partner
9 0 3

Thanks a lot James! That helps

docasar
Shopify Partner
10 0 1

Hi, when we create and update a cart with the storefront API can we pass the processed_at date so the order is registered as when it took place in the past, since we are trying to import old orders into shopify, but the challenge is that old orders allowed for individual line_item discounts to be applied.