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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

OData Post with $expand

(1) ShareShare
ReportReport
Posted on by 3

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.

I have the same question (0)
  • Suggested answer
    Marco Mels Profile Picture
    on at

    Hello,

    If you can provide a scenario in standard MSDyn365 BC, you may want to raise this issue via your CSP to Microsoft support.

    Thanks.

  • Suggested answer
    I Gusti Made Ari Profile Picture
    3,600 on at

    Hi, no need to use $expand . $expand is used to retrieve the data ( GET) in this case you want to retrieve header and lines in single call.

    For your case, i think is missing line no. so add this one  : 

    "PurchaseOrdersPurchLines":
    [
    {
    "Line_No" : 10000,
    "Type": "Item",
    "No": "1896-S",
    "Quantity": 1
    },
    {
    "Line_No" : 20000,
          "Type": "Item",
    "No": "1896-S",
    "Quantity": 1
    }
    ]
  • mjjoachim Profile Picture
    3 on at

    Thank you for the ideas. I tried removing the $expand argument from the POST request. The purchase order is created but the result seems to be the same. Unfortunately, no lines are created. I also tried specifying a value for the Line_No property for each line.

    Another clue I have found testing your ideas is that while the structure of the line items seems to be validated, the data is not. For example, I can pass "ZZ" for the line Type or No properties and I get no indication that the values were invalid.

  • Suggested answer
    Marco Mels Profile Picture
    on at

    Hello,

    If you can provide a scenario in standard, you may want to raise a support request.

    Thanks.

  • Suggested answer
    mjjoachim Profile Picture
    3 on at

    The response from Microsoft was that this is not possible via the OData service. They said it should be possible via the API though: docs.microsoft.com/.../

  • Conor4C Profile Picture
    15 on at

    Did you ever manage to get this to work? I am facing a similar issue with Sales Order. I am able to POST header and SalesOrderSalesLines data but in the response SalesOrderSalesLines is returned "SalesOrderSalesLines": [ ]. Please can someone provide assistance on this issue

  • mjjoachim Profile Picture
    3 on at

    I tried again a month or so ago and the result was the same. As far as I know, it is not possible with Web Services. It is only possible with API pages.

  • Suggested answer
    Nitin Verma Profile Picture
    21,708 Moderator on at

    Hi,

    Please follow the link with Custom API page.

    www.kauffmann.nl/.../

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

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 2,135

#2
YUN ZHU Profile Picture

YUN ZHU 733 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 612

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans