<?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 Python - Issue with pulling results before search job is done. in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/REST-API-Python-Issue-with-pulling-results-before-search-job-is/m-p/69717#M14165</link>
    <description>&lt;P&gt;I wrote a script in Python to run a search query and return the results.  The code to send the search query is:&lt;/P&gt;

&lt;P&gt;sid1 = httplib2.Http(disable_ssl_certificate_validation=True).request(baseurl + '/services/search/jobs','POST',&lt;BR /&gt;
        headers={'Authorization': 'Splunk %s' % sessionKey},body=urllib.urlencode({'search': searchQuery1}))[1]&lt;/P&gt;

&lt;P&gt;The code to return the results is:&lt;/P&gt;

&lt;P&gt;response1 = httplib2.Http(disable_ssl_certificate_validation=True).request(baseurl + '/services/search/jobs/' + slicesid1 + '/results?count=0','GET',&lt;BR /&gt;
        headers={'Authorization': 'Splunk %s' % sessionKey},body=urllib.urlencode({'search': searchQuery1}))[1] &lt;/P&gt;

&lt;P&gt;The issue is that if the results request is made before the result query is completed, no results will be returned.  I have fiddled with sleep time which allows me to return results but that isn't very efficient as the sleep time can be too long or too short.&lt;/P&gt;

&lt;P&gt;I know there is a field called dispatchState that is RUNNING during the search which changes to DONE when it is completed.  How can I put some code in after the initial search query that will continuously check to see if the job is RUNNING or DONE and then once DONE, the results query will run?&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 13:34:05 GMT</pubDate>
    <dc:creator>sd248011</dc:creator>
    <dc:date>2020-09-28T13:34:05Z</dc:date>
    <item>
      <title>REST API Python - Issue with pulling results before search job is done.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-API-Python-Issue-with-pulling-results-before-search-job-is/m-p/69717#M14165</link>
      <description>&lt;P&gt;I wrote a script in Python to run a search query and return the results.  The code to send the search query is:&lt;/P&gt;

&lt;P&gt;sid1 = httplib2.Http(disable_ssl_certificate_validation=True).request(baseurl + '/services/search/jobs','POST',&lt;BR /&gt;
        headers={'Authorization': 'Splunk %s' % sessionKey},body=urllib.urlencode({'search': searchQuery1}))[1]&lt;/P&gt;

&lt;P&gt;The code to return the results is:&lt;/P&gt;

&lt;P&gt;response1 = httplib2.Http(disable_ssl_certificate_validation=True).request(baseurl + '/services/search/jobs/' + slicesid1 + '/results?count=0','GET',&lt;BR /&gt;
        headers={'Authorization': 'Splunk %s' % sessionKey},body=urllib.urlencode({'search': searchQuery1}))[1] &lt;/P&gt;

&lt;P&gt;The issue is that if the results request is made before the result query is completed, no results will be returned.  I have fiddled with sleep time which allows me to return results but that isn't very efficient as the sleep time can be too long or too short.&lt;/P&gt;

&lt;P&gt;I know there is a field called dispatchState that is RUNNING during the search which changes to DONE when it is completed.  How can I put some code in after the initial search query that will continuously check to see if the job is RUNNING or DONE and then once DONE, the results query will run?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:34:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-API-Python-Issue-with-pulling-results-before-search-job-is/m-p/69717#M14165</guid>
      <dc:creator>sd248011</dc:creator>
      <dc:date>2020-09-28T13:34:05Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Python - Issue with pulling results before search job is done.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-API-Python-Issue-with-pulling-results-before-search-job-is/m-p/69718#M14166</link>
      <description>&lt;P&gt;You can write a while loop and continue to refresh the job and check for &lt;CODE&gt;isDone&lt;/CODE&gt; property on the job. Exit when the property value changes to 1.&lt;/P&gt;

&lt;P&gt;Checkout the Python SDK and code sample for this while loop at &lt;A href="http://dev.splunk.com/view/SP-CAAAEE5#normaljob"&gt;http://dev.splunk.com/view/SP-CAAAEE5#normaljob&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2013 15:49:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-API-Python-Issue-with-pulling-results-before-search-job-is/m-p/69718#M14166</guid>
      <dc:creator>Neeraj_Luthra</dc:creator>
      <dc:date>2013-03-21T15:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Python - Issue with pulling results before search job is done.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-API-Python-Issue-with-pulling-results-before-search-job-is/m-p/69719#M14167</link>
      <description>&lt;P&gt;Thanks much that is exactly what I needed.  Only problem I have now is it is not returning all of my results.  Can you let me know how I would add in the count=0 argument on the results line that is:&lt;/P&gt;

&lt;P&gt;for result2 in results.ResultsReader(job.results()):&lt;BR /&gt;
        print result2&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2013 18:56:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-API-Python-Issue-with-pulling-results-before-search-job-is/m-p/69719#M14167</guid>
      <dc:creator>sd248011</dc:creator>
      <dc:date>2013-03-21T18:56:25Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Python - Issue with pulling results before search job is done.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-API-Python-Issue-with-pulling-results-before-search-job-is/m-p/69720#M14168</link>
      <description>&lt;P&gt;Try this:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE&gt;body=urllib.urlencode({'search': searchQuery1, 'count': 0})&lt;/CODE&gt;&lt;/PRE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2013 19:43:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-API-Python-Issue-with-pulling-results-before-search-job-is/m-p/69720#M14168</guid>
      <dc:creator>Neeraj_Luthra</dc:creator>
      <dc:date>2013-03-21T19:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Python - Issue with pulling results before search job is done.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-API-Python-Issue-with-pulling-results-before-search-job-is/m-p/69721#M14169</link>
      <description>&lt;P&gt;I was able to use the count argument in my original code at the top and pull all of the results.  Now I am using the code in the link you gave me with the python SDK and can't figure out how to add in the count=0 argument.  In your link:&lt;/P&gt;

&lt;P&gt;for result2 in results.ResultsReader(job.results()):&lt;BR /&gt;
        print result2&lt;/P&gt;

&lt;P&gt;The above code is to pull the results now.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2013 20:01:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-API-Python-Issue-with-pulling-results-before-search-job-is/m-p/69721#M14169</guid>
      <dc:creator>sd248011</dc:creator>
      <dc:date>2013-03-21T20:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Python - Issue with pulling results before search job is done.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-API-Python-Issue-with-pulling-results-before-search-job-is/m-p/69722#M14170</link>
      <description>&lt;P&gt;How about this ...&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE&gt;kwargs_results = {"count": 0}&lt;BR /&gt;
search_results = job.results(**kwargs_results)&lt;/CODE&gt;&lt;/PRE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:34:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-API-Python-Issue-with-pulling-results-before-search-job-is/m-p/69722#M14170</guid>
      <dc:creator>Neeraj_Luthra</dc:creator>
      <dc:date>2020-09-28T13:34:39Z</dc:date>
    </item>
  </channel>
</rss>

