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
