Knowledge Management

Correct syntax for service.post method for KV store? (Splunk JS SDK)

nprab428
Engager

I"m trying to POST to a KV Store in JS. Currently, I'm able to use the service.request method, with POST as the method type. Example from the KV Store tutorial:

 service.request(
                "storage/collections/data/mycollection/",
                "POST",
                null,
                null,
                JSON.stringify(record),
                {"Content-Type": "application/json"},
                null)
                    .done(function() { 
                         (...)
                    });

I would like to convert this syntax to the service.post method. However, I don't know how to structure the params object to properly include the content-type header and record. My best attempt:

 service.post("storage/collections/data/mycollection/",
                                                {
                                                    body: JSON.stringify(record),
                                                    headers: {
                                                        'Content-Type': 'application/json'
                                                    }
                                                },
                                                function() {
                                                    if(!err) (...); 
                                                }
                                            );

This throws a 400 error, with an error message "Must supply 'Content-Type' header set to 'application/json'

Any ideas on how to proceed?

Tags (2)

kartikm4023
Engager

have u found solution for this issue?

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

.conf25 Global Broadcast: Don’t Miss a Moment

Hello Splunkers, .conf25 is only a click away.  Not able to make it to .conf25 in person? No worries, you can ...

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...