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!

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...