<?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: Splunk API: the proper way to run a saved search in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Splunk-API-the-proper-way-to-run-a-saved-search/m-p/106346#M22393</link>
    <description>&lt;P&gt;Looks like this post helped me get it right: &lt;A href="http://splunk-base.splunk.com/answers/50636/finding-specific-searches-in-splunk-via-rest-api-calls"&gt;http://splunk-base.splunk.com/answers/50636/finding-specific-searches-in-splunk-via-rest-api-calls&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;To trigger the search: &lt;CODE&gt;POST /services/saved/searches/MyCustomSearch/dispatch -d force_dispatch=true&lt;/CODE&gt;. The force_dispatch is optional.&lt;/P&gt;

&lt;P&gt;I can then poll the status of the returned SID (still to be tested)&lt;/P&gt;</description>
    <pubDate>Fri, 26 Apr 2013 07:58:32 GMT</pubDate>
    <dc:creator>brettcave</dc:creator>
    <dc:date>2013-04-26T07:58:32Z</dc:date>
    <item>
      <title>Splunk API: the proper way to run a saved search</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Splunk-API-the-proper-way-to-run-a-saved-search/m-p/106345#M22392</link>
      <description>&lt;P&gt;I have recently starting working on an integration with Splunk via the API, and am unclear on how to run a saved search - there are a number of ways it seems to do this, and so far my integration is triggering search jobs with no results.&lt;/P&gt;

&lt;P&gt;I have been using &lt;A href="http://splunk-base.splunk.com/answers/8945/how-to-start-a-saved-search-using-rest-api"&gt;http://splunk-base.splunk.com/answers/8945/how-to-start-a-saved-search-using-rest-api&lt;/A&gt; and &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTsearch#saved.2Fsearches"&gt;http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTsearch#saved.2Fsearches&lt;/A&gt; for reference. From this, it seems like an effective way of searching is:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Authenticate and get a session ID&lt;/LI&gt;
&lt;LI&gt;Create the Authorization header from the authentication request&lt;/LI&gt;
&lt;LI&gt;POST to the search/jobs endpoint to schedule a search job&lt;/LI&gt;
&lt;LI&gt;Poll the search/jobs/jobId to wait for it to finish (GET, and grab the dispatchState element)&lt;/LI&gt;
&lt;LI&gt;Retrieve the results via search/jobs/jobId/results&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;In Step 3, I am posting the following body to "/services/search/jobs" (not using /serviceNS/myUsername/...):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search=savedsearch MyCustomSearch
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If I log into the job manager, I can see the job. There's a large number of events matched, but no results. So then I thought I would try a Web UI search - I have tried the following 2 variations:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| savedsearch MyCustomSearch
| savedsearch "MyCustomSearch"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But both of those searches return no results. However, I can click the saved search from the "Searches &amp;amp; Reports" menu and get valid results. When I do that, I get the following URI that loads:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;/en-US/app/search/flashtimeline?s=%2FservicesNS%2Fnobody%2Fsearch%2Fsaved%2Fsearches%2FMyCustomSearch
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And this load the correct results.&lt;/P&gt;

&lt;P&gt;When I look at the job manager, I see 2 variations on the search that don't work.&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;| savedsearch "MyCustomSearch" events: correct number of events, but no results, triggered by either the API call or by manually quering &lt;CODE&gt;| savedsearch MyCustomSearch&lt;/CODE&gt;.&lt;/LI&gt;
&lt;LI&gt;MyCustomSearch events: correct number of events, and correct results, triggered by clicking the report in the Web UI menu&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;What is the correct way to invoke the saved search via the API and get correct results?&lt;/P&gt;

&lt;P&gt;Resources used: &lt;A href="http://splunk-base.splunk.com/answers/8945/how-to-start-a-saved-search-using-rest-api"&gt;http://splunk-base.splunk.com/answers/8945/how-to-start-a-saved-search-using-rest-api&lt;/A&gt; &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTsearch#saved.2Fsearches"&gt;http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTsearch#saved.2Fsearches&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2013 14:51:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Splunk-API-the-proper-way-to-run-a-saved-search/m-p/106345#M22392</guid>
      <dc:creator>brettcave</dc:creator>
      <dc:date>2013-04-25T14:51:42Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk API: the proper way to run a saved search</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Splunk-API-the-proper-way-to-run-a-saved-search/m-p/106346#M22393</link>
      <description>&lt;P&gt;Looks like this post helped me get it right: &lt;A href="http://splunk-base.splunk.com/answers/50636/finding-specific-searches-in-splunk-via-rest-api-calls"&gt;http://splunk-base.splunk.com/answers/50636/finding-specific-searches-in-splunk-via-rest-api-calls&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;To trigger the search: &lt;CODE&gt;POST /services/saved/searches/MyCustomSearch/dispatch -d force_dispatch=true&lt;/CODE&gt;. The force_dispatch is optional.&lt;/P&gt;

&lt;P&gt;I can then poll the status of the returned SID (still to be tested)&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2013 07:58:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Splunk-API-the-proper-way-to-run-a-saved-search/m-p/106346#M22393</guid>
      <dc:creator>brettcave</dc:creator>
      <dc:date>2013-04-26T07:58:32Z</dc:date>
    </item>
  </channel>
</rss>

