Skip to main content

Notifications

Business Central forum
Answered

API call to Companies returns no result / unable to access company

Posted on by 85

Hello Experts,

I have an issue I hope you can help me with. I have an API call to try and get the list of companies in Business Central using an OAUTH2 token.

GET REQUEST from Postman: api.businesscentral.dynamics.com/.../<environment name>/api/v2.0/companies

When I send this request in postman I am getting a 200 OK response which is good, but there are no company values available to me. (the response reads "Value": []) In order to try and solve this issue I was playing around with connecting with Web Service Access Key and I was able to pull a list of production environments, so I thought maybe I could sneak by and enter the company as I already know it and try to access Companies(CompanyID)/customers but I got an error that I do not have access to the company.

I was wondering where I went wrong in setup? I have added my Azure AD app to Business Central in the Azure AD application card, Is it a problem with the user who is accessing the token? Are they unable to reach the company? truthfully, I am cobbling together my knowledge from lots of different MS articles that I have read on the subject and am a little out of my element.

If you can point me in the direction of the problem, and/or additional reading that will help me solve this issue, and get a better understanding of API and Business Central in general that would be much appreciated.

Thanks for your time,

Categories:
  • Suggested answer
    James_French Profile Picture
    James_French 85 on at
    RE: API call to Companies returns no result / unable to access company

    Hey ZHU, thanks for this. This was 100% the problem. I was SO SURE that this was already correct I never went back to double check. Thanks!

  • Verified answer
    YUN ZHU Profile Picture
    YUN ZHU 69,612 Super User 2024 Season 2 on at
    RE: API call to Companies returns no result / unable to access company

    Hi, It looks like you already have access to BC, but don't have access to all companies.

    Please check, is the Company Name set in the Azure Active Directory Application Card?

    pastedimage1642036758788v2.png

    Hope this will help.

    Thanks.

    ZHU

  • Suggested answer
    MahGah Profile Picture
    MahGah 15,419 on at
    RE: API call to Companies returns no result / unable to access company

    Hi

    Please see this article for OAUTH connection. I followed it before and had sucess https://yzhums.com/20690/

    I think code for company name is something like  api.businesscentral.dynamics.com/.../companies  which is v2.0/ environment  id / environment name  etc. 

    See this article for more info https://yzhums.com/6117/  specifically below section. 

    yzhums.com/.../

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,524 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,469 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans