<?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: Can I use REST API without curl? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Can-I-use-REST-API-without-curl/m-p/451681#M78306</link>
    <description>&lt;P&gt;Theoretically, you could generate a URL like this and run it in your browser - Splunk will prompt you to log in:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&lt;A href="https://xx.xx.xx.xx:xxxxx/services/search/jobs/export?output_mode=json&amp;amp;search=search%20index=xxx%20earliest=-15m%20latest=now%20%22xyz123%22|%20table%20c1,%20c2" target="test_blank"&gt;https://xx.xx.xx.xx:xxxxx/services/search/jobs/export?output_mode=json&amp;amp;search=search%20index=xxx%20earliest=-15m%20latest=now%20%22xyz123%22|%20table%20c1,%20c2&lt;/A&gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here is a jQuery AJAX example of how you can do API calls, although it's not recommended to do it this way because of the security concerns with passing a username and password through a browser. If you can generate your security token from a cURL call first, then pass that to the js script, that would be better. But for the sake of completeness:&lt;/P&gt;

&lt;P&gt;First, get the auth token:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var settings = {
  "url": "https://xx.xx.xx.xx:xxxxx/services/auth/login",
  "method": "POST",
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded"
  },
  "data": {
    "username": "myuser",
    "password": "mypw"
  }
}

$.ajax(settings).done(function (response) {
  var thisIsMyAuthToken = response; // this part needs refined to grab the sessionKey component
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then do the search request:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var settings = {
  "url": "https://xx.xx.xx.xx:xxxxx/services/search/jobs/export?output_mode=json&amp;amp;search=search%20index=xxx%20earliest=-15m%20latest=now%20%22xyz123%22|%20table%20c1,%20c2,
  "method": "GET",
  "headers": {
    "Authorization": "Splunk " +  thisIsMyAuthToken,
    "Content-Type": "application/x-www-form-urlencoded"
  }
}

$.ajax(settings).done(function (response) {
  console.log(response);
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This test was generated in Postman, which I highly recommend for any API testing. &lt;/P&gt;</description>
    <pubDate>Fri, 19 Jul 2019 23:06:05 GMT</pubDate>
    <dc:creator>jlemley</dc:creator>
    <dc:date>2019-07-19T23:06:05Z</dc:date>
    <item>
      <title>Can I use REST API without curl?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Can-I-use-REST-API-without-curl/m-p/451677#M78302</link>
      <description>&lt;P&gt;Is there a way I can make REST API calls to Splunk to run a search and return data on JSON via webservice rather than use curl?&lt;/P&gt;

&lt;P&gt;Basically, I need the HTTP URL equivalent for below that would work when invoked via javascript or when put into a browser: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;curl -u usr:psd -k &lt;A href="https://xx.xx.xx.xx:xxxxx/services/search/jobs/export" target="test_blank"&gt;https://xx.xx.xx.xx:xxxxx/services/search/jobs/export&lt;/A&gt; -d search="search index=xxx earliest=-15m latest=now "xyz123"| table c1, c2" -d output_mode=json
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Sep 2018 13:17:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Can-I-use-REST-API-without-curl/m-p/451677#M78302</guid>
      <dc:creator>pkd18</dc:creator>
      <dc:date>2018-09-07T13:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use REST API without curl?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Can-I-use-REST-API-without-curl/m-p/451678#M78303</link>
      <description>&lt;P&gt;The search &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/RESTREF/RESTsearch#search.2Fjobs.2Fexport"&gt;REST API reference manual&lt;/A&gt; describes two ways to use the jobs/export option&lt;/P&gt;

&lt;P&gt;Try for example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&lt;A href="https://localhost:8089/services/search/jobs/export?search=search" target="test_blank"&gt;https://localhost:8089/services/search/jobs/export?search=search&lt;/A&gt; index=_internal | head 1&amp;amp;output_mode=raw
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That worked for me.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 23:36:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Can-I-use-REST-API-without-curl/m-p/451678#M78303</guid>
      <dc:creator>gjanders</dc:creator>
      <dc:date>2018-09-07T23:36:57Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use REST API without curl?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Can-I-use-REST-API-without-curl/m-p/451679#M78304</link>
      <description>&lt;P&gt;how about the same URL with user credentials in calling this from Java without Splunk SDK??&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 12:00:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Can-I-use-REST-API-without-curl/m-p/451679#M78304</guid>
      <dc:creator>duddukuri</dc:creator>
      <dc:date>2019-07-19T12:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use REST API without curl?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Can-I-use-REST-API-without-curl/m-p/451680#M78305</link>
      <description>&lt;P&gt;how about the same URL with user credentials in calling this from Java without Splunk SDK??&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 12:00:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Can-I-use-REST-API-without-curl/m-p/451680#M78305</guid>
      <dc:creator>duddukuri</dc:creator>
      <dc:date>2019-07-19T12:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use REST API without curl?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Can-I-use-REST-API-without-curl/m-p/451681#M78306</link>
      <description>&lt;P&gt;Theoretically, you could generate a URL like this and run it in your browser - Splunk will prompt you to log in:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&lt;A href="https://xx.xx.xx.xx:xxxxx/services/search/jobs/export?output_mode=json&amp;amp;search=search%20index=xxx%20earliest=-15m%20latest=now%20%22xyz123%22|%20table%20c1,%20c2" target="test_blank"&gt;https://xx.xx.xx.xx:xxxxx/services/search/jobs/export?output_mode=json&amp;amp;search=search%20index=xxx%20earliest=-15m%20latest=now%20%22xyz123%22|%20table%20c1,%20c2&lt;/A&gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here is a jQuery AJAX example of how you can do API calls, although it's not recommended to do it this way because of the security concerns with passing a username and password through a browser. If you can generate your security token from a cURL call first, then pass that to the js script, that would be better. But for the sake of completeness:&lt;/P&gt;

&lt;P&gt;First, get the auth token:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var settings = {
  "url": "https://xx.xx.xx.xx:xxxxx/services/auth/login",
  "method": "POST",
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded"
  },
  "data": {
    "username": "myuser",
    "password": "mypw"
  }
}

$.ajax(settings).done(function (response) {
  var thisIsMyAuthToken = response; // this part needs refined to grab the sessionKey component
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then do the search request:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var settings = {
  "url": "https://xx.xx.xx.xx:xxxxx/services/search/jobs/export?output_mode=json&amp;amp;search=search%20index=xxx%20earliest=-15m%20latest=now%20%22xyz123%22|%20table%20c1,%20c2,
  "method": "GET",
  "headers": {
    "Authorization": "Splunk " +  thisIsMyAuthToken,
    "Content-Type": "application/x-www-form-urlencoded"
  }
}

$.ajax(settings).done(function (response) {
  console.log(response);
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This test was generated in Postman, which I highly recommend for any API testing. &lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 23:06:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Can-I-use-REST-API-without-curl/m-p/451681#M78306</guid>
      <dc:creator>jlemley</dc:creator>
      <dc:date>2019-07-19T23:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use REST API without curl?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Can-I-use-REST-API-without-curl/m-p/451682#M78307</link>
      <description>&lt;P&gt;By using the below implementation, able to query the &lt;STRONG&gt;Splunk with Rest API&lt;/STRONG&gt; without using Splunk Java SDK&lt;/P&gt;

&lt;P&gt;String uri = "https://****:8089/services/search/jobs/export?search=search  ID=d19b7c20-22e2-4832-883e-8df3907fedc0 |sort by fieldname  @timestamp";&lt;/P&gt;

&lt;P&gt;import org.springframework.http.ResponseEntity;&lt;BR /&gt;
import org.springframework.http.client.support.BasicAuthenticationInterceptor;&lt;BR /&gt;
import org.springframework.web.client.RestTemplate;&lt;BR /&gt;
import org.springframework.web.util.UriComponentsBuilder;&lt;/P&gt;

&lt;P&gt;public class RestSplunkClient{&lt;BR /&gt;
    public String get(String uri, String username, String password) {&lt;BR /&gt;
        RestTemplate restTemplate = new RestTemplate();&lt;BR /&gt;
        if(null!=username &amp;amp;&amp;amp; null!=password &amp;amp;&amp;amp; !username.isEmpty() &amp;amp;&amp;amp; !password.isEmpty()) {&lt;BR /&gt;
            restTemplate.getInterceptors().add(new BasicAuthenticationInterceptor(username, password));&lt;BR /&gt;
        }&lt;BR /&gt;
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(uri);&lt;BR /&gt;
        ResponseEntity&lt;STRING&gt; response =restTemplate.getForEntity(builder.build().toUriString(), String.class);&lt;BR /&gt;
        return response.getBody();&lt;BR /&gt;
    }&lt;BR /&gt;
}&lt;/STRING&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 08:20:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Can-I-use-REST-API-without-curl/m-p/451682#M78307</guid>
      <dc:creator>duddukuri</dc:creator>
      <dc:date>2019-07-23T08:20:53Z</dc:date>
    </item>
  </channel>
</rss>

