<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Cannot access REST API via Javascript Client in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Cannot-access-REST-API-via-Javascript-Client/m-p/180872#M36282</link>
    <description>&lt;P&gt;Please help. Every time I am getting error message as "Error Listing Apps".&lt;/P&gt;</description>
    <pubDate>Tue, 18 Jul 2017 14:19:26 GMT</pubDate>
    <dc:creator>jitendra0101</dc:creator>
    <dc:date>2017-07-18T14:19:26Z</dc:date>
    <item>
      <title>Cannot access REST API via Javascript Client</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Cannot-access-REST-API-via-Javascript-Client/m-p/180867#M36277</link>
      <description>&lt;P&gt;Splunk 6.1.5&lt;/P&gt;

&lt;P&gt;Writing a test application for using REST API using Client JavaScript I got this error&lt;/P&gt;

&lt;P&gt;XMLHttpRequest cannot load &lt;A href="https://localhost:8089/services/auth/login?output_mode=json"&gt;https://localhost:8089/services/auth/login?output_mode=json&lt;/A&gt;. Request header field X-Splunk-Form-Key is not allowed by Access-Control-Allow-Headers.&lt;/P&gt;

&lt;P&gt;The app is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    var http = new splunkjs.JQueryHttp();

    var service = new splunkjs.Service(http,{
      scheme:"https",
      host: "localhost",
      port: 8089,
      username: "username",
      password: "password",
      version: "6.1"
    });

    service.apps().fetch(function(err, apps) {
        if (err) {
            alert("Error listing apps");
            return;
        }
        var myapps = "";
        var appsList = apps.list();
        for(var i = 0; i &amp;amp;lt; appsList.length; i++) {
            myapps += "App " + i + ": " + appsList[i].name + "&amp;amp;lt;br/&amp;amp;gt;"
        } 

        document.getElementById("applist").innerHTML=myapps;
    });
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In server.conf i enalbled cross origin&lt;/P&gt;

&lt;P&gt;[httpServer]&lt;BR /&gt;
crossOriginSharingPolicy = *&lt;/P&gt;

&lt;P&gt;(If I set crossOriginSharingPolicy = &lt;A href="https://localhost:8089"&gt;https://localhost:8089&lt;/A&gt; doesn't work)&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2015 14:24:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Cannot-access-REST-API-via-Javascript-Client/m-p/180867#M36277</guid>
      <dc:creator>Lyonis</dc:creator>
      <dc:date>2015-05-05T14:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot access REST API via Javascript Client</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Cannot-access-REST-API-via-Javascript-Client/m-p/180868#M36278</link>
      <description>&lt;P&gt;Have you managed to make this work? I believe a solution to this would really help me out.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jul 2015 07:50:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Cannot-access-REST-API-via-Javascript-Client/m-p/180868#M36278</guid>
      <dc:creator>Luke__Mcfly</dc:creator>
      <dc:date>2015-07-19T07:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot access REST API via Javascript Client</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Cannot-access-REST-API-via-Javascript-Client/m-p/180869#M36279</link>
      <description>&lt;P&gt;No sorry, I used a workaround creating a python controller that manager REST calls and use it like a forwarder that creates jobs&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jul 2015 08:09:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Cannot-access-REST-API-via-Javascript-Client/m-p/180869#M36279</guid>
      <dc:creator>Lyonis</dc:creator>
      <dc:date>2015-07-24T08:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot access REST API via Javascript Client</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Cannot-access-REST-API-via-Javascript-Client/m-p/180870#M36280</link>
      <description>&lt;P&gt;I know this is an old thread, but if someone is looking for a workaround, maybe they stumble upon this thread.&lt;/P&gt;

&lt;P&gt;I tried to make AJAX calls to the REST API from within dashboard javascript with the same result. Seems like jQuery is always adding the "x-splunk-form-key" header (I thinks thats the CSRF token for the webgui). Since this header is not allowed, it results in a CORS violation. Everything I tried with jQuery's $.ajax() failed (setting the header to "", " " or null). If you try to remove the header completely with ajaxSetup the gui will break &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;So the workaround I used was to use javascript's XmlHttpRequest object (var xhr = new XMLHttpRequest();). With this the header is not added and so the ajax request works like a charm.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2016 07:01:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Cannot-access-REST-API-via-Javascript-Client/m-p/180870#M36280</guid>
      <dc:creator>tfellinger</dc:creator>
      <dc:date>2016-11-02T07:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot access REST API via Javascript Client</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Cannot-access-REST-API-via-Javascript-Client/m-p/180871#M36281</link>
      <description>&lt;P&gt;I had a similar issue and solved by replacing:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var http = new splunkjs.JQueryHttp();
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;with&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var http = new splunkjs.SplunkWebHttp();
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Of course is not documented anywhere as far as I can tell.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2017 14:48:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Cannot-access-REST-API-via-Javascript-Client/m-p/180871#M36281</guid>
      <dc:creator>mgarciar</dc:creator>
      <dc:date>2017-01-11T14:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot access REST API via Javascript Client</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Cannot-access-REST-API-via-Javascript-Client/m-p/180872#M36282</link>
      <description>&lt;P&gt;Please help. Every time I am getting error message as "Error Listing Apps".&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 14:19:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Cannot-access-REST-API-via-Javascript-Client/m-p/180872#M36282</guid>
      <dc:creator>jitendra0101</dc:creator>
      <dc:date>2017-07-18T14:19:26Z</dc:date>
    </item>
  </channel>
</rss>

