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?

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