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

The remote server returned an error: (403) Forbidden. while getting data from web app using API

(0) ShareShare
ReportReport
Posted on by 117

Hi All,

I am trying to get data using a client provided API. Postman shows data is coming from client app. I have created a batch job using Sys operation framework. Now, I am trying to info the same data that postman is showing me in its grid. After I hit OK button on my batch job, I get The Remore Server Returned an Error (403) Forbidden error. Can you please guide me what is the issue ?

I have tried to debug my code. The below mentioned code is what I received from debugger's StackTrace. Can you help me understanding what information it conveys. 

Name Value Type
StackTrace " at Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeInstanceCall(Object instance, String MethodName, Object[] parameters)\r\n at Microsoft.Dynamics.Ax.Xpp.DictClass.Callobject(String _methodName, XppObjectBase _Called, Object[] varArgs)\r\n at Dynamics.AX.Application.SysOperationServiceController.`runOperationInstance(SysOperationServiceController controller) in xppSource://Source/ApplicationFoundation\\AxClass_SysOperationServiceController.xpp:line 801\r\n at Dynamics.AX.Application.SysOperationServiceController.runOperationInstance(SysOperationServiceController controller)\r\n at Dynamics.AX.Application.SysOperationServiceController.`runOperationSynchronously() in xppSource://Source/ApplicationFoundation\\AxClass_SysOperationServiceController.xpp:line 721\r\n at Dynamics.AX.Application.SysOperationServiceController.runOperationSynchronously()\r\n at Dynamics.AX.Application.SysOperationServiceController.`run() in xppSource://Source/ApplicationFoundation\\AxClass_SysOperationServiceController.xpp:line 581\r\n at Dynamics.AX.Application.SysOperationServiceController.run()\r\n at Dynamics.AX.Application.SysOperationSandbox.`startOperation(SysOperationIMarshalledRun operationInstance) in xppSource://Source/ApplicationPlatform\\AxClass_SysOperationSandbox.xpp:line 100\r\n at Dynamics.AX.Application.SysOperationSandbox.startOperation(SysOperationIMarshalledRun operationInstance)\r\n at Dynamics.AX.Application.SysOperationServiceController.`runOperation() in xppSource://Source/ApplicationFoundation\\AxClass_SysOperationServiceController.xpp:line 548\r\n at Dynamics.AX.Application.SysOperationServiceController.runOperation()\r\n at Dynamics.AX.Application.SysOperationController.`startOperation() in xppSource://Source/ApplicationFoundation\\AxClass_SysOperationController.xpp:line 2034\r\n at Dynamics.AX.Application.SysOperationController.startOperation()\r\n at Dynamics.AX.Application.SysOperationServiceController.`startOperation() in xppSource://Source/ApplicationFoundation\\AxClass_SysOperationServiceController.xpp:line 896\r\n at Dynamics.AX.Application.SysOperationServiceController.startOperation()\r\n at Dynamics.AX.Application.APIDataConsumptionController.`main(Args _args) in xppSource://Source/SLDCustomizationSuite\\AxClass_APIDataConsumptionController.xpp:line 26\r\n at Dynamics.AX.Application.APIDataConsumptionController.main(Args _args)\r\n at APIDataConsumptionController::main(Object[] , Boolean& )\r\n at Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeStaticCall(Type type, String MethodName, Object[] parameters)" string

