Discussing APIs and development related to customers, discounts, and order management.
Hello,
I'm having trouble connecting discounts_applications to line_items in the Rest API (Orders API, Get Specific Order endpoint). Here's what I'm hoping to do in psuedocode.
If orders[x].discount_applications[y].title == "target value" then
runningDiscountTotal += orders[x].line_items[?].total_discount
The value for comparison only seems to be in the discount_allocations.title. The problem is the discount_applications and line_items are not necessarily in the same order and there doesn't seem to be a way to link them in the json. Is there a way to do what I'm looking for?
Solved! Go to the solution
This is an accepted solution.
Hi, @API_Ghost
As shown in the figure, the value of 'discount_application_index' can serve as a criterion for judgment.
This is an accepted solution.
Hi, @API_Ghost
As shown in the figure, the value of 'discount_application_index' can serve as a criterion for judgment.
This is exactly what I was looking for! Thank you!
is there a chance to get some code to see how you handle the line times? i try to get close to the sales report, but with refund etc it's a bit difficult for me. thanks for yout help @API_Ghost
Does this help?
i is the index from the initial for loop that looked for the title. If a match is found, it runs the below code.
//START MATCH PROCESSING ============================================
for (let j = 0; j < orderDetails.data.orders[orderIndexLocation].line_items.length; j++)
{
for (let k = 0; k < orderDetails.data.orders[orderIndexLocation].line_items[j].discount_allocations.length; k++)
{
if (orderDetails.data.orders[orderIndexLocation].line_items[j].discount_allocations[k].discount_application_index == i)
{
tempTotal += parseFloat(orderDetails.data.orders[orderIndexLocation].line_items[j].discount_allocations[k].amount)
}
}
}
//STOP MATCH PROCESSING =============================================