Dashboards & Visualizations

[Noob Question] Why do API calls from Javascript require a special library?

neiljpeterson
Communicator

I am looking at this example. I just want to make a search in Splunk using the the API inside some Javascript.

This indicates I need to have splunk.js on the server making the API call. Am I reading this correctly?

However I can run simple API calls using curl by passing some basic info, like the search and log in creds, and get back the data I want. No extras needed.

Can I not do this same thing using Javascript without needing the Splunk specific js files?

0 Karma

airsplunk
Explorer

As strive says, you don't "need" these per se, but why reinvent the wheel? What these libraries do is wrap up a lot of the low level stuff, providing convenience functions. A line of curl is fine, but what about things like exception handling? Once you start making your code robust, you'll probably find yourself writing something very similar to what their libraries already do.

strive
Influencer

I think it is possible but you may spend lots and lots of time in writing the core scripts. That could be something like writing your own base code similar to what Service class provides.
If you look at the documentation of Service Class at http://docs.splunk.com/DocumentationStatic/JavaScriptSDK/1.4/splunkjs.Service.html they have exposed so many methods to access splunk's resources. It is worth to use the existing libraries and build our features on top of that rather than developing something from scratch.

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...