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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

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

(5) ShareShare
ReportReport
Posted on by 14
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)
  • Verified answer
    OussamaSabbouh Profile Picture
    11,500 Super User 2026 Season 1 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
  • Suggested answer
    Dhiren Nagar Profile Picture
    2,876 Super User 2026 Season 1 on at
    Hi,
     
    I have not tried this with my environment but here is a simple suggestion that if the unit cost is getting override, what you can do is first post the record with key fields. Then patch it with unit cost to update the value.
     
    This will help updated only unit cost in next API call.
     
    I hope this helps.
     
    Regards,
    Dhiren.

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

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,986 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,071 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 975 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans