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
Get Updates on the Splunk Community!

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

 Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

🔐 Trust at Every Hop: How mTLS in Splunk Enterprise 10.0 Makes Security Simpler

From Idea to Implementation: Why Splunk Built mTLS into Splunk Enterprise 10.0  mTLS wasn’t just a checkbox ...