I am trying to insert header and line data via the Business Central OData service in one request. I have the Purchase Order page exposed as a public web service. I am making a POST request to the OData service. I am sending the $expand argument like so:
/Sandbox/ODataV4/Company('CRONUS%20USA,%20Inc.')/PurchaseOrders?$expand=PurchaseOrdersPurchLines
This is the body of my request:
{
"Document_Type": "Order",
"Buy_from_Vendor_No": "10000",
"Document_Date": "2020-03-15",
"Payment_Terms_Code": "CM",
"Tax_Area_Code": "ATLANTA, GA",
"PurchaseOrdersPurchLines":
[
{
"Type": "Item",
"No": "1896-S",
"Quantity": 1
},
{
"Type": "Item",
"No": "1896-S",
"Quantity": 1
}
]
}
The purchase order is created, however, the created purchase order has no lines. The response shows the same:
"PurchaseOrdersPurchLines": []
If I change the case of the PurchaseOrdersPurchLines property I receive a BadRequest response with a message of "Does not support untyped value in non-open type." So I think the property name and case for the lines collection are correct.
If I change the value of the $expand argument to the name I have given the purchase order lines service (PurchaseOrderLines) I receive a BadRequest response with the message "Could not find a property named 'PurchaseOrderLines' on type 'NAV.PurchaseOrders'." So I believe the value of the $expand argument is correct.
If I change the case of the Type property to type on one of the lines I receive a BadRequest response with a message of "Does not support untyped value in non-open type." So Business Central does seem to be processing the lines.
I've tried to view the data in the table to see if there were orphaned lines that were created without a document number. I don't know if that's possible but I didn't see any.
Does anybody have any ideas why the lines are not being created? I get the same results trying to insert a purchase invoice and lines.