Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

OData Post with $expand

Posted on by 68

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.

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: OData Post with $expand

    Hi,

    Please follow the link with Custom API page.

    www.kauffmann.nl/.../

  • mjjoachim Profile Picture
    mjjoachim 68 on at
    RE: OData Post with $expand

    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.

  • Conor4C Profile Picture
    Conor4C 15 on at
    RE: OData Post with $expand

    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

  • Suggested answer
    mjjoachim Profile Picture
    mjjoachim 68 on at
    RE: OData Post with $expand

    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/.../

  • Suggested answer
    Marco Mels Profile Picture
    Marco Mels on at
    RE: OData Post with $expand

    Hello,

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

    Thanks.

  • mjjoachim Profile Picture
    mjjoachim 68 on at
    RE: OData Post with $expand

    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
    I Gusti Made Ari Profile Picture
    I Gusti Made Ari 3,594 on at
    RE: OData Post with $expand

    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
    }
    ]
  • Suggested answer
    Marco Mels Profile Picture
    Marco Mels on at
    RE: OData Post with $expand

    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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans