<?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 How can I create a search job using the REST API? in Other Usage</title>
    <link>https://community.splunk.com/t5/Other-Usage/How-can-I-create-a-search-job-using-the-REST-API/m-p/651397#M620</link>
    <description>&lt;P&gt;Following the documentation here:&lt;BR /&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/RESTTUT/RESTsearches#Create_a_search_job" target="_blank" rel="noopener"&gt;https://docs.splunk.com/Documentation/Splunk/latest/RESTTUT/RESTsearches#Create_a_search_job&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I expect that a successful REST API call to endpoint "/services/search/jobs" would return a single job ID as the document shows.&lt;/P&gt;
&lt;P&gt;However, in my testing, when the call returns with a status of 200 (success), the response data contains an object, which contains 6 keys:&amp;nbsp;Object.keys(jobId) =&amp;nbsp;(6) ['links', 'origin', 'updated', 'generator', 'entry', 'paging']&lt;/P&gt;
&lt;P&gt;where, jobId.entry is an array of hundreds of search jobs -- basically the call to create a search job returned a list of all the jobs in the search head.&lt;/P&gt;
&lt;P&gt;The code (JavaScript) is in this public repository:&lt;BR /&gt;&lt;A href="https://github.com/ww9rivers/splunk-rest-search" target="_blank" rel="noopener"&gt;https://github.com/ww9rivers/splunk-rest-search&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Am I missing anything? Thank you for your insights!&lt;/P&gt;</description>
    <pubDate>Thu, 10 Aug 2023 21:17:52 GMT</pubDate>
    <dc:creator>ww9rivers</dc:creator>
    <dc:date>2023-08-10T21:17:52Z</dc:date>
    <item>
      <title>How can I create a search job using the REST API?</title>
      <link>https://community.splunk.com/t5/Other-Usage/How-can-I-create-a-search-job-using-the-REST-API/m-p/651397#M620</link>
      <description>&lt;P&gt;Following the documentation here:&lt;BR /&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/RESTTUT/RESTsearches#Create_a_search_job" target="_blank" rel="noopener"&gt;https://docs.splunk.com/Documentation/Splunk/latest/RESTTUT/RESTsearches#Create_a_search_job&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I expect that a successful REST API call to endpoint "/services/search/jobs" would return a single job ID as the document shows.&lt;/P&gt;
&lt;P&gt;However, in my testing, when the call returns with a status of 200 (success), the response data contains an object, which contains 6 keys:&amp;nbsp;Object.keys(jobId) =&amp;nbsp;(6) ['links', 'origin', 'updated', 'generator', 'entry', 'paging']&lt;/P&gt;
&lt;P&gt;where, jobId.entry is an array of hundreds of search jobs -- basically the call to create a search job returned a list of all the jobs in the search head.&lt;/P&gt;
&lt;P&gt;The code (JavaScript) is in this public repository:&lt;BR /&gt;&lt;A href="https://github.com/ww9rivers/splunk-rest-search" target="_blank" rel="noopener"&gt;https://github.com/ww9rivers/splunk-rest-search&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Am I missing anything? Thank you for your insights!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2023 21:17:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Other-Usage/How-can-I-create-a-search-job-using-the-REST-API/m-p/651397#M620</guid>
      <dc:creator>ww9rivers</dc:creator>
      <dc:date>2023-08-10T21:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a search job using the REST API</title>
      <link>https://community.splunk.com/t5/Other-Usage/How-can-I-create-a-search-job-using-the-REST-API/m-p/651460#M621</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I suppose that there is some misunderstanding to use /services vs. /servicesNS endpoints? Maybe that explain how to use those?&amp;nbsp;&lt;A href="https://community.splunk.com/t5/Splunk-Search/Why-am-I-receiving-this-Error-while-using-the-rest-in-the-splunk/m-p/594581/highlight/true#M206942" target="_blank"&gt;https://community.splunk.com/t5/Splunk-Search/Why-am-I-receiving-this-Error-while-using-the-rest-in-the-splunk/m-p/594581/highlight/true#M206942&lt;/A&gt;&lt;/P&gt;&lt;P&gt;r. Ismo&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2023 11:10:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Other-Usage/How-can-I-create-a-search-job-using-the-REST-API/m-p/651460#M621</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2023-07-21T11:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a search job using the REST API</title>
      <link>https://community.splunk.com/t5/Other-Usage/How-can-I-create-a-search-job-using-the-REST-API/m-p/651500#M622</link>
      <description>&lt;P&gt;No. Actually, in the answer that you linked, you clearly used "&lt;FONT face="andale mono,times"&gt;/services/search/jobs/&lt;/FONT&gt;" to create the search:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;curl -ku &amp;lt;user:pass&amp;gt; https://localhost:8089/services/search/jobs/ -d search=. . .&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my case, I am trying to use the same API endpoint to create a search. My search command is not necessarily a "&lt;FONT face="andale mono,times"&gt;|rest&lt;/FONT&gt;" , rather, it is something like "&lt;FONT face="andale mono,times"&gt;| inputcsv &amp;lt;some-results&amp;gt;.csv&lt;/FONT&gt;" for most my use cases.&lt;/P&gt;&lt;P&gt;Thank you for the thoughts.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2023 21:37:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Other-Usage/How-can-I-create-a-search-job-using-the-REST-API/m-p/651500#M622</guid>
      <dc:creator>ww9rivers</dc:creator>
      <dc:date>2023-07-21T21:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a search job using the REST API</title>
      <link>https://community.splunk.com/t5/Other-Usage/How-can-I-create-a-search-job-using-the-REST-API/m-p/653973#M623</link>
      <description>&lt;P&gt;There is something missing in my NodeJS code, it seems.&lt;/P&gt;&lt;P&gt;This simple Python3 test works (in creating a search job and returning an sid):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os
import requests

# Set up the session with our adapter
SEARCH_ENDPOINT = "https://"+os.environ['SPLUNK_HOST']+":8089/services/search/jobs"
headers = {
    'Authorization': 'Bearer '+os.environ['SPLUNK_TOKEN'],
    "Accept": "application/json"
}
params = {
    "search": "inputcsv search-output.csv",
    "output_mode": "json"
}

response = requests.post(SEARCH_ENDPOINT, data=params, headers=headers, verify=True)
print(response.text)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this NodeJS code does not:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const SEARCH_ENDPOINT = `https://${process.env.SPLUNK_HOST}:8089/services/search/jobs`;
const data = {
	search: "inputcsv search-output.csv",
	output_mode: "json"
};
const options = {
	method: "POST",
	mode: "cors",
	cache: "no-cache",
	credentials: "same-origin",
	headers: {
		Authorization: `Bearer ${process.env.SPLUNK_TOKEN}`,
		Accept: "application/json"
	},
	redirect: "follow",
	referrerPolicy: "no-referrer",
	body: JSON.stringify(data),
};

let response = await fetch(SEARCH_ENDPOINT, options);
console.log(response.status);
console.log(response.body);
console.log(await response.json());&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With the same SPLUNK_HOST and SPLUNK_TOKEN values, the Python code produces an output like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{"sid":"1691684765.268000"}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the NodeJS example returns an XML document.&lt;/P&gt;&lt;P&gt;Any thoughts are much appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2023 16:39:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Other-Usage/How-can-I-create-a-search-job-using-the-REST-API/m-p/653973#M623</guid>
      <dc:creator>ww9rivers</dc:creator>
      <dc:date>2023-08-10T16:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a search job using the REST API</title>
      <link>https://community.splunk.com/t5/Other-Usage/How-can-I-create-a-search-job-using-the-REST-API/m-p/654984#M624</link>
      <description>&lt;P&gt;Got this figured out! The JS version sent the `body` part wrong: It is not supposed to be JSON encoded but HTTP query string encoded.&lt;/P&gt;&lt;P&gt;The working version is here in GitHub:&amp;nbsp;&lt;A href="https://gist.github.com/ww9rivers/dc3fd9ba8d2817b9fc986aa9457a2b61" target="_blank"&gt;https://gist.github.com/ww9rivers/dc3fd9ba8d2817b9fc986aa9457a2b61&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Aug 2023 03:04:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Other-Usage/How-can-I-create-a-search-job-using-the-REST-API/m-p/654984#M624</guid>
      <dc:creator>ww9rivers</dc:creator>
      <dc:date>2023-08-21T03:04:49Z</dc:date>
    </item>
  </channel>
</rss>

