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

API the server has rejected the client credentials

(0) ShareShare
ReportReport
Posted on by 15

Hi

I am trying to connect using IXMLHTTPRequest.

Open method works when I use these params

bstrUrl     'api.businesscentral.dynamics.com/.../beta',;
varAsync[optional]  false
bstrUser[optional]     <user name>
bstrPassword[optional]    <web service access key>

However when I add "/companies" to url, ie

bstrUrl     'https://api.businesscentral.dynamics.com/v1.0/****************************/Sandbox/api/beta/companies',;

it gives error "Authentication_InvalidCredentials - the server has rejected the client credentials"

it works fine in postman

I have the same question (0)
  • Bryanxxxx Profile Picture
    15 on at

    Please ignore this, it was just a syntax error

  • Marco Mels Profile Picture
    on at
  • Jhonatan Ramirez Profile Picture
    40 on at

    hi, could you share how did you solve it?

    I am in the same problem

    thanks in advance

  • Bryanxxxx Profile Picture
    15 on at

    Sorry it has been months since I worked on this, the project has been put on hold and I'm not able to reproduce the situation.

    Hopefully if you post details someone will be able to help.

  • Jhonatan Ramirez Profile Picture
    40 on at

    Hi thanks a lot for your answer, yes

    My steps:

    1. I created an app registration on Azure portal
      1.1. I added Business Central as API permission
      1.2. Created the secret key for that App registration.

    2. create a console application to get token:

    using System;
    using System.Threading.Tasks;
    using System.Net.Http;
    using System.Net.Http.Headers;
    using RestSharp;
    using Newtonsoft.Json;
    using AuthenticationContext = Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext;
    using Microsoft.IdentityModel.Clients.ActiveDirectory;

    namespace BCTestConnectApi
    {
    class BCAPIReq
    {
    static string resource = "https://api.businesscentral.dynamics.com";
    static string authorityUri = "https://login.microsoftonline.com/e53d2a55-6254-40d3-bf7e-6cb554a2s285";
    static string clientId = "d7f6b8e1-b3a0-4454-c4bb-fb8de6a3e2c5";
    static string clientSecret = "_9XPgsLAvoRNQR?WzbSASrDMjx4c6G82";
    static string accessToken = null;
    static string bcResponse;

    static void Main(string[] args)
    {
    ClientCredential clientCredential = new ClientCredential(clientId, clientSecret);
    var authenticationContext = new AuthenticationContext(authorityUriv2, true);
    AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(resource, clientCredential).GetAwaiter().GetResult();
    accessToken = authenticationResult.AccessToken;

    var clientBC = new RestClient("">api.businesscentral.dynamics.com/.../companies");
    clientBC.Timeout = -1;
    var requestBC = new RestRequest(Method.GET);
        requestBC.AddHeader("Content-Type", "application/x-www-form-urlencoded");
        requestBC.AddHeader("Authorization", "Bearer " + accessToken);
        requestBC.AddHeader("Accept", "*/*");
        requestBC.AddHeader("Cache-Control", "no-cache");
        requestBC.AddHeader("Host", "api.businesscentral.dynamics.com");
        requestBC.AddHeader("Accept-Encoding", "gzip, deflate, br");
        requestBC.AddHeader("Connection", "keep-alive");
        requestBC.AddParameter("application/x-www-form-urlencoded", "", ParameterType.RequestBody);
        IRestResponse responseBC = clientBC.Execute(requestBC);
        bcResponse = responseBC.Content;
        object resposeDataBC = JsonConvert.DeserializeObject(bcResponse);
    
        Console.Write(resposeDataBC);
        Console.ReadKey();
    }
    }


    But I received that credentials are not vaild, my app registration secret, are ok because I tested with postman and works, however here in my console is not working.

    Thanks a lot in advance for your help

     
  • Community Member Profile Picture
    on at

    Hi Jhonatan,

    i ran into the same issue. Make sure your Business Central is configured correctly.

    When you search for AAD - Azure Active Directory in Business Central add a new entry and include your App there and give it the nesessary permission for BC. I hope that helps.

  • Damjan Zakojc Profile Picture
    443 on at

    Hi,
    I have the same issue, where I extended standard table and displayed fields on the page as pageextension and then displayed those fields on ApiPage. Fields are displayed under the cloud flow in Power Automation and integration in the cloud flow works as expected. I just cannot figure out why my credentials are not accepted if I click on ODATA link of that on Web Service?
    pastedimage1641981251867v3.png

    pastedimage1641980894655v2.png

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 2,238

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 630

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans