Splunk Enterprise

CORS POLICY ISSUE : Unable to call REST API using custom Javascript Ajax and Httpget method

Javoraqa
Engager

Hi Team,

I am trying to get list of all jobs on click of button using its Public API in Splunk dashboard but i am getting CORS policy issue. The same when called using POSTMAN i am getting list of jobs but not in splunk.
Below are the methods which are already implemented :-

----------server.conf -----------

[httpServer]
crossOriginSharingPolicy = *
crossOriginSharingHeaders = *
allowBasicAuth = true

[general]
listenOnIPv6 = yes

( 1  )---------------------JS CODE-------------------

console.log('Check require !');
require([
"jquery",
"splunkjs/mvc/searchmanager",
"splunkjs/mvc/simplexml/ready!"
], function(
$, SearchManager
) {
var auth_token ="****";
$(".button1").on("click", function (){
console.log('1234567890');
var settings = {
"crossDomain": true,
"url": "https://********************/api/2.0/jobs/runs/list",
"contentType": "application/x-www-form-urlencoded;charset=utf-8",
"method": "GET",
"headers": {
"Authorization": "Bearer ****",
"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"
}
}

$.ajax(settings).done(function (response) {
console.log(response);
});
});
});

( 2  )---------------------ERROR-------------------

Access to XMLHttpRequest at 'https://************/api/2.0/jobs/runs/list?_=2839475543271' from origin 'http://host.example.com:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

-----------------------------------------------

Need an immediate help on above issue ? please help
@thambisetty@ITWhisperer ,  @niketn , @gcusello , @isoutamo ,  @woodcock 

0 Karma

Javoraqa
Engager

Can someone please help on above issue , as this is a roadblocker ?

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...