Splunk Dev

Not able to connect to splunk using javascript sdk

kavyatim
Path Finder

I installed node.js ,copied xmljson to splunk app.
Done with everything as per the document.
The client side program is as follows:




How to start a Splunk session

<script type="text/javascript" charset="utf-8">
function displayApps() {
    var http = new splunkjs.ProxyHttp("/proxy");

    // Create a Service instance and log in 
    var service = new splunkjs.Service(http, {
        username:"admin",
        password:"kav$tim1",
        scheme:"http",
        host:"localhost",
        port:"8089",
        version:"5.0"
    });

   // Verify we logged in


 // First, we log in

service.login(function(err, success) {
// We check for both errors in the connection as well
// as if the login itself failed.
if (err || !success) {
console.log("Error in logging in");
done(err || "Login failed");
return;
}

    // Print installed apps to the console to verify login
    service.apps().fetch(function(err, apps) {
        if (err) {
       console.log("There was an error retrieving the list of applications:", err);
        done(err);
        return;
        }

        var myapps = "";
        var appsList = apps.list();
        console.log("Applications:");
        for(var i = 0; i < appsList.length; i++) {
            myapps += "App " + i + ": " + appsList[i].name + "<br/>"
        } 

        document.getElementById("applist").innerHTML=myapps;
    });

}
</script> 






Tags (1)

jitendra0101
Engager

Please help. Every time I am getting error message as "There was an error retrieving the list of applications".

0 Karma

guilhem
Contributor

I have made another question as there is not enough room in the comment. See
http://splunk-base.splunk.com/answers/84184/javascript-sdk-internal-server-error

0 Karma

Neeraj_Luthra
Splunk Employee
Splunk Employee

@guilhem - What error are you running into? Assuming that you are using node v0.8.x.

0 Karma

guilhem
Contributor

Did you solve this problem? I have exactly the same error as you describe and would be interested in a solution.

By the way you need to use node v0.8.x (and not the latest release) as otherwise it will not work. see http://splunk-base.splunk.com/answers/79378/splunk-502-javascript-sdk-server-error-500-examples-brow...

0 Karma

Neeraj_Luthra
Splunk Employee
Splunk Employee

There are a few issues with what you are doing:

  1. If you are on Splunk 5, you do not need xml2json, unless of course you are trying to run the unit tests.
  2. service.login function call is missing a couple of closing parenthesis.
  3. scheme should be https, unless you have changed the default Splunk installation.
  4. You need to serve this page from a web server and in that web server you will need to set up the proxy. This last steps is taken care of if you run the examples through node, i.e. node sdkdo examples from the command line. This is also documented at JavaScript SDK Browser Examples.
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 ...