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

How to receive the correct access token?

(0) ShareShare
ReportReport
Posted on by 5

Im developing a React Expo app where im trying to access a BC page i've created.

Im able to get access to the page in Postman, but i'm unable to get access in my Expo app.

Here is my code:

    async function fetchToken(tenantId, clientId, clientSecret) {
        let token;

        try {
            const response = await fetch(`login.microsoftonline.com/${tenantId}/oauth2/token`, {
                method: "POST",
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded",
                },
                body:
                    "grant_type=client_credentials" +
                    "&scope=">api.businesscentral.dynamics.com/.default" +
                    "&client_id=" + clientId + "&client_secret=" + clientSecret,
            });

            if (!response.ok) {
                throw new Error(`Failed to fetch token: ${response.statusText}`);
            }

            token = await response.json();
            console.log(token);
        } catch (error) {
            console.error(error);
        }

        return token;
    }

TLDR:

I get the wrong access token, can you help me get the correct one?
I have the same question (0)
  • Jeremy Vyska Profile Picture
    727 on at

    Not sure if this guide will help, but it may relate?

    businesscentralgeek.com/how-to-use-postman-to-connect-with-business-central-apis

  • Nitin Verma Profile Picture
    21,708 Moderator on at

    Please use below syntax for your Body part

    grant_type=client_credentials

    &client_id=413ac35b-e0b6XXXXXXXXXXXXX-72f94d476bf8

    &scope=api.businesscentral.dynamics.com/.default

    &client_secret=9w38Q~PJoLaAsL.ObXXXXXXXXXXXLqIRpGAAb95blu

    header part

    Content-Type - application/x-www-form-urlencoded

  • Nitin Verma Profile Picture
    21,708 Moderator on at

    Also Create an entry in Azure Active directory application page in BC and enabled with your custom app.

    Thanks.

  • Reinert13 Profile Picture
    5 on at

    Do you mean like this?

    const response = await fetch(`login.microsoftonline.com/.../token`, {

                   method: "POST",

                   headers: {

                       "Content-Type": "application/x-www-form-urlencoded",

                   },

                   body:

                       "grant_type=client_credentials" +

                       "&client_id=xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxxxx" +

                       "&scope=api.businesscentral.dynamics.com/.default" +

                       "&client_secret=xxxxx~xxxxxxxxxxxxxxxxxxxx~xxxxxxxxxxxxx"

               });

    Because that didn't change anything

  • Nitin Verma Profile Picture
    21,708 Moderator on at

    Have you added in Azure active directly in BC?

    Also please refer the below link for app registration in Azure.

    www.navwithnav.com/.../

  • Reinert13 Profile Picture
    5 on at

    I followed you video and got a successful response from Postman, but somehow I still can't get it to work in my app. Using https://jwt.io I can see that the access token from Postman gives access to my tenant, but the access token from my app gives me access to Microsoft Graph.

    This is the response I get in the terminal:

    <error xmlns="docs.oasis-open.org/.../code><message>The credentials provided are incorrect</message></error>

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