<?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 Splunk API Script Help in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Splunk-API-Script-Help/m-p/668913#M229443</link>
    <description>&lt;P&gt;All,&lt;/P&gt;&lt;P&gt;Leveraging the following article (&lt;A href="https://community.splunk.com/t5/Other-Usage/How-to-export-reports-using-the-REST-API/m-p/640406/highlight/false#M475" target="_blank" rel="noopener"&gt;https://community.splunk.com/t5/Other-Usage/How-to-export-reports-using-the-REST-API/m-p/640406/highlight/false#M475&lt;/A&gt;) I was able to successfully manipulate the script to:&lt;/P&gt;&lt;P&gt;1. Run using an API token (as opposed to credentials).&lt;/P&gt;&lt;P&gt;2. Get it to run a search I am interested in returning data from.&lt;/P&gt;&lt;P&gt;I am however running into an error with my search (shown below).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;response&amp;gt;
  &amp;lt;messages&amp;gt;
    &amp;lt;msg type="ERROR"&amp;gt;Unparsable URI-encoded request data&amp;lt;/msg&amp;gt;
  &amp;lt;/messages&amp;gt;
&amp;lt;/response&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;The script itself now looks like this (I have removed the token and obscured the Splunk endpoint for obvious reasons.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#!/bin/bash
# A simple bash script example of how to get notable events details from REST API

# EXECUTE search and retrieve SID
SID=$(curl -H "Authorization: Bearer &amp;lt;token ID here&amp;gt;" -k https://host.domain.com:8089/services/search/jobs -d search=" search index=index sourcetype="sourcetype" source="source" [ search index="index" sourcetype="sourcetype" source="source" deleted_at="null" | rename uuid AS host_uuid | stats count by host_uuid | fields host_uuid ] | rename data.id AS Data_ID host_uuid AS Host_ID port AS Network_Port | mvexpand data.xrefs{}.type | strcat Host_ID : Data_ID : Network_Port Custom_ID_1 | strcat Host_ID : Data_ID Custom_ID_2 | stats latest(*) as * by Custom_ID_1 | search state!="fixed" | search category!="informational" | eval unixtime=strptime(first_found,"%Y-%m-%dT%H:%M:%S")" &amp;lt;removed some of the search for brevity&amp;gt; \
| grep "sid" | awk -F\&amp;gt; '{print $2}' | awk -F\&amp;lt; '{print $1}')
echo "SID=${SID}"

Omitted the remaining portion of the script for brevity....&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is at this point shown in brackets (| eval unixtime=strptime(first_found,"%Y-%m-%dT%H:%M:%S") that I am getting the error in question.&lt;/P&gt;&lt;P&gt;The search returns fine up to the point where I am converting time ---- I tried escaping using "\", but that did not seem to help. I am sure I am missing something simple and looking for some help.&lt;/P&gt;</description>
    <pubDate>Thu, 16 Nov 2023 19:50:32 GMT</pubDate>
    <dc:creator>qcjacobo2577</dc:creator>
    <dc:date>2023-11-16T19:50:32Z</dc:date>
    <item>
      <title>Splunk API Script Help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-API-Script-Help/m-p/668913#M229443</link>
      <description>&lt;P&gt;All,&lt;/P&gt;&lt;P&gt;Leveraging the following article (&lt;A href="https://community.splunk.com/t5/Other-Usage/How-to-export-reports-using-the-REST-API/m-p/640406/highlight/false#M475" target="_blank" rel="noopener"&gt;https://community.splunk.com/t5/Other-Usage/How-to-export-reports-using-the-REST-API/m-p/640406/highlight/false#M475&lt;/A&gt;) I was able to successfully manipulate the script to:&lt;/P&gt;&lt;P&gt;1. Run using an API token (as opposed to credentials).&lt;/P&gt;&lt;P&gt;2. Get it to run a search I am interested in returning data from.&lt;/P&gt;&lt;P&gt;I am however running into an error with my search (shown below).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;response&amp;gt;
  &amp;lt;messages&amp;gt;
    &amp;lt;msg type="ERROR"&amp;gt;Unparsable URI-encoded request data&amp;lt;/msg&amp;gt;
  &amp;lt;/messages&amp;gt;
&amp;lt;/response&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;The script itself now looks like this (I have removed the token and obscured the Splunk endpoint for obvious reasons.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#!/bin/bash
# A simple bash script example of how to get notable events details from REST API

# EXECUTE search and retrieve SID
SID=$(curl -H "Authorization: Bearer &amp;lt;token ID here&amp;gt;" -k https://host.domain.com:8089/services/search/jobs -d search=" search index=index sourcetype="sourcetype" source="source" [ search index="index" sourcetype="sourcetype" source="source" deleted_at="null" | rename uuid AS host_uuid | stats count by host_uuid | fields host_uuid ] | rename data.id AS Data_ID host_uuid AS Host_ID port AS Network_Port | mvexpand data.xrefs{}.type | strcat Host_ID : Data_ID : Network_Port Custom_ID_1 | strcat Host_ID : Data_ID Custom_ID_2 | stats latest(*) as * by Custom_ID_1 | search state!="fixed" | search category!="informational" | eval unixtime=strptime(first_found,"%Y-%m-%dT%H:%M:%S")" &amp;lt;removed some of the search for brevity&amp;gt; \
| grep "sid" | awk -F\&amp;gt; '{print $2}' | awk -F\&amp;lt; '{print $1}')
echo "SID=${SID}"

Omitted the remaining portion of the script for brevity....&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is at this point shown in brackets (| eval unixtime=strptime(first_found,"%Y-%m-%dT%H:%M:%S") that I am getting the error in question.&lt;/P&gt;&lt;P&gt;The search returns fine up to the point where I am converting time ---- I tried escaping using "\", but that did not seem to help. I am sure I am missing something simple and looking for some help.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2023 19:50:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-API-Script-Help/m-p/668913#M229443</guid>
      <dc:creator>qcjacobo2577</dc:creator>
      <dc:date>2023-11-16T19:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk API Script Help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-API-Script-Help/m-p/668952#M229463</link>
      <description>&lt;P&gt;Use the --data-urlencode option instead of -d (--data)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;curl -H "Authorization: Bearer &amp;lt;token ID here&amp;gt;" -k https://host.domain.com:8089/services/search/jobs --data-urlencode search='&amp;lt;your search term&amp;gt;'&lt;/LI-CODE&gt;&lt;P&gt;One more thing: SPL uses lots of double quotes. &amp;nbsp;Quote your search with single quotes saves you lots of escapes.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2023 06:17:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-API-Script-Help/m-p/668952#M229463</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-11-17T06:17:46Z</dc:date>
    </item>
  </channel>
</rss>

