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!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...