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!

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