Splunk Dev

How do I format the _key with splunk-python-sdk KVStoreCollectionData.insert data parameter?


I am sending an insert request via the splunk-python-sdk using the class splunklib.client.KVStoreCollectionData(collection) described here: https://docs.splunk.com/Documentation/PythonSDK. But I am throwing an error that is inconsistent with the documentation. Does the insert method require a specific syntax for the _id pair?

The reference documentation for the insert method states, "...An _id field will be generated if not assigned in the data."

When I try to insert a new record with a populated _id field, however, I get a stack trace.

Here is my abbreviated code:

        kvStoreConn = client.connect(**kwargs)
        print("Connected to KVStore Successfully")
        collection = kvStoreConn.kvstore[props.get('dcCollection')]
        kvData = collection.data
    except AuthenticationError:
        print("Failed to connect")

    for record in allRecords:
        recID = record.get('_id')
        kvRecord = 'None'
        except splunklib.binding.HTTPError as herror:
            print ('Found HTTPError: ', herror)
            print('No record found.')

My print methods return this:

Found HTTPError:  HTTP 400 Bad Request -- The _id field is a reserved field and may not be present in a document or query.
No record found.

My POST looks like this [edited for clarity]

  "_id": "5bb27674d6a97e32ed36fc82",
  "submissionName": "U.S. Voluntary Green Power Market Data 2017",
  "abstract": "This data book provides certain data behind figures and tables found in the NREL report Status and Trends in the U.S. Voluntary Green Power Market 2017 Data. These data reflect estimates based on the best available data.",
  "sectors": [
    "Solar Power",
    "Wind Energy"
  "disciplines": [
    "Solar Energy"
  "nrelCenter": "6A20",
  "publisher": "National Renewable Energy Laboratory",
  "fundingOrganization": "DOE",
  "projectTitle": "Green Power Markets",
  "fundingOffice": "Office of Strategic Programs (EE-SP)",
  "projectNumber": "GO28308",
  "pubId": "72204",
  "hasConsent": "1",
 "moratorium": "2018-10-07 18:00:00",
  "keywords": [
    "green power sales",
    "energy certificates",
    "community solar",
  "created": "2018-10-01 13:33:08",
  "publicationDate": "2018-10-01 13:33:08",
  "updated": [
    "2018-10-08 10:10:15",
    "2018-10-08 10:09:53"
  "status": "Publicly accessible",
  "appName": "dc",
  "userId": "user",
  "submitted": "2018-10-01 14:01:06",
  "DOI": "10.7799/1476631"
0 Karma
Get Updates on the Splunk Community!

March Community Office Hours Security Series Uncovered!

Hello Splunk Community! In March, Splunk Community Office Hours spotlighted our fabulous Splunk Threat ...

Stay Connected: Your Guide to April Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars in April. This post ...

Want to Reduce Costs, Mitigate Risk, Improve Performance, or Increase Efficiencies? ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...