Examples using the Splunk REST API
This section shows some typical use cases for the Splunk REST API. These examples show how to use the servicesNS endpoints to access resources within a user/app context. They also show some of the additional operations available, such as moving an object to a different app or changing the permissions of an object.
Create a new Splunk object for a specific context
Create a saved search for the user Alice that is available from the app, myapp. This saved search is private to Alice.
curl -k -u alice:pass https://localhost:8089/servicesNS/alice/myapp/saved/searches/ \ -d name=mysearch \ -d search=*
Edit a Splunk object
Change the above search created for Alice.
Because this search is private to Alice, she can edit the search.
curl -k -u alice:pass https://localhost:8089/servicesNS/alice/myapp/saved/searches/mysearch \ -d search="index=mai*"
Make Alice's saved search, mysearch, available through the app, myapp. Allow all users permissions to read the saved search.
curl -k -u admin:pass https://localhost:8089/servicesNS/alice/myapp/saved/searches/mysearch/acl \ -d perms.read=* \ -d owner=alice \ -d sharing=app
Edit the search at the shared location. Because the search is now a shared resource, use <nobody> for the <user> context.
curl -k -u alice:pass https://localhost:8089/servicesNS/nobody/myapp/saved/searches/mysearch \ -d search="index=main"
Move an object to a different app
The saved search that was previously available to all in the context of myapp is now only available in the context of otherapp.
curl -k -u admin:pass https://localhost:8089/servicesNS/nobody/myapp/saved/searches/mysearch/move \ -d user=nobody \ -d app=otherapp
Access objects available in all user/app contexts
Using wildcards, access all saved searches that you have permission to view.
For an admin user, this includes other user's private saved searches.
For a non-admin user, you retrieve only saved searches you have permission to view.
curl -k -u admin:pass https://localhost:8089/servicesNS/-/-/saved/searches curl -k -u alice:pw https://localhost:8089/servicesNS/-/-/saved/searches
Creating searches using the REST API
Additional examples and tutorials
This documentation applies to the following versions of Splunk® Enterprise: 6.0, 6.0.1, 6.0.2, 6.0.3, 6.0.4, 6.0.5, 6.0.6, 6.0.7, 6.0.8, 6.0.9, 6.0.10, 6.0.11, 6.0.12, 6.0.13, 6.0.14, 6.0.15, 6.1, 6.1.1, 6.1.2, 6.1.3, 6.1.4, 6.1.5, 6.1.6, 6.1.7, 6.1.8, 6.1.9, 6.1.10, 6.1.11, 6.1.12, 6.1.13, 6.1.14