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, ...
Answered

Rest API GET call JSON format using basic authentication in Dynamics 365

(0) ShareShare
ReportReport
Posted on by 505

Hi all,

I have Third-party application hosting REST API which returns JSON. I am consuming this service in D365.

For consuming I followed the blog https://rahulmsdax.blogspot.com/2018/12/rest-api-get-call-json-format-using.html

when I am trying to consume in Runnable class, I am getting exception when I am trying to get response from request

pastedimage1581002934345v1.png

pastedimage1581002951023v2.png

Exception is

Error executing code: Wrong argument type for function.

were as GetResponse() method, Do not expect any parameter.

I tried

1) clearing Usage Data

I have the same question (0)
  • nmaenpaa Profile Picture
    101,172 Moderator on at

    What is the type of your "response" variable?

  • Martin Dráb Profile Picture
    239,647 Most Valuable Professional on at

    The error isn't coming from GetResponse() - it's a bug in your error handling. strFmt() doesn't know what to do with the System.Exception object you're passing to it.

    By the way, there is a better solution for catching CLR exceptions:

    System.Net.WebException webException;
    
    try
    {
        ...
    }
    catch (webException)
    {
        ...
    }

    (This is new in F&O; it doesn't work in AX 2012 and older versions.)

  • Ishu.caddengg@hotmail.com Profile Picture
    505 on at

    Thanks Martin.

    This exception handling routed me with correct problem.

    pastedimage1581129827274v1.png

    It is giving the error for Authentication failed.

    If I am not wrong then it is looking for D365FO current user(this is because I am running in Client with Runnable class) is not able to login in third party application. That why I am getting this error.

    What is right way of doing it? Should I run on server then it will pick the user from IIS -->Application pool-->Identity? this IIS user should have rights in Third party application?

    Will it be same case in Azure environment of D365FO ? AS third party application will be residing locally only?

  • Martin Dráb Profile Picture
    239,647 Most Valuable Professional on at

    The RunOn property and client/server keywords in X++ have no meaning in F&O. Unlike in older versions, there is no client application running X++. All X++ code now executes on the web server.

    To be callable from cloud, the third-party must either be open to the internet or (which is safer) you'll need some kind of proxy (an example).

    I think you'll have to use explicit credentials when calling the service, because you have no controls over accounts of environments hosted by Microsoft. By the way, don't forget that Basic Authentication doesn't use encryption, therefore either build a secured channel or avoid Basic Authentication completely.

  • WillWU Profile Picture
    22,363 on at

    Hi partner,

    Do you mean that you want to integrate with third-party application?

    Before any apps can communicate with Dynamics 365 for Operations services, they must be registered in AAD.

    More information about registering applications in AAD here:

    https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app

    If you want to integrate data from external apps.

    You can also try BYOD and Azure Service Bus.

    Hope this helps.

  • Martin Dráb Profile Picture
    239,647 Most Valuable Professional on at

    Note that the last reply applies in the opposite case - if the external application called in F&O instead of F&O calling the app.

  • Ishu.caddengg@hotmail.com Profile Picture
    505 on at

    Hi Will,

    There is JSON REST API is exposed by Third party application. In D365 F&O, we have to consume it.

    First we have to do the same in IN House VM then we will move it to Azure.

    While doing the same in ON Premise, we are getting error for Authentication

    Now it is clear to do it in AZURE we have to register in AAD.

    Before that for ON Premise, I want to understand how the authentication take place.

    1) Is it mandatory to provide USER ID while consuming it ?

    2)If everything run on Web Server, it should take authentication from IIS App pool?

  • Ishu.caddengg@hotmail.com Profile Picture
    505 on at

    Hi Martin,

    I guess, I did not clear things from starting, please go through the below

    Sorry I am bit confuse with your reply

    There is JSON REST API is exposed by Third-party application. In D365 F&O, we have to consume it.

    First we have to do the same in IN House VM then we will move it to Azure.

    While doing the same in ON Premise, we are getting error for Authentication

    Now it is clear to do it in AZURE we have to register in AAD.(keeping this part aside for a while)

    Before that for ON Premise, I want to understand how the authentication take place.

    1) Is it mandatory to provide USER ID while consuming it ?

    2)If everything run on Web Server, it should take authentication from IIS App pool?

    3) What is the option available other than "Basic Authnetication"?

  • Martin Dráb Profile Picture
    239,647 Most Valuable Professional on at

    Yes, I understand your scenario - that's why I said what I said.

    You said that "Now it is clear to do it in AZURE we have to register in AAD", but that's far from clear. It would be true only if the third-party application required AAD authentication, but you never said anything like that. On the contrary, you're explicitly trying to use a different authentication mechanism than AAD.

    It seems to me that you're still confused by the information from Will, which doesn't apply in your case. It would be used if you called F&O API from outside - then you'd need AAD, because F&O API depends on AAD. But you're talking about calling the third-party API, not F&O API.

    Regarding your questions:

    1) Is it mandatory to provide USER ID while consuming it? No, it depends on the authentication mechanism used by the third-party application.

    2) f everything run on Web Server, it should take authentication from IIS App pool? No. as I said you have no control over these things and you can't depend on it. Even the assumption and the web server will be IIS may be wrong.

    3) What is the option available other than "Basic Authnetication"? There are many options in general, but it's not really the right question. You want to call an API of a specific third-party application and the question should be what this app supports. If what the app natively supports doesn't meet your needs, you could use some kind of middleware.

  • Ishu.caddengg@hotmail.com Profile Picture
    505 on at

    Thanks for the reply

    Out of curiousity again I am raising few question

    1) When I tried CONSUME web service of Third party app

         A) if we consume SOAP based --> D365FO was able to connect and read/respond the data

         b) if we consume REST API JSON --> D365FO is getting Authentication error(whose screenshot is attached in above trail).

    What could be the reason behind this?

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!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 698

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 698

#3
André Arnaud de Calavon Profile Picture

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans