Getting Data In

How to make a POST request to Splunk API in a SimpleXML javascript dashboard?

herbatology
New Member

How can I use the splunkjs "Service" class to make POST changes to .conf files via the REST API in a Splunk SimpleXML JavaScript Dashboard (embedded via <dashboard script="myscript.js">)?

I've tried to use the documentation, however it is unclear to me, if I can use this class in javascript in a SimpleXML dashboard and how.
https://docs.splunk.com/DocumentationStatic/JavaScriptSDK/1.0/splunkjs.Service.Endpoint.html#splunkj...

Previously I've used SearchManager objects to query the rest API via the "| rest" command, but apparently this command only allows GET requests and not POST. This is not suitable for me as I want to CHANGE a config file directly via a javascript call to the REST API, without a workaround with a custom python search command or elsewhat.

require([
    'jquery', 
    'underscore',
    'splunkjs/http',
    'splunkjs/service',
    'splunkjs/mvc',
    'splunkjs/mvc/searchmanager', 
    'splunkjs/mvc/simplexml/ready!'
], function($, _, Http, Service, mvc, SearchManager, TableView) {
      var endpoint = new splunkjs.Service.Endpoint(service, "search/jobs/12345");
     endpoint.post("control", {action: "cancel"}, function() { console.log("CANCELLED"))});
});
0 Karma

divya1388
Explorer

@herbatology  Did you find any solution to this? I am trying to find an answer for the same question. My use case is to post a Maintenance Window when a submit button on the dashboard is clicked.

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