web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Business Central API v2.0: purchase invoice line unitCost resets to 0 when locationId is set

(1) ShareShare
ReportReport
Posted on by 2
Hi everyone,
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:
json
{
  "lineType": "Item",
  "itemId": "<item-guid>",
  "quantity": 1,
  "locationId": "<location-guid>",
  "unitCost": 12.34
}
 

Questions
1. Is it expected that setting `locationId` causes `unitCost` to be recalculated/overwritten on purchase invoice lines?
2. What’s the recommended approach to reliably set unit cost for item lines with a location (standard API only), or is a custom API/action required?
Any guidance or known limitations/bugs would be really appreciated.
Thanks!
 
Screenshot 2026-01-21 134615.png
I have the same question (0)
  • Suggested answer
    OussamaSabbouh Profile Picture
    7,654 on at
    Hello,
     
    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

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.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,472

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 742 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 684 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans