<?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: connecting Rest API from R in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/connecting-Rest-API-from-R/m-p/204019#M40278</link>
    <description>&lt;P&gt;&lt;CODE&gt;-d&lt;/CODE&gt; is to specify data for an HTTP POST body as is described in &lt;A href="http://curl.haxx.se/docs/manpage.html#-d"&gt;man curl&lt;/A&gt;. So you want to actually POST (not GET) a form with a search parameter set to the search you want to perform. &lt;/P&gt;

&lt;P&gt;You may also be interested in the &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.5/RESTREF/RESTsearch#search.2Fjobs"&gt;search REST API docs&lt;/A&gt; which go into detail about the GET and POST methods, as well as parameters that can be used with each. Also there are some &lt;A href="http://dev.splunk.com/restapi"&gt;tutorials&lt;/A&gt; that get into the different search modes and how to poll for results, and clean up jobs if needed.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;EDIT TO ADD: After figuring out how to download, install, and run R and and install install httr, could this give you a better starting point?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;install.packages("httr")
library(httr)
r &amp;lt;- POST(splunk_server, 
          path = "services/search/jobs",
          config( ssl_verifyhost = FALSE, ssl_verifypeer = 0),
          authenticate(username, password),
          encode = "form",
          body = list( search = "noop | stats count",
                       exec_mode = "oneshot",
                       output_mode = "json" ), 
          verbose())
stop_for_status(r)
content(r, "parsed", "application/json")$results
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Of course &lt;CODE&gt;splunk_server&lt;/CODE&gt; is the url to the API port (default: &lt;CODE&gt;&lt;A href="https://servername:8089" target="test_blank"&gt;https://servername:8089&lt;/A&gt;&lt;/CODE&gt;) and you'd of course fill in your own search for the search parameter (instead of my  count nothing: &lt;CODE&gt;noop | stats count&lt;/CODE&gt;, you'd likely have &lt;CODE&gt;search  | ...&lt;/CODE&gt;), and send along other parameters as needed from the REST API documentation as needed.&lt;/P&gt;</description>
    <pubDate>Thu, 03 Sep 2015 12:47:54 GMT</pubDate>
    <dc:creator>acharlieh</dc:creator>
    <dc:date>2015-09-03T12:47:54Z</dc:date>
    <item>
      <title>connecting Rest API from R</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/connecting-Rest-API-from-R/m-p/204018#M40277</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I am trying to perform search using rest api from R language.  This is the curl I am using which is available in splunk doc. &lt;/P&gt;

&lt;P&gt;curl -u admin:changeme -k &lt;A href="https://localhost:8089/services/search/jobs" target="_blank"&gt;https://localhost:8089/services/search/jobs&lt;/A&gt; -d search="search *"&lt;/P&gt;

&lt;P&gt;I am using httr GET method in R. Below is the sample code. When I use the curl I get a sid in response. But the same process when I run from R it returns all the search details. Not able to figure what I am missing out in below code.&lt;/P&gt;

&lt;P&gt;response &amp;lt;- GET(splunk_server,&lt;BR /&gt;
                   path=search_job_export_endpoint,&lt;BR /&gt;
                    config(ssl_verifyhost=FALSE, ssl_verifypeer=0),&lt;BR /&gt;
                   authenticate(username, password),&lt;BR /&gt;
                   query=list(search=urlencode(search_terms)),&lt;BR /&gt;&lt;BR /&gt;
                   verbose())&lt;/P&gt;

&lt;P&gt;What does -d in curl exactly do ?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:10:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/connecting-Rest-API-from-R/m-p/204018#M40277</guid>
      <dc:creator>debraj</dc:creator>
      <dc:date>2020-09-29T07:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: connecting Rest API from R</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/connecting-Rest-API-from-R/m-p/204019#M40278</link>
      <description>&lt;P&gt;&lt;CODE&gt;-d&lt;/CODE&gt; is to specify data for an HTTP POST body as is described in &lt;A href="http://curl.haxx.se/docs/manpage.html#-d"&gt;man curl&lt;/A&gt;. So you want to actually POST (not GET) a form with a search parameter set to the search you want to perform. &lt;/P&gt;

&lt;P&gt;You may also be interested in the &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.5/RESTREF/RESTsearch#search.2Fjobs"&gt;search REST API docs&lt;/A&gt; which go into detail about the GET and POST methods, as well as parameters that can be used with each. Also there are some &lt;A href="http://dev.splunk.com/restapi"&gt;tutorials&lt;/A&gt; that get into the different search modes and how to poll for results, and clean up jobs if needed.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;EDIT TO ADD: After figuring out how to download, install, and run R and and install install httr, could this give you a better starting point?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;install.packages("httr")
library(httr)
r &amp;lt;- POST(splunk_server, 
          path = "services/search/jobs",
          config( ssl_verifyhost = FALSE, ssl_verifypeer = 0),
          authenticate(username, password),
          encode = "form",
          body = list( search = "noop | stats count",
                       exec_mode = "oneshot",
                       output_mode = "json" ), 
          verbose())
stop_for_status(r)
content(r, "parsed", "application/json")$results
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Of course &lt;CODE&gt;splunk_server&lt;/CODE&gt; is the url to the API port (default: &lt;CODE&gt;&lt;A href="https://servername:8089" target="test_blank"&gt;https://servername:8089&lt;/A&gt;&lt;/CODE&gt;) and you'd of course fill in your own search for the search parameter (instead of my  count nothing: &lt;CODE&gt;noop | stats count&lt;/CODE&gt;, you'd likely have &lt;CODE&gt;search  | ...&lt;/CODE&gt;), and send along other parameters as needed from the REST API documentation as needed.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2015 12:47:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/connecting-Rest-API-from-R/m-p/204019#M40278</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2015-09-03T12:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: connecting Rest API from R</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/connecting-Rest-API-from-R/m-p/204020#M40279</link>
      <description>&lt;P&gt;Thanks for clarification. I am getting same result with POST as well.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2015 12:52:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/connecting-Rest-API-from-R/m-p/204020#M40279</guid>
      <dc:creator>debraj</dc:creator>
      <dc:date>2015-09-03T12:52:27Z</dc:date>
    </item>
  </channel>
</rss>

