Dashboards & Visualizations

How to get session key for Splunk connect

npbala_22
Explorer

While Connect the Splunk Using Service.connect am getting 401 error due authentication getting failed. I have to pass session key or token on login post method header. Am striking with getting session key/token. Can you resolve this by with out using Curl

Code:

Service service = new Service("XX.XXX.X.XXX", YYYY,"http");
service.login("XXXXXX", "YYYYY);

Error:

Exception in thread "main" com.splunk.HttpException: HTTP 401 -- {"status":1}
at com.splunk.HttpException.create(HttpException.java:84)
at com.splunk.HttpService.send(HttpService.java:500)
at com.splunk.Service.send(Service.java:1297)
at com.splunk.HttpService.post(HttpService.java:348)
at com.splunk.Service.login(Service.java:1125)
at com.Practice.SplunkConnection.secureConnection(SplunkConnection.java:132)
at com.Practice.SplunkConnection.main(SplunkConnection.java:79)
Picked up JAVA_TOOL_OPTIONS: -agentlib:jvmhook

Tags (2)
0 Karma

p_gurav
Champion

Can you try:
ServiceArgs loginArgs = new ServiceArgs();
loginArgs.setUsername("username");
loginArgs.setPassword("password");
loginArgs.setHost(host);
loginArgs.setPort(Integer.parseInt(port));
Service.connect(loginArgs);

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

.conf25 Global Broadcast: Don’t Miss a Moment

Hello Splunkers, .conf25 is only a click away.  Not able to make it to .conf25 in person? No worries, you can ...

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...