<?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 Rest API and Jquery AJax Requests do not work in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Rest-API-and-Jquery-AJax-Requests-do-not-work/m-p/129617#M26612</link>
    <description>&lt;P&gt;I 've been trying to retrieve search results in json with no success.&lt;/P&gt;

&lt;P&gt;I'm able to retrieve the sessionKey but other POST and GET requests are unsuccessful &lt;/P&gt;

&lt;P&gt;I keep getting error: 401 Unauthorized.&lt;/P&gt;

&lt;P&gt;I'm running the code below in the node.js server that you can download with the splunk javascript sdk&lt;BR /&gt;
and I disabled ssl for the splunk management port 8089 under server.conf: &lt;/P&gt;

&lt;P&gt;[sslConfig]&lt;BR /&gt;
enableSplunkdSSL = false&lt;/P&gt;

&lt;P&gt;I'm shooting requests from the localhost:6969 to localhost:8089.&lt;/P&gt;

&lt;P&gt;Here is the code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$(function(){
    var $session_id = $('#session_id');
    var seid;
    $.ajax({
        method: 'POST',
        crossDomain: true,
        url: 'http://localhost:8089/servicesNS/admin/search/auth/login/',
        data: 'username=admin&amp;amp;password=splunk&amp;amp;output_mode=json',
        dataType: 'json',
        success: function(data){
            $session_id.append(data.sessionKey);
            seid=data.sessionKey;
            console.log('success',data.sessionKey,seid);
        }

    });


    $.ajax({
        type: 'GET',
        username: 'admin',
        password: 'splunk',
        crossDomain: true,
        url: 'http://localhost:8089/servicesNS/admin/search/',
        processData: false,
        dataType: 'json',
        success: function(data){
            console.log('success',data);
        }

    });

    $.ajax({
        type: 'POST',
        username: 'admin',
        password: 'splunk',
        headers: {'Authorization':' Splunk '+seid},
        crossDomain: true,
        url: 'http://localhost:8089/servicesNS/admin/search/search/jobs/',
        data: 'search="search error"',
        processData: false,
        dataType: 'json',
        success: function(data){
            console.log('success',data);
        }

    });
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have noticed that all code examples in the splunk documentation are bypassing the ssl self signed certificates of splunk. Is there a way to do that client side in Jquery or through some conf file on the server side?&lt;/P&gt;

&lt;P&gt;I have tried the curl command and I always get results with it: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;curl -u admin:changeme &lt;A href="http://localhost:8089/servicesNS/admin/search/" target="test_blank"&gt;http://localhost:8089/servicesNS/admin/search/&lt;/A&gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;with and without the -k (allow ssl sites without certificate).&lt;/P&gt;

&lt;P&gt;I'm not a developer and I really don't know where to continue.&lt;BR /&gt;
Can anyone point me in the right direction?&lt;/P&gt;</description>
    <pubDate>Sat, 18 Jul 2015 22:58:01 GMT</pubDate>
    <dc:creator>Luke__Mcfly</dc:creator>
    <dc:date>2015-07-18T22:58:01Z</dc:date>
    <item>
      <title>Rest API and Jquery AJax Requests do not work</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Rest-API-and-Jquery-AJax-Requests-do-not-work/m-p/129617#M26612</link>
      <description>&lt;P&gt;I 've been trying to retrieve search results in json with no success.&lt;/P&gt;

&lt;P&gt;I'm able to retrieve the sessionKey but other POST and GET requests are unsuccessful &lt;/P&gt;

&lt;P&gt;I keep getting error: 401 Unauthorized.&lt;/P&gt;

&lt;P&gt;I'm running the code below in the node.js server that you can download with the splunk javascript sdk&lt;BR /&gt;
and I disabled ssl for the splunk management port 8089 under server.conf: &lt;/P&gt;

&lt;P&gt;[sslConfig]&lt;BR /&gt;
enableSplunkdSSL = false&lt;/P&gt;

&lt;P&gt;I'm shooting requests from the localhost:6969 to localhost:8089.&lt;/P&gt;

&lt;P&gt;Here is the code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$(function(){
    var $session_id = $('#session_id');
    var seid;
    $.ajax({
        method: 'POST',
        crossDomain: true,
        url: 'http://localhost:8089/servicesNS/admin/search/auth/login/',
        data: 'username=admin&amp;amp;password=splunk&amp;amp;output_mode=json',
        dataType: 'json',
        success: function(data){
            $session_id.append(data.sessionKey);
            seid=data.sessionKey;
            console.log('success',data.sessionKey,seid);
        }

    });


    $.ajax({
        type: 'GET',
        username: 'admin',
        password: 'splunk',
        crossDomain: true,
        url: 'http://localhost:8089/servicesNS/admin/search/',
        processData: false,
        dataType: 'json',
        success: function(data){
            console.log('success',data);
        }

    });

    $.ajax({
        type: 'POST',
        username: 'admin',
        password: 'splunk',
        headers: {'Authorization':' Splunk '+seid},
        crossDomain: true,
        url: 'http://localhost:8089/servicesNS/admin/search/search/jobs/',
        data: 'search="search error"',
        processData: false,
        dataType: 'json',
        success: function(data){
            console.log('success',data);
        }

    });
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have noticed that all code examples in the splunk documentation are bypassing the ssl self signed certificates of splunk. Is there a way to do that client side in Jquery or through some conf file on the server side?&lt;/P&gt;

&lt;P&gt;I have tried the curl command and I always get results with it: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;curl -u admin:changeme &lt;A href="http://localhost:8089/servicesNS/admin/search/" target="test_blank"&gt;http://localhost:8089/servicesNS/admin/search/&lt;/A&gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;with and without the -k (allow ssl sites without certificate).&lt;/P&gt;

&lt;P&gt;I'm not a developer and I really don't know where to continue.&lt;BR /&gt;
Can anyone point me in the right direction?&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jul 2015 22:58:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Rest-API-and-Jquery-AJax-Requests-do-not-work/m-p/129617#M26612</guid>
      <dc:creator>Luke__Mcfly</dc:creator>
      <dc:date>2015-07-18T22:58:01Z</dc:date>
    </item>
    <item>
      <title>Re: Rest API and Jquery AJax Requests do not work</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Rest-API-and-Jquery-AJax-Requests-do-not-work/m-p/129618#M26613</link>
      <description>&lt;P&gt;I also altered the server.conf  &lt;/P&gt;

&lt;P&gt;[httpServer]&lt;BR /&gt;
crossOriginSharingPolicy = *&lt;/P&gt;

&lt;P&gt;Using the Chrome Advanced Rest Client I can also retrieve results. How come it's just not possible with jquery or javascript?&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jul 2015 14:00:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Rest-API-and-Jquery-AJax-Requests-do-not-work/m-p/129618#M26613</guid>
      <dc:creator>Luke__Mcfly</dc:creator>
      <dc:date>2015-07-19T14:00:22Z</dc:date>
    </item>
    <item>
      <title>Re: Rest API and Jquery AJax Requests do not work</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Rest-API-and-Jquery-AJax-Requests-do-not-work/m-p/129619#M26614</link>
      <description>&lt;P&gt;I know this is kind of an old thread and possibly too late, but here's an example showing how to get a session key and then list the installed apps. You will need to have a signed SSL certificate from a trusted CA installed or directly hit &lt;CODE&gt;&lt;A href="https://&amp;lt;splunk_server&amp;gt;:8089/services/auth/login" target="test_blank"&gt;https://&amp;lt;splunk_server&amp;gt;:8089/services/auth/login&lt;/A&gt;&lt;/CODE&gt; and accept the security exception for this to work.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var getSessionKey = $.ajax({
    type: "POST",
    url: "https://&amp;lt;splunk_server&amp;gt;:8089/services/auth/login",
    data: "username=admin&amp;amp;password=changeme",
}),
listApps = getSessionKey.then(function(data) {
    return $.ajax({
        type: "GET",
        url: "https://&amp;lt;splunk_server&amp;gt;:8089/services/apps/local",
        headers: {"Authorization" : "Splunk " + $(data).find("sessionKey").text()},
    });
});

listApps.done(function(data) {
    console.log(data);
});
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 May 2016 22:26:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Rest-API-and-Jquery-AJax-Requests-do-not-work/m-p/129619#M26614</guid>
      <dc:creator>shaskell_splunk</dc:creator>
      <dc:date>2016-05-03T22:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Rest API and Jquery AJax Requests do not work</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Rest-API-and-Jquery-AJax-Requests-do-not-work/m-p/129620#M26615</link>
      <description>&lt;P&gt;Nice, however this will not work if you use the regular webport and then get the rest api via this port using /splunkd/__raw/services/auth/login as it cannot handle the callback parameter &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;BR /&gt;
(I would like to use the regular port for a number of reasons, one being we do not open firewall access to the rest port and i also potentially would like to use sso).&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2016 15:42:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Rest-API-and-Jquery-AJax-Requests-do-not-work/m-p/129620#M26615</guid>
      <dc:creator>dominiquevocat</dc:creator>
      <dc:date>2016-11-29T15:42:48Z</dc:date>
    </item>
  </channel>
</rss>

