Why does BC include this blank record in the API response when it's not saved to the database?

I created custom API pages for Service Management in Business Central (Service Order, Service Item Line, Service Order Line) using standard BC tables.

 

The Problem

When I do a deep insert (POST with nested child records), the API response includes an extra blank child record that doesn't exist in the database.

Pattern:

  • Insert 1 Service Order Line → Response shows 2 (only 1 in database)
  • Insert 2 Service Order Lines → Response shows 3 (only 2 in database)

Details:

For the Service API, I linked Service Order to Service Item Line using Document No. and Document Type, and linked Service Item Line to Service Order Line using Document No., Document Type, and Line No. All these pages use PageType = API. Because I need to expand additional children for Service Order Line (for example, Reservation Entry and DimensionSetLine), I used this query:

baseUrl/serviceOrders?$expand=serviceItemLines($expand=serviceOrderLines)

The data returned for serviceOrder and serviceItemLines is correct, but the data in serviceOrderLines is incorrect, as I mentioned above.