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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

Making Custom API Work Dynamically Without Company ID in URL base on Boolean

(6) ShareShare
ReportReport
Posted on by 268
Hi Team,

I would like to understand how we can call a custom API (of type API Page) in Business Central without including the Company ID in the URL. Currently, we have created a custom API to create a Sales Order in Business Central from a third-party system. As per the standard format, we are required to mention the Company ID in the URL.

However, we want this API to work dynamically, so we don't have to hardcode or pass the Company ID manually in the API call.

For example, we are using the standard Companies API to retrieve the list of companies. In our setup, we want to maintain a Boolean field—if this Boolean is set to true for a particular company, then only that company should be allowed to create a Sales Order via the custom API from our .NET platform.

Is there any recommended approach or alternative to achieve this dynamic company selection without hardcode or pass the Company ID manually in the API call?
 
Thanks & Regards,
I have the same question (0)
  • Gerardo Rentería García Profile Picture
    27,261 Most Valuable Professional on at

    Hi, good day
    I hope this can help you, and give you some hints.

    Business Central API – leave out CompanyId from the URL

    Best Regards
    Gerardo

  • Suggested answer
    Ramesh Kumar Profile Picture
    7,561 Super User 2026 Season 1 on at
    Business Central use https://api.businesscentral.dynamics.com/v2.0/{tenantId}/sandbox/api/{publisher}/{group}/{version}/companies({companyId})/salesOrders  and company is scoped to mandatory.
     

    Use the companies endpoint to dynamically determine the company " This is what you’re already doing. Extend it like so:

    1. Call the GET /companies endpoint

    2. Filter the list based on your custom Boolean (e.g., "Enable External Order" = true)

    3. Extract the matching companyId

    4. Pass that companyId into your Sales Order creation call

    https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/webservices/api-overview

    https://www.waldo.be/2022/02/28/business-central-api-leave-out-companyid-from-the-url/

     

    Thanks, Ramesh

     

    If this was helpful, please check the "Does this answer your question?" box and mark it as verified.

     


       
     
     
  • Verified answer
    YUN ZHU Profile Picture
    101,995 Super User 2026 Season 1 on at
    Can't you just use Company ID as a variable in the code?
    Do not hard code the Endpoint. Write it in a format similar to the following so that you can pass in different Company IDs according to the situation.
    'https://api.businesscentral.dynamics.com/v2.0/c8558e71-6ad8-4fcd-9f29-3ca165b41bbe/Sandbox242/api/v1.0/companies(' + CompanyID + ')/'
     
    Hope this can give you some hints.
    Thanks.
    ZHU
  • CU08050848-0 Profile Picture
    268 on at

    Hello Ramesh Kumar,

    Thank you for your reply.

    In Business Central, the Company table is a system and virtual table, so it cannot be extended for create new custom Boolean . I have also tried creating a page extension for the Companies API and added a global variable, but that global variable is not appearing in the response when calling the standard API as per my research.

    How can we achieve this requirement?

  • CU08050848-0 Profile Picture
    268 on at
    Hello Yun Zhu,
     
    Thanks for replay and hints.
  • Suggested answer
    Jeffrey Bulanadi Profile Picture
    9,123 Super User 2026 Season 1 on at

    Hi,

    Hardcoding the Company ID in every API call can be a real blocker, especially when you're trying to build scalable integrations across tenants or environments. BC’s default API structure expects the company context in the URL, but there are a few ways to work around that.

    • This lets you omit the company segment from the URL entirely — the system will route requests to the default company. It’s clean, but only works if you’re okay with a single company context per NST.
    • One option is to leverage the ServicesDefaultCompany setting on the server. If you're running BC on-prem, you can configure this via PowerShell:
      Set-NAVServerConfiguration -KeyName "ServicesDefaultCompany" -KeyValue "CRONUS" -ServerInstance BC
      Set-NAVServerInstance -ServerInstance BC -Restart
      
    • For SaaS, unfortunately, this setting isn’t exposed. So your best bet is to use the Companies API to fetch the list dynamically, then filter based on your Boolean flag (e.g., AllowExternalAPI = true). From there, your .NET platform can select the correct company and inject it into the URL at runtime. It’s not as seamless, but it keeps things dynamic and avoids hardcoding.
    • If you’re building a custom API page, you can also consider exposing a wrapper endpoint via an unbound OData action or a proxy codeunit that handles the routing internally — though this requires more setup and doesn’t eliminate the need for company context entirely.


    Helpful Reference
    BC API – leave out CompanyId from the URL
    Developing a custom API – Microsoft Learn
    How To Create Custom APIs In BC – BC Geek


    If you find this helpful, feel free to mark this as the suggested or verified answer.

    Cheers
    Jeffrey

  • CU24071253-3 Profile Picture
    6 on at

    Hello Jeffrey,

    Thank you for your reply.

    In Business Central (SaaS), the Company table is a system and virtual table, so it cannot be extended for create new custom Boolean . I have also tried creating a page extension for the Companies API and added a global variable, but that global variable is not appearing in the response when calling the standard API as per my research.

     

  • Suggested answer
    Sohail Ahmed Profile Picture
    11,177 Super User 2026 Season 1 on at
    You can avoid hardcoding the company ID by using it as a variable in your code. Build the API endpoint dynamically
     
     
    ✅ Mark this answer as verified if it helps 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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,050 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,441 Super User 2026 Season 1

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 1,175 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans