There is something missing in my NodeJS code, it seems. This simple Python3 test works (in creating a search job and returning an sid): 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) But this NodeJS code does not: 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()); With the same SPLUNK_HOST and SPLUNK_TOKEN values, the Python code produces an output like this: {"sid":"1691684765.268000"} But the NodeJS example returns an XML document. Any thoughts are much appreciated!
... View more