Splunk Dev

JS SDK: Splunk API successfully authenticates but rejects any subsequent requests with 401 Unauthorized error

akhandelwal_hf
New Member

It seems like I'm able to successfully establish connection with the Splunk (Enterprise) API since I'm able to successfully authenticate and retrieve a sessionKey using:

var http = new splunkjs.SplunkWebHttp()

var service = new splunkjs.Service(http, {
  scheme: 'https',
  host: '<splunk-web-address>',
  port: 8089,
  username: '<username>',
  password: prompt('password'),
  version: '6.6.3'
})

service.apps().fetch((err, apps) => {
  console.log(err)
  console.log(apps)
})

The last statement to retrieve and log the apps fails with the following (note that the first login call on the left was successful as the auth token was put in the request header of the /services/apps request by the SDK):

Splunk API requests

The response is just: {"messages":[{"type":"ERROR","text":"Unauthorized"}]} My user has a role with all the rest-* capabilities, so I'm stumped. Any suggestions appreciated.

0 Karma
Get Updates on the Splunk Community!

Unleash the Power of Splunk MCP and AI, Meet Us at .Conf 2025, and Find Even More New ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Observability Professionals: Build Resilience and Visibility with These .conf25 ...

  If you're focused on performance, availability, and full-stack visibility, the Observability track at ...

See just what you’ve been missing | Observability tracks at Splunk University

Looking to sharpen your observability skills so you can better understand how to collect and analyze data from ...