Reporting

How to start a saved search using REST API

mauhumor
Explorer

How to start a saved search using REST API URL?

I can make a GET the saves searchs, extract the 'search' expression and run it using a POST.

But I could not find any reference on how to start a job passing as an argument a saves search ID instead of the search expression.

Is there a another URL or parameter for that?

Tags (2)
1 Solution

Genti
Splunk Employee
Splunk Employee
curl -k -u admin:changeme -d "search=savedsearch %22Errors%20in%20the%20last%2024%20hours%22" https://localhost:8089/services/search/jobs/

This will call a savedsearch named "Errors in the last 24 hours" - one of the default splunk saved searches..

Check this thread for some more info on how to run rest api searches, how to check if the search has finished, and how to get the results http://answers.splunk.com/questions/8940/

View solution in original post

dishasaxena
Path Finder

You can get the search ID for the saved search by running below command:

curl -k -u user:password https://localhost:8089/servicesNS/admin/search/saved/searches/My_Saved_Search/dispatch -d "trigger_actions=1"

You will get a response like below:

admin__admin__search__RMD53566916a3c467274_at_1376044050_4161

Now you can get the output by running below command:

curl -k -u user:password https://localhost:8089/servicesNS/admin/search/search/jobs/admin__admin__search__RMD53566916a3c46727... --get  -d output_mode=csv -d count=10

Note: admin__admin__search__RMD53566916a3c467274_at_1376044050_4161 is the serach ID you received from output of above command.

jgigliotti
Engager

I use the example to search ID for my saved search however get the following error, any assistance please thanks.

curl -k -u user:password https://localhost:8089/servicesNS/admin/search/saved/searches/My_Saved_Search/dispatch -d "trigger_action=1"


<msg type="ERROR">
 In handler 'savedsearch': Argument "trigger_action" is not supported by this handler.
0 Karma

raugugliaro
New Member

Just FYI for anybody reading this thread its "trigger_actions" not "trigger_action"

0 Karma

Genti
Splunk Employee
Splunk Employee
curl -k -u admin:changeme -d "search=savedsearch %22Errors%20in%20the%20last%2024%20hours%22" https://localhost:8089/services/search/jobs/

This will call a savedsearch named "Errors in the last 24 hours" - one of the default splunk saved searches..

Check this thread for some more info on how to run rest api searches, how to check if the search has finished, and how to get the results http://answers.splunk.com/questions/8940/

Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...