Splunk Search

Splunk REST API with NodeJs: trouble getting started creating a search job

mattee1283
New Member

I'm new to this, and would appreciate any help from someone who uses NodeJs with Splunk. I can successfully query past search jobs and details for a specific search job given the SID, but I can't create a search job or get a session key through the login link. Below is the code I have working so far, and after that I will show the code that is not working:

const url = 'https://mydomain:8089/services/search/jobs'
const auth = {
      username: 'myusername',
      password: 'mypassword',
}
axios.get(url, {auth})
.then((response) => {
      // do something with the response ...
})
.catch((error) => {
      // handle error ...
})

However, when I try to create a search job in a similar way, it does not work, and when I try to get a session key, it does not work. I will show both codes snippets. The following gives me a 401 Unauthorized:

const search = 'search mysearch'
const params = {search}
axios.post(url, {auth, params})
.then((response) =>  {
      // do something with response ...
})
.catch((error) => {
      // handle error ...
})

When I try to first get a session key, however, it gives me a 400 Bad Request:

const loginurl = 'https://mydomain:8089/services/auth/login'
axios.post(loginurl, {auth})
.then((response) => {
      // do something with response ...
})
.catch((error) => {
      // handle error ...
})

I've been banging my head against the wall with this. Any help is greatly appreciated!

Labels (1)
0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...