Discussing APIs and development related to customers, discounts, and order management.
Hey Everyone,
I noticed today that the line_items.total_discounts field is not populating when using the Order API. I know this worked in the past but when I associate any data to this field on the Order API, it does not show up on my order in my Shopify admin. The Order API documentation says this field is still writable and it should show up on my order.
I have multiple examples with the request id if that helps. The JSON request looks something like this.
{
"email": "example@example.com",
"currency": "USD",
"customer": {
"email": "example@example.com",
"first_name": "Led"
},
"tax_lines": [{
"rate": "0.05",
"price": 5.0,
"title": "State Tax"
}],
"total_tax": 5.0,
"line_items": [{
"sku": "1009-1001",
"price": 50.0,
"title": "Goblet of Fire",
"quantity": 1,
"total_discount": 5.0
}, {
"sku": "1009-3001",
"price": 25.0,
"title": "Golden Snitch",
"quantity": 2,
"total_discount": 5.0
}],
"send_receipt": false,
"transactions": [{
"amount": 120.75
}],
"discount_codes": [{
"code": "Coupon1",
"amount": 10.0
}],
"shipping_lines": [{
"price": 15.75,
"title": "Fedex Ground"
}],
"taxes_included": "False",
"billing_address": {
"zip": "2215",
"city": "Boston",
"country": "US",
"address1": "4 Yawkey Way",
"province": "MA",
"last_name": "Dent"
},
"note_attributes": [{
"name": "Delivery-Date",
"value": "2018/12/21"
}, {
"name": "Customer Note",
"value": "Thank You"
}, {
"name": "PO Number",
"value": "123"
}],
"total_discounts": 10.0,
"shipping_address": {
"zip": "2215",
"city": "Boston",
"country": "US",
"address1": "4 Yawkey Way",
"province": "MA",
"last_name": "Dent"
},
"buyer_accepts_marketing": "TRUE"
}
We have customers that rely the line item total_discounts while importing their orders so any help you can provide here would be greatly appreciated.
Thanks for all your help!
@Josh Is this something you could give us a hand with? We have a customer that is working on a migration to Shopify this week and he would like to import this data. The fields worked previously and the documentation still suggests that we should be able to write to the fields but it's not working. I have a bunch of tests with request ids that I've run if you need any more data.
Hey @Ralph-HA ,
When using the Shopify REST Admin API to create Orders and applying a fixed value discount via a discount code, I find the the discount applied to the line items does not appear "order.line_items.total_discounts" field (this field usually remains 0.00 when using the API), but rather the discount applied to the line items should appear in the "order.line_items.discount_allocations.amount" field. Feel free to check this value when you make orders with discounts and let me know if this helps provide the total discount applied per line item for you.
If you have evidence of cases where you use the Shopify REST Admin API to create Orders that have a fixed value discount via a discount code applied to it but the "order.line_items.total_discounts" field is not 0.00, then feel free to send me the X-Request-ID values and I would happily take a look for you.
To learn more visit the Shopify Help Center or the Community Blog.
Hi Hassain,
Ah okay! I see it in the order.line_items.discount_allocations. This is a bit confusing as the documentation does not mention this and I know in the past line item discounts were added to the order.line_items.total_discounts. Maybe it's something that can be updated on the Order Api docs?
It sounds as if the order.line_items.total_discounts can not be populated via the Order API. Is that correct? If not, what is this field used for and how does it get populated? Again there is very little information in the documentation about this.
Also, is there a way to display the line item discount on the Order admin? I know this is something that's bringing up confusion for us, so I suspect merchants are going to wonder why the discount does not show up on the line item after they've created the order with our app. Any insights you can provide here would be great.
Thanks for your help! I'm looking forward to hearing back from you.
Ralph
Hey @Ralph-HA ,
Happy I could help. I will try to answer your follow up questions as best that I can:
It sounds as if the order.line_items.total_discounts can not be populated via the Order API. Is that correct? If not, what is this field used for and how does it get populated? Again there is very little information in the documentation about this.
Yes, order.line_items.total_discounts can not be populated via the Order API. From my knowledge, this field is only ever populated from Shopify POS since this sales channel is capable of applying discounts specifically to line items in an order without the need to use a discount code (https://help.shopify.com/en/manual/sell-in-person/transactions/cart/discounts/line-item-pos-discount). I do agree however that our documentation could be better at explaining this.
Also, is there a way to display the line item discount on the Order admin?
Yes, but it depends on the type of discount applied. If the discount applied was intended to take money off of specific products/line items, the Shopify Web Admin will reflect that these line items were reduced from their original price. It would look like this:
However if the discount was applied to the whole order in general - even if in our internal API data models will calculate that overall discount split across the line items - our Shopify Web Admin will just show the discount taken off the total price and not demonstrate the line item discount. It would like this:
However in this case, if the merchant was really interested in seeing how Shopify split this overall discount was split against the line items, they could add the text ".json" to the end of the URL in their browser and see the API data model of this order.
To learn more visit the Shopify Help Center or the Community Blog.
Hi Hassain,
This is great! Thank you. Everything makes sense now, thanks for your help. I just have one final question.
I haven't been able to get the display working like this, https://screenshot.click/20-02-dc0i3-gvx3i.png using the order API. When I add the order.line_item.total_discounts everything looks good on the data side. I see everything as expected, however the display you linked to that crosses out the price does not show up on the Order. Since you say this depends on the type of discount provided, is there something else I need to do on the order API to make this work? Is it possible to have this display happen by simply adding the order.line_item.total_discounts? Is there something I would have to add to the original data I posted on this thread?
Thanks again!