Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Unanswered

Batch Post Using Custom API

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/
}
}
]
}'
  • 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;
                    }
                }
            }
        }
  • Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 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.

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