Can't seem to get discount applications on line items using rest order API

Topic summary

A developer is struggling to import orders with line-item-specific discounts via Shopify’s REST Order API. Despite three days of attempts, discount applications aren’t being preserved correctly.

The Issue:

  • POST requests include line items with total_discount, discount_allocations, and discount_applications fields properly structured
  • Each line item specifies discount amounts (e.g., $5.34, $8.66) with corresponding allocation indexes
  • The discount_applications array at the top level defines custom discounts with fixed amounts, targeting line items

What’s Happening:

  • Created orders return with modified discount data
  • The discount type changes from the original specification to “manual”
  • The discount description gets ignored entirely
  • Target selection changes from the intended value to different settings

Current Status:
The developer acknowledges the post is lengthy due to uncertainty about which details are relevant, suggesting they’re unsure what’s causing the API to reject or modify their discount configuration. They’re seeking guidance on what they might be doing wrong in their implementation.

Summarized with AI on November 9. AI used: claude-sonnet-4-5-20250929.

Greetings, all:

I’m trying to import orders from an existing (custom) system. Some orders have discounts that apply to one or more line items. I’ve been beating my head against the rest API for three days now, so I just know I’m doing something blatantly stupid.

I’m sorry for the length of what follows: I don’t know what’s relevant.

Here’s the body of the POST request:

{:browser_ip=>"68.53.113.90",
 :buyer_accepts_marketing=>false,
 :currency=>"USD",
 :email=>"dave+test@pragprog.org",
 :fulfillment_status=>"fulfilled",
 :gateway=>"unknown",
 :name=>"PIP-89977",
 :note_attributes=> [...],
 :order_number=>89977,
 :processed_at=>2008-05-15 17:57:18 -0500,
 :source_name=>"pip",
 :source_identifier=>181480,
 :tags=>"pip",
 :taxes_included=>false,
 :test=>true,
 :customer=> { ... },
 :line_items=>
  [{:fulfillable_quantity=>1,
    :fulfillment_status=>"fulfilled",
    :grams=>500,
    :product_id=>"fr_arr",
    :quantity=>1,
    :sku=>"FR_ARR-P-00",
    :title=>"Advanced Rails Recipes (electronic book)",
    :name=>"FR_ARR-P-00",
    :price=>"24.00",
    :total_discount=>5.34,
    :discount_allocations=>[{:amount=>5.34, :discount_application_index=>1}]},
   {:fulfillable_quantity=>1,
    :fulfillment_status=>"fulfilled",
    :grams=>500,
    :product_id=>"fr_arr",
    :quantity=>1,
    :sku=>"FR_ARR-B-00",
    :title=>"Advanced Rails Recipes (printed book)",
    :name=>"FR_ARR-B-00",
    :price=>"38.95",
    :total_discount=>8.66,
    :discount_allocations=>[{:amount=>8.66, :discount_application_index=>1}]}],
 :shipping_lines=>[{:price=>"6.75", :title=>"Shipping PRIORITY/FLATRATEENVELOPE"}],
 :transactions=>
  [{:gateway=>"Authorize.net",
    :processed_at=>2008-05-15 17:57:18 -0500,
    :amount=>55.7,
    :authorization=>nil,
    :kind=>"authorization",
    :status=>nil,
    :message=>"cc_trans.id: 39619: This transaction has been approved."},
   {:gateway=>"Authorize.net",
    :processed_at=>2008-05-16 09:54:29 -0500,
    :amount=>55.7,
    :authorization=>nil,
    :kind=>"capture",
    :status=>"success",
    :message=>"cc_trans.id: 39744: This transaction has been approved."}],
 :total_discounts=>14.0,
 :discount_applications=>
  [{:type=>"script",
    :description=>"Advanced Rails Recipes Combo Pack",
    :value=>14.0,
    :value_type=>"fixed_amount",
    :allocation_method=>"across",
    :target_selection=>"explicit",
    :target_type=>"line_item"}]}

But what comes back from the created order contains the following:

First, at the top level:

"discount_applications"=>
    [{"target_type"=>"line_item",
      "type"=>"manual",
      "value"=>"14.0",
      "value_type"=>"fixed_amount",
      "allocation_method"=>"across",
      "target_selection"=>"all",
      "title"=>"Custom discount",
      "description"=>"Custom discount"}],

Note that the type has been changed to manual, and the description in the original request has been ignored.

A line item from that same response looks like this:

{"id"=>13447041417402,
      "admin_graphql_api_id"=>"gid://shopify/LineItem/13447041417402",
      "attributed_staffs"=>[],
      "current_quantity"=>1,
      "fulfillable_quantity"=>0,
      "fulfillment_service"=>"manual",
      "fulfillment_status"=>"fulfilled",
      "gift_card"=>false,
      "grams"=>500,
      "name"=>"Advanced Rails Recipes (printed book)",
      "price"=>"38.95",
      "price_set"=>{"shop_money"=>{"amount"=>"38.95", "currency_code"=>"USD"}, "presentment_money"=>{"amount"=>"38.95", "currency_code"=>"USD"}},
      "product_exists"=>false,
      "product_id"=>nil,
      "properties"=>[],
      "quantity"=>1,
      "requires_shipping"=>true,
      "sku"=>"FR_ARR-B-00",
      "taxable"=>true,
      "title"=>"Advanced Rails Recipes (printed book)",
      "total_discount"=>"0.00",
      "total_discount_set"=>
       {"shop_money"=>{"amount"=>"0.00", "currency_code"=>"USD"}, "presentment_money"=>{"amount"=>"0.00", "currency_code"=>"USD"}},
      "variant_id"=>nil,
      "variant_inventory_management"=>nil,
      "variant_title"=>nil,
      "vendor"=>nil,
      "tax_lines"=>[],
      "duties"=>[],
      "discount_allocations"=>
       [{"amount"=>"8.66",
         "amount_set"=>{"shop_money"=>{"amount"=>"8.66", "currency_code"=>"USD"}, "presentment_money"=>{"amount"=>"8.66", "currency_code"=>"USD"}},
         "discount_application_index"=>0}]}],

Note that the total_discount field is zero. When I pull the order up in the admin app, I see the overall order discount, but nothing at the line item level:

I know I’m just being stupid: could someone tell me just how?

Thanks

Dave