Splunk Dev

Splunk NodeJS module not giving a successful login against Splunk cloud

ab73863
New Member

We are using Splunk cloud in our enterprise and as part of an automation project we want programatic way for doing Splunk search. Based on Splunk website we found that there is node module splunk-sdk (https://www.npmjs.com/package/splunk-sdk) using which we can access Splunk even though the module is not mentioning explicitly anything about Splunk cloud. 

Following is the code we attempted but its failing to connect. Would like to know if any special configuration needs to be done in order to achieve the connection.

 

(async=>{
let splunkjs = require('splunk-sdk');

let service  = new splunkjs.Service({username: "myusername", password: "***"});


async function myFunction() {
  try {
    await service.login();
    console.log("Login was successful: " + success);
    let jobs = await jobs.fetch();
    let jobList = jobs.list();
    for(let i = 0; i < jobList.length; i++) {
        console.log("Job " + i + ": " + jobList[i].sid);
    }
} catch(err) {
    console.log(err);
}  

 

Following is the error we are getting.

ab73863_0-1723255897649.png

Please help in understanding and resolving this issue if anyone has encountered the same issue.

Labels (1)
0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

@ab73863- Try this approach with sessionKey.

VatsalJagani_0-1723369459905.png

Specify Splunk Cloud URL and port number should be 8089 but you can confirm with your Splunk Cloud Representative or Splunk Cloud Support.

 

I hope this helps!!!

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...