I have the same question (0)
  • 00030000036294D5 Profile Picture
    117 on at

    Sorry. I do not know what It is looking like this. Earlier, It was fine while I was writing.

    " at Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeInstanceCall(Object instance, String MethodName, Object[] parameters)\r\n at Microsoft.Dynamics.Ax.Xpp.DictClass.Callobject(String _methodName, XppObjectBase _Called, Object[] varArgs)\r\n at Dynamics.AX.Application.SysOperationServiceController.`runOperationInstance(SysOperationServiceController controller) in xppSource://Source/ApplicationFoundation\\AxClass_SysOperationServiceController.xpp:line 801\r\n at Dynamics.AX.Application.SysOperationServiceController.runOperationInstance(SysOperationServiceController controller)\r\n at Dynamics.AX.Application.SysOperationServiceController.`runOperationSynchronously() in xppSource://Source/ApplicationFoundation\\AxClass_SysOperationServiceController.xpp:line 721\r\n at Dynamics.AX.Application.SysOperationServiceController.runOperationSynchronously()\r\n at Dynamics.AX.Application.SysOperationServiceController.`run() in xppSource://Source/ApplicationFoundation\\AxClass_SysOperationServiceController.xpp:line 581\r\n at Dynamics.AX.Application.SysOperationServiceController.run()\r\n at Dynamics.AX.Application.SysOperationSandbox.`startOperation(SysOperationIMarshalledRun operationInstance) in xppSource://Source/ApplicationPlatform\\AxClass_SysOperationSandbox.xpp:line 100\r\n at Dynamics.AX.Application.SysOperationSandbox.startOperation(SysOperationIMarshalledRun operationInstance)\r\n at Dynamics.AX.Application.SysOperationServiceController.`runOperation() in xppSource://Source/ApplicationFoundation\\AxClass_SysOperationServiceController.xpp:line 548\r\n at Dynamics.AX.Application.SysOperationServiceController.runOperation()\r\n at Dynamics.AX.Application.SysOperationController.`startOperation() in xppSource://Source/ApplicationFoundation\\AxClass_SysOperationController.xpp:line 2034\r\n at Dynamics.AX.Application.SysOperationController.startOperation()\r\n at Dynamics.AX.Application.SysOperationServiceController.`startOperation() in xppSource://Source/ApplicationFoundation\\AxClass_SysOperationServiceController.xpp:line 896\r\n at Dynamics.AX.Application.SysOperationServiceController.startOperation()\r\n at Dynamics.AX.Application.APIDataConsumptionController.`main(Args _args) in xppSource://Source/SLDCustomizationSuite\\AxClass_APIDataConsumptionController.xpp:line 26\r\n at Dynamics.AX.Application.APIDataConsumptionController.main(Args _args)\r\n at APIDataConsumptionController::main(Object[] , Boolean& )\r\n at Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeStaticCall(Type type, String MethodName, Object[] parameters)"
  • Suggested answer
    huijij Profile Picture
    19,811 on at

    Hi 00030000036294D5,

    Please check if the accessToken is incorrect or invalid.You can follow the steps described in the below link:

    www.youtube.com/watch

  • AnithaEswaran Profile Picture
    2,032 on at

    Hi,

    While trying from postman, you would have passed the token or authentication keys ? Have you passed such authentication in your class?

  • 00030000036294D5 Profile Picture
    117 on at

    Hi Anitha,

                    Yes, It is using basic authentication and I have used username and password in my code. Let me share my code as well.

  • 00030000036294D5 Profile Picture
    117 on at

    System.Net.HttpWebRequest          request;
            System.Net.HttpWebResponse         response;
            System.Byte[]                      byteArray;
            System.IO.Stream                   dataStream;
            System.IO.StreamReader             streamRead;
            System.IO.StreamWriter             streamWrite;
            System.Net.ServicePoint            servicePoint;
            System.Net.ServicePointManager     servicePointmgr;
            System.Net.HttpVersion             version;
            CLRObject                          clrObj;
            Newtonsoft.Json.JsonReader         reader;
            System.Text.Encoding               utf8;
            Counter                            countCounter;
            Object                             obj;
            Map                                data;
            System.Byte[]                      byteArraynew;
            System.Net.WebHeaderCollection     headers = new System.Net.WebHeaderCollection();
         
            new InteropPermission(InteropKind::ClrInterop).assert();
      
            str  byteStr = strfmt('%1:%2', "USERNAME", "PASSWORD");
            
            headers  = new System.Net.WebHeaderCollection();
            url      = "http://dummy.restapiexample.com/api/v1/employees";
            clrObj   = System.Net.WebRequest::Create(url);
            request  = clrObj;
            request.set_Method("GET");
            request.set_KeepAlive(true);
            request.set_ContentType("application/json");
            utf8            = System.Text.Encoding::get_UTF8();
            byteArraynew    = utf8.GetBytes(byteStr);
            byteStr         = System.Convert::ToBase64String(byteArraynew);
    
            headers.Add("Authorization", 'Basic '   byteStr);
            request.set_Headers(headers);
    
            servicePoint = request.get_ServicePoint();
    
            System.Net.ServicePointManager::set_Expect100Continue(false);
            System.Net.ServicePointManager::set_SecurityProtocol(System.Net.SecurityProtocolType::Tls12);
    
            response    = request.GetResponse();
            dataStream  = response.GetResponseStream();
            streamRead  = new System.IO.StreamReader(dataStream);
            jsonString  = streamRead.ReadToEnd();
    
            info(strFmt("RESPONSE: %1",jsonString));
    
            dataStream.Close();
            response.Close();
        }

  • 00030000036294D5 Profile Picture
    117 on at

    On username and password, I am using credentials that are being used on postman. On URL, I am using the API url provided by the client. Is this code right ? please guide me .

  • 00030000036294D5 Profile Picture
    117 on at

    4048.PNG

  • 00030000036294D5 Profile Picture
    117 on at

    The above pic is what I am getting as an 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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans