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 Sales order with lines

(1) ShareShare
ReportReport
Posted on by 15

I am trying to insert header and line data via the Business Central OData service in one request. I have the Sales Order page exposed as a public web service (ID 42). I am making a POST request to the OData service.

/Sandbox/ODataV4/Company('CRONUS Canada, Inc.')/SalesOrder

This is the body of my request:

{
    "Document_Type": "Order",
    "No": "",
    "Sell_to_Customer_No": "10000",
    "Sell_to_Customer_Name": "Adatum Corporation",
    "Quote_No": "",
    "Posting_Description": "Order S-ORD101001",
    "Sell_to_Address": "360 Main Street, Suite 1150",
    "Sell_to_Address_2": "",
    "Sell_to_City": "Winnipeg",
    "Sell_to_County": "MB",
    "Sell_to_Post_Code": "R3C 3Z3",
    "Sell_to_Country_Region_Code": "CA",
    "Sell_to_Contact_No": "CT000001",
    "Sell_to_Phone_No": "",
    "SellToMobilePhoneNo": "",
    "Sell_to_E_Mail": "robert.townes@contoso.com",
    "No_of_Archived_Versions": 0,
    "Document_Date": "2022-04-02",
    "Posting_Date": "2022-04-02",
    "Order_Date": "2022-04-02",
    "Due_Date": "2022-05-02",
    "Requested_Delivery_Date": "2022-04-03",
    "Promised_Delivery_Date": "0001-01-01",
    "External_Document_No": "",
    "Your_Reference": "OPEN",
    "ShpfyOrderNo": "",
    "ShpfyShopify_Risk_Level": " ",
    "Salesperson_Code": "JO",
    "Campaign_No": "",
    "Opportunity_No": "",
    "Responsibility_Center": "",
    "Assigned_User_ID": "CFORSEY",
    "Job_Queue_Status": " ",
    "CFDI_Purpose": "",
    "CFDI_Relation": "",
    "CFDI_Export_Code": "",
    "WorkDescription": "",
    "Currency_Code": "",
    "Company_Bank_Account_Code": "",
    "Prices_Including_VAT": false,
    "VAT_Bus_Posting_Group": "",
    "Payment_Terms_Code": "1M(8D)",
    "Payment_Method_Code": "",
    "EU_3_Party_Trade": false,
    "Tax_Liable": true,
    "Tax_Area_Code": "MB",
    "SelectedPayments": "No payment service is made available.",
    "Shortcut_Dimension_1_Code": "SALES",
    "Shortcut_Dimension_2_Code": "SMALL",
    "Payment_Discount_Percent": 2,
    "Pmt_Discount_Date": "2022-04-10",
    "Journal_Templ_Name": "",
    "Direct_Debit_Mandate_ID": "",
    "ShippingOptions": "Default (Sell-to Address)",
    "Ship_to_Code": "",
    "Ship_to_UPS_Zone": "",
    "Ship_to_Contact": "Robert Townes",
    "Shipment_Method_Code": "",
    "Shipping_Agent_Code": "FEDEX",
    "Shipping_Agent_Service_Code": "NEXT DAY",
    "Package_Tracking_No": "",
    "BillToOptions": "Default (Customer)",
    "BillToContactPhoneNo": "",
    "BillToContactMobilePhoneNo": "",
    "Location_Code": "",
    "Shipment_Date": "2022-06-02",
    "Shipping_Advice": "Partial",
    "Outbound_Whse_Handling_Time": "",
    "Shipping_Time": "1D",
    "Combine_Shipments": false,
    "Transaction_Specification": "",
    "Transaction_Type": "",
    "Transport_Method": "",
    "Exit_Point": "",
    "Area": "",
    "Language_Code": "ENC",
    "Prepayment_Percent": 0,
    "Compress_Prepayment": true,
    "Prepmt_Payment_Terms_Code": "1M(8D)",
    "Prepayment_Due_Date": "2022-05-02",
    "Prepmt_Payment_Discount_Percent": 2,
    "Prepmt_Pmt_Discount_Date": "2022-04-10",
    "Prepmt_Include_Tax": false,
    "Transit_to_Location": "",
    "Transport_Operators": 0,
    "Transit_from_Date_Time": "0001-01-01T00:00:00Z",
    "Transit_Hours": 0,
    "Transit_Distance": 0,
    "Vehicle_Code": "",
    "Trailer_1": "",
    "Trailer_2": "",
    "Control1310005": false,
    "Insurer_Name": "",
    "Insurer_Policy_Number": "",
    "Medical_Insurer_Name": "",
    "Medical_Ins_Policy_Number": "",
    "SAT_Weight_Unit_Of_Measure": "",
    "Date_Filter": "''..07/07/22",
    "SalesOrderSalesLines": [
        {
            "Document_Type": "Order",
            "Document_No": "",
            "Line_No": 10000,
            "Type": "Item",
            "FilteredTypeField": "Item",
            "No": "",
            "Item_Reference_No": "",
            "ShpfyOrderNo": "",
            "IC_Partner_Code": "",
            "IC_Partner_Ref_Type": " ",
            "IC_Partner_Reference": "",
            "IC_Item_Reference": "",
            "Variant_Code": "",
            "Substitution_Available": false,
            "Purchasing_Code": "",
            "Nonstock": false,
            "VAT_Prod_Posting_Group": "",
            "Description": "ATLANTA Whiteboard, base",
            "Description_2": "",
            "Drop_Shipment": false,
            "Special_Order": false,
            "Return_Reason_Code": "",
            "Package_Tracking_No": "",
            "Location_Code": "",
            "Bin_Code": "",
            "Control50": "Optional",
            "Quantity": 12,
            "Qty_to_Assemble_to_Order": 0,
            "Reserved_Quantity": 0,
            "Unit_of_Measure_Code": "PCS",
            "Unit_of_Measure": "Piece",
            "Unit_Cost_LCY": 1637.3,
            "SalesPriceExist": false,
            "Unit_Price": 2099.1,
            "Tax_Liable": true,
            "Tax_Area_Code": "MB",
            "Tax_Group_Code": "TAXABLE",
            "Line_Discount_Percent": 0,
            "Line_Amount": 25189.2,
            "Amount_Including_VAT": 28463.8,
            "SalesLineDiscExists": false,
            "Line_Discount_Amount": 0,
            "Prepayment_Percent": 0,
            "Prepmt_Line_Amount": 0,
            "Prepmt_Amt_Inv": 0,
            "Allow_Invoice_Disc": true,
            "Inv_Discount_Amount": 0,
            "Inv_Disc_Amount_to_Invoice": 0,
            "Qty_to_Ship": 12,
            "Quantity_Shipped": 0,
            "Qty_to_Invoice": 12,
            "Quantity_Invoiced": 0,
            "Prepmt_Amt_to_Deduct": 0,
            "Prepmt_Amt_Deducted": 0,
            "Allow_Item_Charge_Assignment": true,
            "Qty_to_Assign": 0,
            "Qty_Assigned": 0,
            "Requested_Delivery_Date": "2022-04-03",
            "Promised_Delivery_Date": "0001-01-01",
            "Planned_Delivery_Date": "2022-04-03",
            "Planned_Shipment_Date": "2022-04-02",
            "Shipment_Date": "2022-04-02",
            "Shipping_Agent_Code": "FEDEX",
            "Shipping_Agent_Service_Code": "NEXT DAY",
            "Shipping_Time": "1D",
            "Work_Type_Code": "",
            "Whse_Outstanding_Qty": 0,
            "Whse_Outstanding_Qty_Base": 0,
            "ATO_Whse_Outstanding_Qty": 0,
            "ATO_Whse_Outstd_Qty_Base": 0,
            "Outbound_Whse_Handling_Time": "",
            "Blanket_Order_No": "",
            "Blanket_Order_Line_No": 0,
            "FA_Posting_Date": "0001-01-01",
            "Depr_until_FA_Posting_Date": false,
            "Depreciation_Book_Code": "",
            "Use_Duplication_List": false,
            "Duplicate_in_Depreciation_Book": "",
            "Appl_from_Item_Entry": 0,
            "Appl_to_Item_Entry": 0,
            "Deferral_Code": "",
            "Shortcut_Dimension_1_Code": "SALES",
            "Shortcut_Dimension_2_Code": "SMALL",
            "ShortcutDimCode3": "",
            "ShortcutDimCode4": "",
            "ShortcutDimCode5": "",
            "ShortcutDimCode6": "",
            "ShortcutDimCode7": "",
            "ShortcutDimCode8": "",
            "Gross_Weight": 80.27,
            "Net_Weight": 69.8,
            "Unit_Volume": 0.31,
            "Units_per_Parcel": 0,
            "Retention_Attached_to_Line_No": 0,
            "Retention_VAT_Percent": 0,
            "Custom_Transit_Number": "",
            "TotalSalesLine_Line_Amount": 0,
            "Invoice_Discount_Amount": 0,
            "Invoice_Disc_Pct": 0,
            "Total_Amount_Excl_VAT": 0,
            "Total_VAT_Amount": 0,
            "Total_Amount_Incl_VAT": 0
        }
    ]
}


