question

saad_bin_iqbal avatar image
saad_bin_iqbal asked ·

I'm getting the Exception when I exchange the Item using exchangeItem() method of OrderConnector class. W/System.err: com.clover.sdk.v1.ClientException: status code: 400 cannot find lineItem with id:

Our goal is to exchange/replace the item with another one as per my requirement. Because we don't know all the details of the Item(here Fuel) so I add a similar Fuel Item to the Order and do payment. we try to exchange/replace Item for the correct one after Fuel is dispensed using already paid Order id. It works sometimes.

The code I'm using to exchange the item is as below

BPS_Application.getBPSApplicationInstance().getOrderConnector().exchangeItem(orderId, lineItemId, fuelReplacedID, "", "");

and I get the exception as
"10-15 11:16:33.336 32079-21162/com.bluepumpsoftware.application W/System.err: com.clover.sdk.v1.ClientException: status code: 400 cannot find lineItem with id: JWQ8JCVEWHJMT10-15 11:16:33.336 32079-21162/com.bluepumpsoftware.application W/System.err: at com.clover.sdk.v1.ServiceConnector.throwOnFailure(ServiceConnector.java:316)10-15 11:16:33.336 32079-21162/com.bluepumpsoftware.application W/System.err: at com.clover.sdk.v1.ServiceConnector.execute(ServiceConnector.java:249)10-15 11:16:33.336 32079-21162/com.bluepumpsoftware.application W/System.err: at com.clover.sdk.v3.order.OrderV31Connector.exchangeItem(OrderV31Connector.java:403)10-15 11:16:33.336 32079-21162/com.bluepumpsoftware.application W/System.err: at com.bluepumpsoftware.activities.BPS_HomeActivity$8$1.run(BPS_HomeActivity.java:1798)"

I also asked the question on the page
https://community.clover.com/questions/13887/comcloversdkv1clientexception-status-code-400-cann.html
Clover Android SDK
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Chanel avatar image
Chanel answered ·
Hi @saad_bin_iqbal. I haven't been able to reproduce your issue, but I believe I know what is happening.

You seem to have a race condition in your code. OrderConnector operates with data directly from Clover servers, so you may not be giving the device a chance to push the new item before you try to exchange it. I suggest using Clover Webhooks to listen for inventory updates (when a new item is created) and making sure that new item is accessible. Then send a notification to your app to let it know that it can go ahead with the exchange.
3 comments Share
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thanks @Chanel for your answer.

Actually, I don't create a new Item for exchange.

We have already Items sync with Clover and my device.

Here, There are all Item's Ids below we used to exchange the items by selecting any of these.

(H1MQKF89BWAJP, 069N54DGVEPAR, HYAMA7TMB82R8, 2WEEK6EVJJQT0, 5EYQKC79EBE3P, 379HJTASD7Y52, WF1C9ZZHVSPJA, 7CENFS1N5PKR2, X39JMSQB017E4, XP3H45WHXTVZW, BKVP8AJ70H9B2, KMY4QZG74MDDE, A50815GC3ZA80, DY730BB898WTC, RB7QN64AH5Z8M, S8ABFE3VZTWBW, NPFAKM9XKN5CE, 9HKTZ59M5A53P, JWQ8JCVEWHJMT, VPD1RJ8DRR02J)

and OrderConnector also provides the Item's Id when I go to exchange it.

And please also let me know how can I listen to Inventory updates?

0 Likes 0 · ·

Hi @Chanel , We analyzed the issue at my side and It seems to be happening due to data is not synched with/between clover and device as you said.

So could you please suggest me a way by which I could know when data is sync between Clover and my device so that I can exchange the Item at that time.

Please provide me some code snippet to listen the sync if possible.

Thanks in advance.

0 Likes 0 · ·

My apologies, but it looks like InventoryConnector doesn't have an onUpdateListener.

Instead, I suggest setting up Clover Webhooks and have an outside source listen for inventory updates. Once you've confirmed what items have been created/updated, you can then send a notification to your app to proceed with the exchange.

0 Likes 0 · ·

Welcome to the
Clover Developer Community