Unable to get OrderLineItem that has negative quantity

Hello! I’m trying to get all sold items in time interval but can’t get OrderLineItem that has negative quantity(returned goods).
I’m using SDK, Java 8.
square.getPaymentsApi().listPayments(…) →
→ square.getOrdersApi().batchRetrieveOrders(body)
→ Iterate over order.getLineItems() and lineItem.getQuantity()

There is no problem with getting of positive quantities. Is it possible to be included into response also OrderLienItem that has negative quantities?
Thank you!

Hey @Galin welcome to the forums! Can you provide your application ID as well as an example of an order ID you’re expecting to see in the response? Thanks!

Hi, Josh.

Our Production Application ID: sq0idp-vT1vg_OklnRCT2iweK29Fg

Iterating over com.squareup.square.models.Order and then “List of OrderLineItem lineItems”:
Order id: HIA0h78GjYcuOszy51iDCDgeV, product name ‘PEAK TICKET’, qty = 1
Order id: ziyG00fDaSWoGaj9wZwIXueeV, product name ‘PEAK TICKET’, qty = 1
So from this iteration I’m only receiving than these two items has been sold.
But these two items has been returned after that, our client tell us that because he can see this into his Square profile.
From where can I get that these two products has been returned?
I have checked also into “List of OrderReturn returns” but this is null.

Our client see this qty as negative value into table exported from Square system:

Many thanks!

:wave: With Square there is separate return order_id. This order will have the item detail if it was an itemized return from either the Dashboard or POS. For example the return order for ziyG00fDaSWoGaj9wZwIXueeV is RN48Rmwxi7Kt1twkPrMocl6eV. You can get this order by retrieving the refund for the payment by the refund_id. That response will have the refund order_id which will have the return order information. Also here is the documentation for Returns and Exchanges. :slightly_smiling_face:

1 Like

Many thanks, Bryan!
I have used square.getRefundsApi() for getting all PaymentRefunds in time interval → then square.getOrdersApi().batchRetrieveOrders(body) to get orders by ids → order.getReturns() iterate → currentReturn.getReturnLineItems() add them with negative sigh to sold items
So this solve my issue for getting all sold-returned items in period of time.