I’m integrating with Dynamics 365 Business Central using the standard REST API v2.0.
**Issue:** When I create **purchase invoice lines** and include **locationId**, the line’s **unitCost** (Direct Unit Cost) ends up as **0** (or gets reset to 0), even though I send a non-zero value.
What I’m doing
1. Create Purchase Invoice header via API
2. Create Purchase Invoice line via API with a payload similar to:
This is expected with the standard BC v2.0 API—when you POST a purchase invoice line with itemId, quantity, and locationId, Business Central runs its normal validation logic (same as the UI) and recalculates Direct Unit Cost, which can overwrite the unitCost you send (often ending up as 0), especially since JSON field order isn’t guaranteed. The standard, supported workaround is to POST the line first with all “driver” fields (item, quantity, location, UoM), then PATCH the created line to set unitCost afterward; if even PATCH gets overridden, the only reliable solution is a custom API or custom action that controls the Validate() order and sets the cost last.
Regards,
Oussama Sabbouh
Was this reply helpful?YesNo
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.