The sales order is created, however, the created sales order has no lines. The response shows the same:

"SalesOrderSalesLines": [

If I change the case of the SalesOrderSalesLines property I receive a BadRequest response with a message of "Invalid Request Body  CorrelationId:  def102fb-5140-43ff-8c9d-47cb1d9363fe." So I think the property name and case for the lines collection are correct.

Does anybody have any ideas why the lines are not being created?

This guy had a similar issue:    

Please do not link me to API v1.0 or v2.0 as I am aware they exist but I need to use OData calls.

I have the same question (0)
  • Suggested answer
    JAngle Profile Picture
    133 on at

    This might help: www.kauffmann.nl/.../

  • Conor4C Profile Picture
    15 on at

    Thank you for replying so quickly however, this does not work. I continue to get "SalesOrderSalesLines": [.

    This is how my URL looks: ODataV4/Company('CRONUS Canada, Inc.')/SalesOrder?$expand=SalesOrderSalesLines

    and the POST body:

    {
        "Document_Type": "Order",
        "No": "",
        "Sell_to_Customer_No": "10000",
        "Sell_to_Customer_Name": "Adatum Corporation",
        "Quote_No": "",
        "Posting_Description": "Order S-ORD101001",
        "Sell_to_Address": "360 Main Street, Suite 1150",
        "Sell_to_Address_2": "",
        "Sell_to_City": "Winnipeg",
        "Sell_to_County": "MB",
        "Sell_to_Post_Code": "R3C 3Z3",
        "Sell_to_Country_Region_Code": "CA",
        "Sell_to_Contact_No": "CT000001",
        "Sell_to_Phone_No": "",
        "SellToMobilePhoneNo": "",
        "Sell_to_E_Mail": "robert.townes@contoso.com",
        "No_of_Archived_Versions": 0,
        "Document_Date": "2022-04-02",
        "Posting_Date": "2022-04-02",
        "Order_Date": "2022-04-02",
        "Due_Date": "2022-05-02",
        "Requested_Delivery_Date": "2022-04-03",
        "Promised_Delivery_Date": "0001-01-01",
        "External_Document_No": "",
        "Your_Reference": "OPEN",
        "ShpfyOrderNo": "",
        "ShpfyShopify_Risk_Level": " ",
        "Salesperson_Code": "JO",
        "Campaign_No": "",
        "Opportunity_No": "",
        "Responsibility_Center": "",
        "Assigned_User_ID": "CFORSEY",
        "Job_Queue_Status": " ",
        "CFDI_Purpose": "",
        "CFDI_Relation": "",
        "CFDI_Export_Code": "",
        "WorkDescription": "",
        "Currency_Code": "",
        "Company_Bank_Account_Code": "",
        "Prices_Including_VAT": false,
        "VAT_Bus_Posting_Group": "",
        "Payment_Terms_Code": "1M(8D)",
        "Payment_Method_Code": "",
        "EU_3_Party_Trade": false,
        "Tax_Liable": true,
        "Tax_Area_Code": "MB",
        "SelectedPayments": "No payment service is made available.",
        "Shortcut_Dimension_1_Code": "SALES",
        "Shortcut_Dimension_2_Code": "SMALL",
        "Payment_Discount_Percent": 2,
        "Pmt_Discount_Date": "2022-04-10",
        "Journal_Templ_Name": "",
        "Direct_Debit_Mandate_ID": "",
        "ShippingOptions": "Default (Sell-to Address)",
        "Ship_to_Code": "",
        "Ship_to_UPS_Zone": "",
        "Ship_to_Contact": "Robert Townes",
        "Shipment_Method_Code": "",
        "Shipping_Agent_Code": "FEDEX",
        "Shipping_Agent_Service_Code": "NEXT DAY",
        "Package_Tracking_No": "",
        "BillToOptions": "Default (Customer)",
        "BillToContactPhoneNo": "",
        "BillToContactMobilePhoneNo": "",
        "Location_Code": "",
        "Shipment_Date": "2022-06-02",
        "Shipping_Advice": "Partial",
        "Outbound_Whse_Handling_Time": "",
        "Shipping_Time": "1D",
        "Combine_Shipments": false,
        "Transaction_Specification": "",
        "Transaction_Type": "",
        "Transport_Method": "",
        "Exit_Point": "",
        "Area": "",
        "Language_Code": "ENC",
        "Prepayment_Percent": 0,
        "Compress_Prepayment": true,
        "Prepmt_Payment_Terms_Code": "1M(8D)",
        "Prepayment_Due_Date": "2022-05-02",
        "Prepmt_Payment_Discount_Percent": 2,
        "Prepmt_Pmt_Discount_Date": "2022-04-10",
        "Prepmt_Include_Tax": false,
        "Transit_to_Location": "",
        "Transport_Operators": 0,
        "Transit_from_Date_Time": "0001-01-01T00:00:00Z",
        "Transit_Hours": 0,
        "Transit_Distance": 0,
        "Vehicle_Code": "",
        "Trailer_1": "",
        "Trailer_2": "",
        "Control1310005": false,
        "Insurer_Name": "",
        "Insurer_Policy_Number": "",
        "Medical_Insurer_Name": "",
        "Medical_Ins_Policy_Number": "",
        "SAT_Weight_Unit_Of_Measure": "",
        "Date_Filter": "''..07/07/22",
        "SalesOrderSalesLines": [
            {
                "Document_Type": "Order",
                "Document_No": "",
                "Line_No": 10000,
                "Type": "Item",
                "FilteredTypeField": "Item",
                "No": "",
                "Item_Reference_No": "",
                "ShpfyOrderNo": "",
                "IC_Partner_Code": "",
                "IC_Partner_Ref_Type": " ",
                "IC_Partner_Reference": "",
                "IC_Item_Reference": "",
                "Variant_Code": "",
                "Substitution_Available": false,
                "Purchasing_Code": "",
                "Nonstock": false,
                "VAT_Prod_Posting_Group": "",
                "Description": "ATLANTA Whiteboard, base",
                "Description_2": "",
                "Drop_Shipment": false,
                "Special_Order": false,
                "Return_Reason_Code": "",
                "Package_Tracking_No": "",
                "Location_Code": "",
                "Bin_Code": "",
                "Control50": "Optional",
                "Quantity": 12,
                "Qty_to_Assemble_to_Order": 0,
                "Reserved_Quantity": 0,
                "Unit_of_Measure_Code": "PCS",
                "Unit_of_Measure": "Piece",
                "Unit_Cost_LCY": 1637.3,
                "SalesPriceExist": false,
                "Unit_Price": 2099.1,
                "Tax_Liable": true,
                "Tax_Area_Code": "MB",
                "Tax_Group_Code": "TAXABLE",
                "Line_Discount_Percent": 0,
                "Line_Amount": 25189.2,
                "Amount_Including_VAT": 28463.8,
                "SalesLineDiscExists": false,
                "Line_Discount_Amount": 0,
                "Prepayment_Percent": 0,
                "Prepmt_Line_Amount": 0,
                "Prepmt_Amt_Inv": 0,
                "Allow_Invoice_Disc": true,
                "Inv_Discount_Amount": 0,
                "Inv_Disc_Amount_to_Invoice": 0,
                "Qty_to_Ship": 12,
                "Quantity_Shipped": 0,
                "Qty_to_Invoice": 12,
                "Quantity_Invoiced": 0,
                "Prepmt_Amt_to_Deduct": 0,
                "Prepmt_Amt_Deducted": 0,
                "Allow_Item_Charge_Assignment": true,
                "Qty_to_Assign": 0,
                "Qty_Assigned": 0,
                "Requested_Delivery_Date": "2022-12-12",
                "Promised_Delivery_Date": "2022-12-12",
                "Planned_Delivery_Date": "2022-12-12",
                "Planned_Shipment_Date": "2022-12-10",
                "Shipment_Date": "2022-12-10",
                "Shipping_Agent_Code": "FEDEX",
                "Shipping_Agent_Service_Code": "NEXT DAY",
                "Shipping_Time": "1D",
                "Work_Type_Code": "",
                "Whse_Outstanding_Qty": 0,
                "Whse_Outstanding_Qty_Base": 0,
                "ATO_Whse_Outstanding_Qty": 0,
                "ATO_Whse_Outstd_Qty_Base": 0,
                "Outbound_Whse_Handling_Time": "",
                "Blanket_Order_No": "",
                "Blanket_Order_Line_No": 0,
                "FA_Posting_Date": "0001-01-01",
                "Depr_until_FA_Posting_Date": false,
                "Depreciation_Book_Code": "",
                "Use_Duplication_List": false,
                "Duplicate_in_Depreciation_Book": "",
                "Appl_from_Item_Entry": 0,
                "Appl_to_Item_Entry": 0,
                "Deferral_Code": "",
                "Shortcut_Dimension_1_Code": "SALES",
                "Shortcut_Dimension_2_Code": "SMALL",
                "ShortcutDimCode3": "",
                "ShortcutDimCode4": "",
                "ShortcutDimCode5": "",
                "ShortcutDimCode6": "",
                "ShortcutDimCode7": "",
                "ShortcutDimCode8": "",
                "Gross_Weight": 80.27,
                "Net_Weight": 69.8,
                "Unit_Volume": 0.31,
                "Units_per_Parcel": 0,
                "Retention_Attached_to_Line_No": 0,
                "Retention_VAT_Percent": 0,
                "Custom_Transit_Number": "",
                "TotalSalesLine_Line_Amount": 0,
                "Invoice_Discount_Amount": 0,
                "Invoice_Disc_Pct": 0,
                "Total_Amount_Excl_VAT": 0,
                "Total_VAT_Amount": 0,
                "Total_Amount_Incl_VAT": 0
            }
        ]
    }

  • Suggested answer
    YUN ZHU Profile Picture
    95,597 Super User 2025 Season 2 on at

    Hi, As far as I know, this is an old question, we can't do it with Odata, we can only use Soap and API, it is recommended to use API

    https://stackoverflow.com/questions/53631543/creating-both-sales-header-and-sales-lines-in-one-call-i-nav-odata-rest-api

    Hope this helps.

    Thanks.

    ZHU

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

    Hi,

    I think you are using the standard api not the custom one, as JAngle mentioned the link

    www.kauffmann.nl/.../

    Kauffmann used the custom api page and how its working as he shown in the link, please follow that.

  • ballu Profile Picture
    45 on at

    Hi Conor4C , Were you able to find the Solution for this and able to insert Header and Line data in a single call through OData ?

  • Conor4C Profile Picture
    15 on at

    Hi Ballu, I was unable to find a solution to this and no one has provided any useful resources. As far as my research goes, it is currently not possible to create a sales order with line items in 1 OData call, as for why...who knows please someone enlighten me. As a work around I have used the V2 API to create the header data and then use OData calls to add additional header data and the line Items, which now uses up to 3 calls... If you find out anything please let me know.

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,917

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,161 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,025 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans