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

Bad Request in Post to Item Journal from Customized Table

(0) ShareShare
ReportReport
Posted on by 34

I am posting thousands of inventory from my Business Central customized table to Business Central Item Journal Odata Api through Rest and it does posting limited transaction while debuging in repeater but it stops at some 200 or 300 row of table with the error of 400 Bad Request, i wanted to know is thiis due to large no of records or what? and what is the solution?

My code:

   TblTestInventory.Init();
        TblTestInventory.Reset();
        TblTestInventory.SetRange(TblTestInventory.IsSync, false);
        TblTestInventory.SetRange(TblTestInventory.ERP_No, '');
        if TblTestInventory.find('-') then begin
            repeat begin
                Clear(JObject);
                Clear(jsonText);
                Clear(Content);
                Clear(ResponseMessage);

                ChecKtransid := TblTestInventory."Transaction id";

                batch := format(Date2DMY(TblTestInventory.BUSINESS_DATE, 2)) + '-' + FORMAT(TblTestInventory.BUSINESS_DATE, 0, '<Month Text,3>');

                JObject.Add('Journal_Template_Name', 'COGS');
                JObject.Add('Journal_Batch_Name', batch);
                JObject.Add('Posting_Date', TblTestInventory.BUSINESS_DATE);
                JObject.Add('Entry_Type', 'Sale');
                JObject.Add('Item_No', TblTestInventory.SKU);
                JObject.Add('Quantity', TblTestInventory.QUANTITY);
                JObject.Add('Location_Code', TblTestInventory.Location);
                JObject.Add('Shortcut_Dimension_1_Code', TblTestInventory.Location);
                JObject.Add('Shortcut_Dimension_2_Code', 'OPERATIONS');

                JObject.WriteTo(jsonText);
                Content.WriteFrom(jsonText);
                Content.GetHeaders(contentHeaders);
                contentHeaders.Remove('Content-Type');
                contentHeaders.Add('Content-Type', 'application/json');

                if not Http_Client.Post('api.businesscentral.dynamics.com/.../Company/----------------------/EVS_ItemJournalLine', Content, ResponseMessage) then
                    Error('The call to the web service failed.');
                if not ResponseMessage.IsSuccessStatusCode() then
                    Error('The web service returned an error message:\\' + 'Status code: ' + Format(ResponseMessage.HttpStatusCode()) + 'Description: ' + ResponseMessage.ReasonPhrase());

                // for is sync and document no
                if ResponseMessage.IsSuccessStatusCode() = true then begin
                    ResponseMessage.Content().ReadAs(responseString);
                    if Json_TokenR.ReadFrom(responseString) then begin
                        if Json_TokenR.IsObject then begin
                            Json_ObjectR := Json_TokenR.AsObject();
                            if GetResultJsonValue(Json_ObjectR, 'Document_No', Json_ValueR) then begin
                                TblTestInventory.ERP_No := Json_ValueR.AsText();
                            end;
                        end;
                    end;
                    TblTestInventory.IsSync := true;
                    TblTestInventory.Modify();
                end;
                // for is sync and document no

            end until TblTestInventory.Next = 0;
I have the same question (0)
  • Verified answer
    DAnny3211 Profile Picture
    10,139 Moderator on at
    RE: Bad Request in Post to Item Journal from Customized Table

    Hi

    if 200 or 300 rows are successful, it makes me think that there might be some error in the data in your custom table, also because it seems to me from your code that you make one call per row, so I don't think there are any limitations on the number of rows.

    Double-check the data in your table

    DAniele

  • Verified answer
    YUN ZHU Profile Picture
    88,163 Super User 2025 Season 2 on at
    RE: Bad Request in Post to Item Journal from Customized Table

    Hi, I also think it is a data problem. If it is a size limit, the error message is different.

    429 - Too Many Requests or 413: Request Entity Too Large.

    More details:

    https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/dynamics-current-limits

    Hope this helps as well.

    Thanks.

    ZHU

  • Abdul Mateen Profile Picture
    34 on at
    RE: Bad Request in Post to Item Journal from Customized Table

    Yes it's a data Problem. Thank 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

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

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

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans