Getting Data In

Examples of using variable in REST API search? Is it possible?

the_wolverine
Champion

Are there any examples of how to pass a variable to query when using REST API?

Tags (1)
0 Karma
1 Solution

the_wolverine
Champion

Here's an example of running a saved search and passing a variable to it. In this case, the variable is host field:

$curl -k -u admin:password https://splunkserver:8089/services/search/jobs/export -d search="savedsearch \ MySavedSearch%20host%3Dwolverine*"

(use "MySavedSearch" and input variable host=wolverine* )

I have a saved search named "MySavedSearch" the query of the search contains:

"index=main $host$ | head 100"

I wish there were more examples like this in the documentation so I am providing it here in hopes that it can help someone else.

View solution in original post

the_wolverine
Champion

Here's an example of running a saved search and passing a variable to it. In this case, the variable is host field:

$curl -k -u admin:password https://splunkserver:8089/services/search/jobs/export -d search="savedsearch \ MySavedSearch%20host%3Dwolverine*"

(use "MySavedSearch" and input variable host=wolverine* )

I have a saved search named "MySavedSearch" the query of the search contains:

"index=main $host$ | head 100"

I wish there were more examples like this in the documentation so I am providing it here in hopes that it can help someone else.

the_wolverine
Champion

For example, I want to create a search that accepts a variable input (e.g. IP address) so I can reuse it. After thinking more about this, looks like I can pre-populate Splunk with saved searches that accept such a variable but it would be nice to see cool examples of how other customers have done this.

0 Karma

dart
Splunk Employee
Splunk Employee

Can you expand upon your use case? I'm not clear on what you mean by a variable.

0 Karma
Get Updates on the Splunk Community!

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 ...

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...