What's your biggest current challenge? Have your say in Community Polls along the right column.
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.

Applying discounts on line item level with order create API

Applying discounts on line item level with order create API

sanjeev_kmr
Tourist
7 0 1

How to apply discounts on line item level while creating an order using order create API? I have tried applying discounts on the specific line item with "total_discount","discount_allocations","total_discount_set"  fields. But once the order is created the discount is getting applied on an order level.

Replies 4 (4)

SBD_
Shopify Staff
1831 273 421

Hey @sanjeev_kmr,

 

Those fields are read-only. You'll want to apply a discount which affects the line items.

 

Alternatively, you can apply line item discounts using checkout API or draft order API.

Scott | Developer Advocate @ Shopify 

Nortski
Shopify Partner
20 0 5

Hi. What are the writable fields?

seshna
Shopify Partner
13 0 1

I just spent a LONG time trying to get it working.

 

The only way I could was to first created a Shopify Draft order, add an 'applied discount', then complete the draft order.

If you are using the shopify_api gem, it looks like this

order_params = { 
  line_items: [
    { 
      variant_id: 39304862138471, 
      quantity: 1, 
      applied_discount: { value_type: 'fixed_amount', value: '100', amount: '100' } 
    }] 
}
draft_shopify_order = ShopifyAPI::DraftOrder.new(order_params)
draft_shopify_order.save!
draft_shopify_order.complete({ payment_pending: true }) # because i dont want the status to be Paid
docasar
Shopify Partner
10 0 1

Hi, were you able to modify the processed_at order date? We need to import orders from other old websites, and we are having a very had time trying to figure out how to process those orders and keep the old line_itme discounts when those only applied to certain items within the order and not to the whole.