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

Community site session details

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

Batch Post Using Custom API

(0) ShareShare
ReportReport
Posted on by 2
Hi All,
I am currently trying to implement a batch post for Sales Lines in Business Central. I created a custom Sales Lines Api, when I try to post I get the error ‘'POST' requests for 'companies' of EdmType 'Entity' are not allowed within Dynamics 365 Business Central OData web services.’. If I try to add ‘ODataEDMType = 'SalesLine';’ to the ‘SystemId’ field in the API then all my other custom APIs stop working, and I get the error ‘BadRequest_NotSupported’. Note, that the other APIs are not calling the same table (the Sales Line table) and they are all GET requests.
Any help on the matter would be greatly appreciated.
 
This is the endpoint being used 'https:/api.businesscentral.dynamics.com/v2.0/<tenant_id>/<environment_name>/api/<publisher>/Automation/v2.0/companies(<company_id>)/?batch'
 
and this is an example of the JSON
'{
/requests/: [
{
/id/: /r1/,
/method/: /POST/,
/url/: /salesHeaders(<sales_header_id>)/salesLines/,
/headers/: {
/Content-Type/: /application/json/
},
/body/: {
/quantity/: 1.0,
/unitPrice/: 4.11,
/discountPercent/: 10.0,
/description/: //,
/itemNumber/: /ITM-000001/,
/lineType/: /Item/,
/lineNumber/: 1,
/documentType/: /Order/,
/locationCode/: /WEST/,
/unitOfMeasure/: /PACK/
}
},
{
/id/: /r2/,
/method/: /POST/,
/url/: /salesHeaders(<sales_header_id>)/salesLines/,
/headers/: {
/Content-Type/: /application/json/
},
/body/: {
/quantity/: 1.0,
/unitPrice/: 4.11,
/discountPercent/: 10.0,
/description/: //,
/itemNumber/: /ITM-000002/,
/lineType/: /Item/,
/lineNumber/: 2,
/documentType/: /Order/,
/locationCode/: /WEST/,
/unitOfMeasure/: /PACK/
}
}
]
}'
I have the same question (0)
  • Inge M. Bruvik Profile Picture
    1,067 Moderator on at
    Batch Post Using Custom API
    Maybe you can try to share the code for the custom API that you are using? That will make it easier to assist you.
  • Community member Profile Picture
    2 on at
    Batch Post Using Custom API
    Sure this is the API I created, 
     
    page 60778 "API Sales Lines"
    {
        PageType = API;
        APIVersion = 'v2.0';
        APIPublisher = <Publisher>;
        APIGroup = 'Automation';
        EntityCaption = 'Sales Line';
        EntitySetCaption = 'Sales Lines';
        EntityName = 'salesLine';
        EntitySetName = 'salesLines';
        ODataKeyFields = SystemId;
        SourceTable = "Sales Line";
        Extensible = true;
        DelayedInsert = true;
        layout
        {
            area(content)
            {
                repeater(Group)
                {
                    field("Id"; Rec.SystemId)
                    {
                        Caption = 'Id';
                        ApplicationArea = All;
                        Editable = false;
                        // ODataEDMType =  'Collection(DIMENSION)';//Collection('sales');'SalesLines';
                    }
                    field("documentType"; Rec."Document Type")
                    {
                        ApplicationArea = All;
                        Editable = true;
                    }
                    field("documentNo"; Rec."Document No.")
                    {
                        ApplicationArea = All;
                        Editable = true;
                    }
                    field("lineType"; Rec.Type)
                    {
                        ApplicationArea = All;
                        Editable = true;
                    }
                    
                    field("description"; Rec.Description)
                    {
                        ApplicationArea = All;
                        Editable = true;
                    }
                    field("itemNumber"; Rec."No.")
                    {
                        ApplicationArea = All;
                        Editable = true;
                    }             
                    
                    field("discountPercent"; Rec."Line Discount %")
                    {
                        ApplicationArea = All;
                        Editable = true;
                    }
                    field(LocationId; LocationId)
                    {
                        ApplicationArea = All;
                        Editable = true;
                    }
                    field("locationCode"; Rec."Location Code")
                    {
                        ApplicationArea = All;
                        Editable = true;
                    }
                    field("reasonCode"; Rec."Return Reason Code")
                    {
                        ApplicationArea = All;
                        Editable = true;
                    }
                    field("CustomerPriceGroup"; Rec."Customer Price Group")
                    {
                        ApplicationArea = All;
                        Editable = true;
                    }
                   
                    field(DateCreated; Rec.SystemCreatedAt)
                    {
                        Caption = 'Id';
                        ApplicationArea = All;
                        Editable = false;
                    }
                    field(LastModified; Rec.SystemModifiedAt)
                    {
                        Caption = 'Id';
                        ApplicationArea = All;
                        Editable = false;
                    }
                    field(SystemCreatedBy; Rec.SystemCreatedBy)
                    {
                        Caption = 'Id';
                        ApplicationArea = All;
                        Editable = false;
                    }
                    field(SystemModifiedBy; Rec.SystemModifiedBy)
                    {
                        Caption = 'Id';
                        ApplicationArea = All;
                        Editable = false;
                    }
                    field("unitPrice"; Rec."Unit Price")
                    {
                        ApplicationArea = All;
                        Editable = true;
                    }
                }
            }
        }

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,351

#2
Sumit Singh Profile Picture

Sumit Singh 2,072

#3
YUN ZHU Profile Picture

YUN ZHU 1,807 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans