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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Business Central forum

Token for API

(0) ShareShare
ReportReport
Posted on by 449

Hello everyone,

How can i pass a token to consume .net API, through HttpClient in AL Extension.

Thanks!!!

Categories:
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,172 Most Valuable Professional on at

    Use the Authorization header and pass username and web service access key (generated from user card in D365BC). Something like (XXX is the base46 of 'user:web service access key' string):

    var

        strUrl: Text;

        client: HttpClient;

        reqHeaders: HttpHeaders;

        request: HttpRequestMessage;

        response: HttpResponseMessage;

    begin

        strUrl := 'https://APIAddress/token';

        request.SetRequestUri(strUrl);

        reqHeaders.Clear();

        request.GetHeaders(reqHeaders);

        request.Method := 'GET';

        reqHeaders.Add('authorization', 'Basic XXX');

        client.Send(request, response);

        response.Content().ReadAs(responseText);

     

    end;`

  • Manish Ratan Profile Picture
    449 on at

    Will try this and update you the result

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans