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!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...