AppD Archive

Problem using REST API from AJAX (CORS problem).

CommunityUser
Splunk Employee
Splunk Employee

Hi,

I'm trying to use the REST API from inside a webpage using AJAX, and I am facing a CORS problem.

I'm invoking the applications list using this url, (which works fine from a browser tab) :

https://mycompany.saas.appdynamics.com/controller/rest/applications?output=JSON

I am getting an http code 200, but with no Allow-Control-Allow-Origin header, so the browser is throwing this error :

XMLHttpRequest cannot load https://mycompany.saas.appdynamics.com/controller/rest/applications?output=JSON. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

What do I need to do to get the REST API working from within an html page?

(this is saas dedicated environment)

Thanks in advance

Andy_Czerwinski
Explorer

I have the same question. Has anyone built this from a browser webapp or are people using a proxy layer to get to the API's?

CommunityUser
Splunk Employee
Splunk Employee

Simply build the jar using "mvn package" at the command line. The jar is built to "target/smiley-http-proxy-servlet-VERSION.jar". You don't have to build the jar if you aren't modifying the code, since released versions are deployed to maven-central. If you are using maven then you can add this to your dependencies in your pom like so: (Note: the version below is not necessarily the latest.)

<dependency>
    <groupId>org.mitre.dsmiley.httpproxy</groupId>
    <artifactId>smiley-http-proxy-servlet</artifactId>
    <version>1.7</version>
</dependency>

Ivy and other dependency managers can be used as well.

0 Karma

CommunityUser
Splunk Employee
Splunk Employee

Hi,

maybe you post this message in the wrong thread?

best regards,

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Introduction to Splunk AI

How are you using AI in Splunk? Whether you see AI as a threat or opportunity, AI is here to stay. Lucky for ...

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...

Maximizing the Value of Splunk ES 8.x

Splunk Enterprise Security (ES) continues to be a leader in the Gartner Magic Quadrant, reflecting its pivotal ...