Order total is not updated after a new item is added by API

Hi,
I need to add a variable discount to an order. To do that I first insert the order with the bought products using “OrderService.placeOrder”
and then I add an OrderItem (the discount), of type 11 = Special: Order Total, to the order using “DataService.add”. The discount is correctly added to the order, in fact I find
the discount in the order summary in my dashboard, but the order total is wrong as it is not updated withe the value of the new item.
To fix the order total I have to click on the new item (the discount) in the Order Items and then simply click save in the “Order Item information” form.
In this way the order toal is correctly recalculated.

How can I add a new item to the order and then force the order total recalculation?

If you are adding items to the Order, then you need to be using the “addOrderItem” API function.

https://developer.infusionsoft.com/docs/xml-rpc/#invoice-add-an-item-to-an-invoice

That will recalculate the total for you.

There is also the “recalculateTax” function if you need to calculate the tax again.

https://developer.infusionsoft.com/docs/xml-rpc/#invoice-calculate-invoice-tax