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...
Suggested Answer

Getting a valid Bearer Token from sharepoint in NAV 17

(0) ShareShare
ReportReport
Posted on by 20

Hello Experts,

Can you please help me to downgrade this Business Central AL Code to NAV17 ?

procedure GetToken() Token: text
    Var
        TypeHelper: Codeunit "Type Helper";
        client: HttpClient;
        cont: HttpContent;
        header: HttpHeaders;
        response: HttpResponseMessage;
        Jobject: JsonObject;
        tmpString: Text;
        granttype: text;
        clientid: text;
        ClientSecret: text;
        resources: text;
        RequestURI_L: Text;
        Jtoken: JsonToken;
        ResponseText: Text;
        tenant: Text;
    Begin
        SharepointSetup_L.Get(UserId);
        granttype := SharepointSetup_L."Grant Type";
        clientid := SharepointSetup_L.Client_Id   '@'   SharepointSetup_L.Tenant;
        ClientSecret := SharepointSetup_L."Client Secret";
        resources := SharepointSetup_L.Resources   '/'   SharepointSetup_L.Domain   '.sharepoint.com@'   SharepointSetup_L.Tenant;
        cont.WriteFrom('grant_type='   TypeHelper.UrlEncode(granttype)   '&client_id='
          TypeHelper.UrlEncode(clientid)   '&client_secret='   TypeHelper.UrlEncode(ClientSecret)
          '&resource='   TypeHelper.UrlEncode(resources)   '');
        cont.GetHeaders(header);
        header.Add('charset', 'UTF-8');
        header.Remove('Content-Type');
        header.Add('Content-Type', 'application/x-www-form-urlencoded');
        RequestURI_L := 'https://accounts.accesscontrol.windows.net/'   SharepointSetup_L.Tenant   '/tokens/oAuth/2';
        client.Post(RequestURI_L, cont, response);
        response.Content.ReadAs(ResponseText);
        Jobject.ReadFrom(ResponseText);
        Jobject.Get('access_token', Jtoken);
        Token := Jtoken.AsValue().AsText();
    end;

I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    95,729 Super User 2025 Season 2 on at

    Hi, hope the following can give you some hints.

    How can I get an access token from from Azure AD using NAV2017 — mibuso.com

    Thanks.
    ZHU

  • zizousa2 Profile Picture
    20 on at

    Thank you but can you help me to convert this code into C/AL NAV17 please, it will be used to generate a valid Bearer Access Token from Sharepoint to use it to list Sharepoint Library Files list in Navision Item Card in a spesific Listpart

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,362

#2
YUN ZHU Profile Picture

YUN ZHU 867 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 607

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans