Dashboards & Visualizations

Can i use REST API of Splunk itself in Splunk?

kartik13
Communicator

I am trying to make a custom dashboard as Splunk dashboard using a third party framework. I am trying to connect to splunk through REST API ,but during ajax call its giving me Request header field Access-Control-All-Headers is not allowed by Access-Control-Allow-Headers. error.My server.conf config are as follows

    [sslConfig]
sslKeysfilePassword = $1$0RQz5YVamCN2
enableSplunkdSSL = false
[general]
pass4SymmKey = $1$hlhnucAc03F2
serverName = KARTIKES-WS01

[lmpool:auto_generated_pool_download-trial]
description = auto_generated_pool_download-trial
quota = MAX
slaves = *
stack_id = download-trial

[lmpool:auto_generated_pool_forwarder]
description = auto_generated_pool_forwarder
quota = MAX
slaves = *
stack_id = forwarder

[lmpool:auto_generated_pool_free]
description = auto_generated_pool_free
quota = MAX
slaves = *
stack_id = free

[lmpool:auto_generated_pool_enterprise]
description = auto_generated_pool_enterprise
quota = MAX
slaves = *
stack_id = enterprise

[license]
active_group = Free

[httpServer]
crossOriginSharingPolicy = *
allowBasicAuth = false

[general]
listenOnIPv6 = yes

and my ajax request is

$.ajax({
                url:"http://localhost:9080/services/search/jobs/export",
                type:"POST",
                dataType:"json",

                data:JSON.stringify(somedata),
                headers:{
                "Access-Control-Allow-Origin" : "*",
                "Access-Control-Allow-Methods" : "GET,POST,PUT,DELETE,OPTIONS",
                "Access-Control-Allow-Headers": "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"

                },
                crossDomain: true,
             contentType:"application/x-www-form-urlencoded",
                success:function(data){
                    console.log("Data is loaded" + data);
                    },
                error:function(){
                    console.log("Something went Wrong");
                }

      });

So , Can i use REST API in SPlunk itself? Any idea on this?

0 Karma
1 Solution

lguinn2
Legend

Yes, you can run REST API commands in the Splunk search UI. Here is an app that shows examples of exactly how to do it:
REST Endpoint Examples

Download the app and try it out, then look at the implementation to see how they did it!

View solution in original post

jaredlaney
Contributor

Is the error referring to this?

"Access-Control-Allow-Headers": "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"

where you're using Access-Control-Allow-Headers in the variable Access-Control-Allow-Headers?

kartik13
Communicator

yes it was refering to that .I found the solution RESTAPI of Spluk accepts only the Content-Type in headers with following details:

"Content-Type":"application/x-www-form-urlencoded;charset=utf-8"

0 Karma

lguinn2
Legend

Yes, you can run REST API commands in the Splunk search UI. Here is an app that shows examples of exactly how to do it:
REST Endpoint Examples

Download the app and try it out, then look at the implementation to see how they did it!

kartik13
Communicator

Thanks .. I found the solution

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

From Data to Insight: Announcing the Winners of the Splunk Dashboard Contest

Hi Splunkers, First off, thank you to everyone who participated in our very first From Data to Insight: The ...

Splunk Developers: Construct Your Future at the .conf26 Builder Bar

Calling all Splunk architects, platform admins, and app developers: the site is open, and the blueprints are ...

Quick connection discovery mode for forwarders

When a Splunk forwarder loses connectivity to its indexers, it does not always reconnect immediately. In many ...