<?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 - JSON Expecting value: line 1 column 1 (char 0) in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Splunk-API-JSON-Expecting-value-line-1-column-1-char-0/m-p/593433#M206549</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/235142"&gt;@bijodev1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;May be this will help you.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests
import json
# from requests.auth import HTTPBasicAuth
# import urllib3
# urllib3.disable_warnings()
#
#
#
# search_query={'search':'search earliest = -24h index=_internal | stats count by sourcetype'}
# response = requests.post('https://localhost:8000/services/search/jobs/export', data=search_query,verify=False, auth=HTTPBasicAuth('admin', 'admin'))
# print("Status = "+str(response.status_code) )
# print("response text = "+str(response.text))
# # json_data = json.loads(str(response.text))

import requests
import urllib3
from base64 import b64encode
import urllib.parse
from csv import reader

urllib3.disable_warnings()


def fetch_data_using_userid(userid):
    url = "https://localhost:8089/servicesNS/admin/search/search/jobs/export"
    payload = {
        'search': f'search index=_internal earliest=-1h sourcetype="{userid}" | stats count by sourcetype',
        'output_mode': 'json'
    }
    safe_payload = urllib.parse.urlencode(payload)

    userAndPass = b64encode(b"admin:admin123").decode("ascii")
    headers = {
        'Authorization': 'Basic %s' % userAndPass,
        'Content-Type': 'application/x-www-form-urlencoded'
    }
    response = requests.request("POST", url, headers=headers, data=safe_payload, verify=False)
    return response.text



# open file in read mode
with open('user_data.csv', 'r') as read_obj:
    # pass the file object to reader() to get the reader object
    csv_reader = reader(read_obj)
    header = next(csv_reader)
    if header is not None:
        # Iterate over each row in the csv using reader object
        for row in csv_reader:
            # row variable is a list that represents a row in csv
            print(row)
            response_text = fetch_data_using_userid(row[0])
            print(response_text)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;</description>
    <pubDate>Tue, 12 Apr 2022 11:04:58 GMT</pubDate>
    <dc:creator>kamlesh_vaghela</dc:creator>
    <dc:date>2022-04-12T11:04:58Z</dc:date>
    <item>
      <title>Splunk API - JSON Expecting value: line 1 column 1 (char 0)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-API-JSON-Expecting-value-line-1-column-1-char-0/m-p/593397#M206535</link>
      <description>&lt;P&gt;Hi Team, when I use curl - I am able to get the output in JSON format.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when I am trying to use requests module, I am getting json decode error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests
import json
from requests.auth import HTTPBasicAuth
search_query={'search':'search earliest = -24h index=* userid=abc123'}
requests.post('https://1.1.1.1/services/search/jobs/export, data=search_query,verify=False, auth=HTTPBasicAuth('admin', 'pass'))
print("Status = "+str(response.status_code) )
print("response text = "+str(response.text))
json_data = json.loads(str(response.text))
json.dump(json_obj)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 07:38:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-API-JSON-Expecting-value-line-1-column-1-char-0/m-p/593397#M206535</guid>
      <dc:creator>bijodev1</dc:creator>
      <dc:date>2022-04-12T07:38:39Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk API - JSON Expecting value: line 1 column 1 (char 0)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-API-JSON-Expecting-value-line-1-column-1-char-0/m-p/593410#M206540</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/235142"&gt;@bijodev1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Refer below example code. It is working for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests
import urllib3
from base64 import b64encode
import urllib.parse

urllib3.disable_warnings()

url = "https://localhost:8089/servicesNS/admin/search/search/jobs/export"
payload = {
  'search': 'search index=_internal earliest=-1h | stats count by sourcetype',
  'output_mode':'json'
}
safe_payload = urllib.parse.urlencode(payload)

userAndPass = b64encode(b"admin:admin123").decode("ascii")
headers = {
  'Authorization': 'Basic %s' % userAndPass,
  'Content-Type': 'application/x-www-form-urlencoded'
}
response = requests.request("POST", url, headers=headers, data=safe_payload, verify=False)

print(response.text)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 07:41:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-API-JSON-Expecting-value-line-1-column-1-char-0/m-p/593410#M206540</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2022-04-12T07:41:25Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk API - JSON Expecting value: line 1 column 1 (char 0)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-API-JSON-Expecting-value-line-1-column-1-char-0/m-p/593411#M206541</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/127939"&gt;@kamlesh_vaghela&lt;/a&gt;&amp;nbsp;thank you so much for the answer, output_mode=json worked for me. Just wanted to add one more thing along with this.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;search_query={'search':'search earliest = -24h index=* userid=abc123'}&lt;/LI-CODE&gt;&lt;P&gt;I have a csv file, which contains a list of userID, I need to use it in the search query against the filed userid, how can I do it, can you guide me how to do it. like what placeOrder i have to use here.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 07:49:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-API-JSON-Expecting-value-line-1-column-1-char-0/m-p/593411#M206541</guid>
      <dc:creator>bijodev1</dc:creator>
      <dc:date>2022-04-12T07:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk API - JSON Expecting value: line 1 column 1 (char 0)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-API-JSON-Expecting-value-line-1-column-1-char-0/m-p/593426#M206545</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/235142"&gt;@bijodev1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First make sure your csv data is accessible from search bar using inputlookup command. like&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|inputlookup user_data | table userid&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then use it into your existing search.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;search_query={'search':'search earliest = -24h index=* [|inputlookup user_data | table userid]'}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 10:27:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-API-JSON-Expecting-value-line-1-column-1-char-0/m-p/593426#M206545</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2022-04-12T10:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk API - JSON Expecting value: line 1 column 1 (char 0)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-API-JSON-Expecting-value-line-1-column-1-char-0/m-p/593429#M206546</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/127939"&gt;@kamlesh_vaghela&lt;/a&gt;&amp;nbsp;, I want to use the csv using python like a variable&lt;/P&gt;&lt;P&gt;like I assign a each value from csv and assign it to a variable, and call it in the search query and create a table data like a dataFrame.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 10:39:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-API-JSON-Expecting-value-line-1-column-1-char-0/m-p/593429#M206546</guid>
      <dc:creator>bijodev1</dc:creator>
      <dc:date>2022-04-12T10:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk API - JSON Expecting value: line 1 column 1 (char 0)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-API-JSON-Expecting-value-line-1-column-1-char-0/m-p/593433#M206549</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/235142"&gt;@bijodev1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;May be this will help you.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests
import json
# from requests.auth import HTTPBasicAuth
# import urllib3
# urllib3.disable_warnings()
#
#
#
# search_query={'search':'search earliest = -24h index=_internal | stats count by sourcetype'}
# response = requests.post('https://localhost:8000/services/search/jobs/export', data=search_query,verify=False, auth=HTTPBasicAuth('admin', 'admin'))
# print("Status = "+str(response.status_code) )
# print("response text = "+str(response.text))
# # json_data = json.loads(str(response.text))

import requests
import urllib3
from base64 import b64encode
import urllib.parse
from csv import reader

urllib3.disable_warnings()


def fetch_data_using_userid(userid):
    url = "https://localhost:8089/servicesNS/admin/search/search/jobs/export"
    payload = {
        'search': f'search index=_internal earliest=-1h sourcetype="{userid}" | stats count by sourcetype',
        'output_mode': 'json'
    }
    safe_payload = urllib.parse.urlencode(payload)

    userAndPass = b64encode(b"admin:admin123").decode("ascii")
    headers = {
        'Authorization': 'Basic %s' % userAndPass,
        'Content-Type': 'application/x-www-form-urlencoded'
    }
    response = requests.request("POST", url, headers=headers, data=safe_payload, verify=False)
    return response.text



# open file in read mode
with open('user_data.csv', 'r') as read_obj:
    # pass the file object to reader() to get the reader object
    csv_reader = reader(read_obj)
    header = next(csv_reader)
    if header is not None:
        # Iterate over each row in the csv using reader object
        for row in csv_reader:
            # row variable is a list that represents a row in csv
            print(row)
            response_text = fetch_data_using_userid(row[0])
            print(response_text)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 11:04:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-API-JSON-Expecting-value-line-1-column-1-char-0/m-p/593433#M206549</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2022-04-12T11:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk API - JSON Expecting value: line 1 column 1 (char 0)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-API-JSON-Expecting-value-line-1-column-1-char-0/m-p/593438#M206551</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/127939"&gt;@kamlesh_vaghela&lt;/a&gt;&amp;nbsp;thank you so much, it worked perfectly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;one last thing, can the data be appended or store in a form of dataframe pandas.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 11:47:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-API-JSON-Expecting-value-line-1-column-1-char-0/m-p/593438#M206551</guid>
      <dc:creator>bijodev1</dc:creator>
      <dc:date>2022-04-12T11:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk API - JSON Expecting value: line 1 column 1 (char 0)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-API-JSON-Expecting-value-line-1-column-1-char-0/m-p/593443#M206552</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/235142"&gt;@bijodev1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've a little know on pandas library. &amp;nbsp;But you can do it.&lt;/P&gt;&lt;P&gt;In our python script `response_text` will return json string. you can use that json to convert into DataFrame.&lt;/P&gt;&lt;P&gt;You can also get selected value from `response_text` and create dictionary of userid &amp;amp; those selected values to create DataFrame.&lt;/P&gt;&lt;P&gt;Please check below links for the same.&lt;/P&gt;&lt;P&gt;&lt;A href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html" target="_blank"&gt;https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.w3schools.com/python/pandas/pandas_dataframes.asp" target="_blank"&gt;https://www.w3schools.com/python/pandas/pandas_dataframes.asp&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://towardsdatascience.com/how-to-convert-json-into-a-pandas-dataframe-100b2ae1e0d8" target="_blank"&gt;https://towardsdatascience.com/how-to-convert-json-into-a-pandas-dataframe-100b2ae1e0d8&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 12:20:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-API-JSON-Expecting-value-line-1-column-1-char-0/m-p/593443#M206552</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2022-04-12T12:20:26Z</dc:date>
    </item>
  </channel>
</rss>

