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!

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

Splunk Decoded: Business Transactions vs Business IQ

It’s the morning of Black Friday, and your e-commerce site is handling 10x normal traffic. Orders are flowing, ...

Fastest way to demo Observability

I’ve been having a lot of fun learning about Kubernetes and Observability. I set myself an interesting ...