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 :
Finance | Project Operations, Human Resources, ...
Unanswered

Calling external webservice through X++ - OAuth 2.0 header

(0) ShareShare
ReportReport
Posted on by 150

Hi All,

I'm calling a web service through X++, but it's giving me 401 Unauthorized because of OAuth 2.0, can anyone please help me on adding the header authorization to my request. here is my code, note that i can make c# project and add it as a reference but im looking to have it here through X++ instead.

System.Net.HttpWebRequest webRequest;
System.IO.Stream stream;
System.Net.ServicePoint servicePt;
System.Text.Encoding utf8;
System.Byte[] bytes;
System.String sysString;
System.IO.StreamReader streamReader = null;

//For OAuth
str aadTenant;
str aadClientAppId;
str aadClientAppSecret;
str aadResource;


utf8 = System.Text.Encoding::get_UTF8();
bytes = utf8.GetBytes(jsonRequest);

clrObj = System.Net.WebRequest::Create(url);

webRequest = clrObj;
webRequest.set_Method('POST');
webRequest.set_KeepAlive(true);
webRequest.set_ContentType('application/json');
webRequest.set_ContentLength(bytes.get_Length());

servicePt = webRequest.get_ServicePoint();
servicePt.set_Expect100Continue(false);


stream = webRequest.GetRequestStream();
stream.Write(bytes,0,bytes.get_Length());
stream.Close();

I have the same question (0)
  • bankk Profile Picture
    6,611 on at
    Hi,
    Did you end up solving this issue through X++? I'm in the same boat and trying to figure out how to handle it. Thanks.
  • Martin Dráb Profile Picture
    238,751 Most Valuable Professional on at
    It doesn't matter whether you use C# or X++, because you use exactly the same classes. Classes like System.Net.HttpWebRequest are not specifying to AX, they're a part of .NET Framework. There a good idea is looking for a solution in C# (because you'll find many more resources than about X++) and then rewrite the code to X++ (or just call a C# library from X++ via .NET Interop).
     
    For example, you could borrow OAuthHelper class from F&O integration samples.
     
    Of course, you must already have an app registration in Azure AD (Entra).
     
    Note that capabilities of .NET Interop differs in AX versions, therefore mentioning your version may be important.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 510 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 399

#3
Adis Profile Picture

Adis 251 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans