[SOLVED] Why can't I delete an order item from an order when the order item was added through the API?

I’ve got a script setup to add additional order items to an order after a POST purchase process runs.

The new order items appear on the order exactly as desired, but you can’t delete them from the order.

I discovered this while trying to test my code.

When I try to delete any order item that was added through the API, I get the following message:

java.lang.IllegalArgumentException: id must be valid

Any one have any ideas?

… just to clarify, I’m not trying to delete from the API, but through the Order Editor itself.

Hi @Marion_Dorsett, I’m not familiar with the rules around orders but this sounds like it might be a bug. I would work with support to create a ticket for further investigation.

I have the same feeling, but you never now… Bug or Feature?

Thanks, I’ll put in a ticket.

The support ticket revealed the issue.

I used dsAdd() from the iSDK to add the order items… here’s the response:

Hi Marion,

I believe I’ve narrowed down the problem. It looks like when you use DataService.add instead of InvoiceService.addOrderItem, it does not automatically create a payment plan for the order. When you remove an order item via the front-end, it again automatically modifies the payment plan, but because there’s no pay plan to modify, it throws that error.

I would recommend using InvoiceService.addOrderItem instead of DataService, because that service will automagically interact with the necessary tables and get everything working cohesively.

Using addOrderItem () resolves the issue.