Security

401 Unauthorized - REST API using GuzzleHttp

sandyapps
New Member

I am using GuzzleHttp

Login call " services/auth/login " works fine and I get the session token as well.

but after this each call give me following error

Client error: POST https://myip:8089/services/search/jobs resulted in a 401 Unauthorized response: Unauthorized

here is my code:

$host= "https://myip:8089/services/search/jobs";
$request = new \GuzzleHttp\Psr7\Request('POST', $host, [ 'headers' => ['Authorization' => 'Splunk xxxxxxxxxxxxxxxxxxxx',
                                                         'Content-Type' => 'application/x-www-form-urlencoded']]);
$response = $client->send($request, [   'verify' => false,
                                        'form_params' =>   ["search" => 'search index="asm_live" sourcetype=syslog OR sourcetype=syslog_f5asm attack_type attack_type="*" ip_client="*" | stats count']
                                    ]);

I am running in circles and unable to figure out the problem.

Tags (1)
0 Karma

yorkshireandrew
New Member

I found I was getting unauthorised using the 'admin' user but when I created my own with its own group giving it (admin, can_delete, power, splunk-system-role, user) privilages... I was able to get results using that... for example I created user bob then this worked.

.\curl.exe -u bob:bob -k https://127.0.0.1:8089/servicesNS/nobody/search/saved/searches

,I found I was getting unauthorised using the 'admin' user but when I created my own with its own group giving it (admin, can_delete, power, splunk-system-role, user) privilages... I was able to get results using that... for example I created user bob then this worked.

.\curl.exe -u bob:bob -k https://127.0.0.1:8089/servicesNS/nobody/search/saved/searches

0 Karma

sandyapps
New Member

Thank you for your Answer.

Actually I never found a solution for this, we had to use php SDK given by Splunk

its works like a charm 🙂

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

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