<?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: Using python to query splunk and get SID - error 404 in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Using-python-to-query-splunk-and-get-SID-error-404/m-p/683971#M114168</link>
    <description>&lt;P&gt;What happens if you use the v2 jobs endpoint? (the non-v2 one is deprecated, as per &lt;A href="https://docs.splunk.com/Documentation/Splunk/9.2.1/RESTREF/RESTsearch" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/9.2.1/RESTREF/RESTsearch&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;Instead of:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;url = "https://abc.splunkcloud.com:8089/servicesAB/-/xyz/search/jobs"&lt;/LI-CODE&gt;&lt;P&gt;Try:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;url = "https://abc.splunkcloud.com:8089/servicesAB/-/xyz/search/v2/jobs"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 11 Apr 2024 21:00:50 GMT</pubDate>
    <dc:creator>marnall</dc:creator>
    <dc:date>2024-04-11T21:00:50Z</dc:date>
    <item>
      <title>Using python to query splunk and get SID - error 404</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Using-python-to-query-splunk-and-get-SID-error-404/m-p/682633#M114010</link>
      <description>&lt;P&gt;I have this query (below):&lt;/P&gt;
&lt;P&gt;1) When I run this query in Splunk web, I get back SID and get data using SID.&lt;/P&gt;
&lt;P&gt;2) When I use curl command, I get back SID and get data using SID.&lt;/P&gt;
&lt;P&gt;3) But when I use Python, I get SID in the response with status code 201.&lt;/P&gt;
&lt;P&gt;#read this query from file&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;with open("aquery2.txt", "r") as f:
aQuery = f.read()

##derive earliest and latest 
finalAQuery=("search" + " " +("earliest=" + "1711982700.001" + "=" + ("latest=" + 1711983600.0 + " " + aQuery)

&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;url = "&lt;A href="https://abc.splunkcloud.com:8089/servicesAB/-/xyz/search/jobs" target="_blank" rel="noopener"&gt;https://abc.splunkcloud.com:8089/servicesAB/-/xyz/search/jobs&lt;/A&gt;"&lt;BR /&gt;def getSid():&lt;BR /&gt;try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;response = requests.post(url, headers={'Authorization': TOKEN}, data={'search': finalAQuery}, verify=False)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I get back the SID. But when I use the SID to get the results, I get error 404, &amp;lt;Response [404]&amp;gt;&lt;BR /&gt;{"messages":[{"type":"FATAL","text":"Unknown endpoint."}]}&lt;/P&gt;
&lt;P&gt;def getMetric():&lt;BR /&gt;try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;getData=(url + '/' + sid + '/results')
getSidResponse = requests.get(getData, headers={'Authorization': TOKEN}, data={'output_mode' : 'json'}, verify=False)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#aquery.txt contents below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=apigee sourcetype="apigee:Prod_access_logs" | rex field=proxyUri "(?P&amp;lt;proxyUri&amp;gt;(([a-zA-Z]+)\d)(?:\d\/[a-zA-Z]+|\/[a-zA-Z]+)+)" | convert num("requestTimeinSec") |rex field=_raw "(?&amp;lt;timeStamp&amp;gt;\d{4}\-\d{1,2}\-\d{1,2}T\d{1,2}\:\d{1,2}\:\d{1,2}\-\d{1,2}\:\d{1,2})\s+(?&amp;lt;hostValue&amp;gt;\w+)\s+\S+\s+\S+\s+(?&amp;lt;requestTimeinSec&amp;gt;\S+)\s+\-\s+-\s+(?P&amp;lt;httpStatusCode&amp;gt;\w+)\s+(?&amp;lt;upstreamHttpStatusCode&amp;gt;\w+)\s+\w+\s+\w+\s+(?&amp;lt;methodName&amp;gt;\w+)\s+(?&amp;lt;proxyUri&amp;gt;\S+)\s+(?&amp;lt;httpVersion&amp;gt;\S+)\s+(?&amp;lt;messageId&amp;gt;\S+)" |rex field=_raw "^([^\t]+\t){35}(?P&amp;lt;ClientId&amp;gt;[^\t]+)" | eval totalResponseTime=round(requestTimeinSec*1000) | replace "z1/credit/bank/info/usa" with "x1/credit/bank/info/canada" in proxyUri | replace "v1/taste" with "/connecticut/taste/v1/newyork" in proxyUri | rangemap field="httpStatusCode" "httpStatusCode"=0-499 | rename range as RangeSuccesshttpStatusCode | eval Product=case(like(ClientId, "JERSEY"), "aaa", like(ClientId, "APPLE"), "bbb", like(ClientId, "HELLO"), "ccc") | eval ATier=case((like(proxyUri,"/paypal/jersey/v1/newyork") AND like(methodName,"POST") AND IN (Product, "aaa", "bbb", "ccc")) , "Tier1", (like(proxyUri,"v1/credit/bank/info/canada") AND like(methodName,"GET") AND IN (Product, "aaa", "bbb", "ccc")) OR (like(proxyUri,"v1/credit/accounts/profile") AND like(methodName,"GET") AND IN (Product, "Venmo", "Cobrand", "PPC")), "Tier2",(like(proxyUri,"v1/alerts/preferences") AND like(methodName,"GET") AND IN (Product, "Venmo", "Cobrand", "PPC")), "Tier3",1==1,"NA") | stats count(totalResponseTime) as TotalTrans, count(eval(RangeSuccesshttpStatusCode="httpStatusCode")) as TotalSuccesTran, count(eval(httpStatusCode&amp;lt;500)) as GoodEvents, by ATier Product proxyUri methodName | where ((Product IN ("aaa", "bbb", "ccc")) AND (ATier IN ("Tier1", "Tier2","Tier3"))) |rename methodName AS Method | fields ATier proxyUri Method TotalTrans GoodEvents&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2024 17:46:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Using-python-to-query-splunk-and-get-SID-error-404/m-p/682633#M114010</guid>
      <dc:creator>nisheethbaxi</dc:creator>
      <dc:date>2024-04-01T17:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using python to query splunk and get SID - error 404</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Using-python-to-query-splunk-and-get-SID-error-404/m-p/683971#M114168</link>
      <description>&lt;P&gt;What happens if you use the v2 jobs endpoint? (the non-v2 one is deprecated, as per &lt;A href="https://docs.splunk.com/Documentation/Splunk/9.2.1/RESTREF/RESTsearch" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/9.2.1/RESTREF/RESTsearch&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;Instead of:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;url = "https://abc.splunkcloud.com:8089/servicesAB/-/xyz/search/jobs"&lt;/LI-CODE&gt;&lt;P&gt;Try:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;url = "https://abc.splunkcloud.com:8089/servicesAB/-/xyz/search/v2/jobs"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2024 21:00:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Using-python-to-query-splunk-and-get-SID-error-404/m-p/683971#M114168</guid>
      <dc:creator>marnall</dc:creator>
      <dc:date>2024-04-11T21:00:50Z</dc:date>
    </item>
  </channel>
</rss>

