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

Query multiple companies in one API request

(0) ShareShare
ReportReport
Posted on by 55

Hi,

I have multiple companies that all have the same setup of custom APIs that give us some data we want. Is there a way to call all of the companies in one call to the API? Now I have 12 of them which all just use different company IDs.

I have the same question (0)
  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,105 Moderator on at

    You will have to get the companies and loop through them. Or you will have to create a custom api where the back-end code is doing the processing in all the companies using the ChangeCompany function. That is doable but the standard api only allows you to call one company at the time.

    docs.microsoft.com/.../dynamics_company_get

    docs.microsoft.com/.../devenv-develop-custom-api

  • RandomName Profile Picture
    55 on at

    Thx.

    Will try to create a page that gets data from all companies and then try to create an API page out of it.

    If anyone out there has an example of some simple code that does it for one field of one table that would be much apprecaited. I have done API pages before but they have all been very straightforward.

    /D

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,105 Moderator on at

    I do not think you should do this as an API page. It will be easier with a codeunit that you publish as web service through the web service page.

    That codeunit can take two or more parameters where parameter one can be the action you want to execute and the second one a list of companies you want to execute the action for.

    I created a very simple example here. You could feed this codeunit with a json dataset with all the companies you want to process and it can return a json dataset with all the company registration numbers.

    I did not put in the json pharsing, So you can't use it directly.

    codeunit 50100 MyApi
    {
        
        procedure preformaction(ActionType : Integer;CompanyList :Text) myText: Text[1024];
        var
        CompanyInfo : Record "Company Information";
        begin
    
    foreach companyName in companylist  do begin
            //loop through all the companies in the company list
            CompanyInfo.ChangeCompany('CompanyName');
            CompanyInfo.findset(false,false);
            myText  = CompanyInfo."Registration No.";
    end;
    
    
        end;
        
    }

  • Verified answer
    YUN ZHU Profile Picture
    95,331 Super User 2025 Season 2 on at

    Hi, I'm not sure what data you want to collect, another easy way is to create a page in BC that collects all company data when it opens, and then access it via a web service.

    Here is a simple example.

    https://yzhums.com/21252/

    Hope this helps as well.

    Thanks.

    ZHU

  • RandomName Profile Picture
    55 on at

    Thanks a lot.

    What I want to do is be able to get the general ledger data from 10 companies in one query. Im willing to sacrifice some performance if I dont have to make the same query 10 times.

    This is part of a very simple ETL flow for a basic DW solution so we would be pulling quite a lot of tables.

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 3,143

#2
Jainam M. Kothari Profile Picture

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

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans