Skip to content

Instantly share code, notes, and snippets.

@ww9rivers
Created August 21, 2023 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ww9rivers/dc3fd9ba8d2817b9fc986aa9457a2b61 to your computer and use it in GitHub Desktop.
Save ww9rivers/dc3fd9ba8d2817b9fc986aa9457a2b61 to your computer and use it in GitHub Desktop.
A JS version of the rest1.py
import diagnostics_channel from 'node:diagnostics_channel';
import querystring from 'node:querystring';
const SEARCH_ENDPOINT = `https://${process.env.SPLUNK_HOST}:8089/services/search/jobs`;
const data = {
search: "inputcsv pharmacy-calls.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: querystring.encode(data),
};
diagnostics_channel.subscribe('http', (message, name) => {
console.log('name:', name);
console.log('message:', message);
})
let response = await fetch(SEARCH_ENDPOINT, options);
console.log(response.status);
console.log(response.body);
console.log(await response.json());
@ww9rivers
Copy link
Author

See the Python3 version of this script for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment