Getting Data In

Is there a way to update existing values in KV store via REST API?

splunk403
Explorer

Like insert and delete, do we have any rest implementation for update? Or is there anyway to update the existing values of kvstore

reference:
http://dev.splunk.com/view/SP-CAAAEZX

for insert:

 // Use the request method to send a REST POST request
            // to the storage/collections/data/{collection}/ endpoint
            service.request(
                "storage/collections/data/mycollection/",
                "POST",
                null,
                null,
                JSON.stringify(record),
                {"Content-Type": "application/json"},
                null)

for delete:

/ Delete the record that corresponds to the key ID using
            // the del method to send a DELETE request
            // to the storage/collections/data/{collection}/ endpoint
            service.del("storage/collections/data/mycollection/" + encodeURIComponent(form_keyid))
                .done(function() {

Thanks

0 Karma

illescas
Engager

You can update a kv value by doing the same service.request() as you do for an insert but just modify the REST API call. Which is to add the _key for the record after your collection https://< localhost >/..data/mycollction/keyID

The only other thing you need to remember to do is make sure the record includes all your other key values, or else it will update those to empty

         var record = { 
                "CustID": form_id, 
                "CustName": form_name, 
                "CustStreet": form_street,
                "CustCity": form_city,
                "CustState": form_state,
                "CustZip": form_zip 
         }; 

         var keyID = '5410be5441ba15298e4624d1'

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

ChrisG
Splunk Employee
Splunk Employee

I'm not that familiar with using the REST API with KV Store, but in case this is useful:

There is information about updating on the page Use the REST API to manage KV Store collections and data.

There are also some examples in the REST API Reference, for instance: storage/collections/config/{collection} POST

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...