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