How to add or update KVM in which key is an integer?

Not applicable

I am having a KVM in which keys are integers and its corresponding value is a string. I can add it in the management UI. But when I try to edit using a KVM policy as given below I am getting this error

{ "fault": { "faultstring": "KeyValueMap entry name 1 is invalid", "detail": { "errorcode": "keyvaluemap.service.keyvaluemap_entry_name_invalid" } } }

I need to update an already existing KVM entry. How to do it?

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="Key-Value-Map-Operations-2" mapIdentifier="FooBar"> 
<DisplayName>Key Value Map Operations-2</DisplayName> 
<Properties/> 
<ExpiryTimeInSecs>60</ExpiryTimeInSecs> 
<Put> 
<Key> 
<Parameter>1</Parameter> 
</Key> 
<Value>Foo</Value>
</Put> 
<Scope>environment</Scope> 
</KeyValueMapOperations>
0 5 616
5 REPLIES 5

Not applicable

I tried the same thing but i got the same error, but then i tried to set it using "ref" to a variable, there was no error but the key was stored as a float no 1.0, then i used the same 1.0 as literal value and it worked, so i think this is how we can set a key with a number in KVM policy, @Anil Sagar your comments?

I don't know why a Key with a single parameter consisting of a single-digit integer does not work.

I suppose there is a simple workaround - just use a second parameter that contains a fixed-string .

<KeyValueMapOperations name="Key-Value-Map-Operations-2" mapIdentifier="FooBar"> 
  <ExpiryTimeInSecs>60</ExpiryTimeInSecs> 
  <Put> 
    <Key> 
      <Parameter>anything</Parameter> 
      <Parameter>1</Parameter> 
    </Key> 
    <Value>Foo</Value>
  </Put> 
  <Scope>environment</Scope> 
</KeyValueMapOperations>

But then key will be like “anything__1” ?

Yes, that's true. But is that a problem? You can retrieve with the corresponding Get policy

<KeyValueMapOperations name="Key-Value-Map-Operations-3" mapIdentifier="FooBar"> 
  <ExpiryTimeInSecs>60</ExpiryTimeInSecs> 
  <Get> 
    <Key> 
      <Parameter>anything</Parameter> 
      <Parameter>1</Parameter> 
    </Key> 
  </Get> 
  <Scope>environment</Scope> 
</KeyValueMapOperations>

Problem? Is your objection about the aesthetics? I agree, it's not beautiful. But it shouldn't be an obstacle.

I noticed that a single-digit integer key value does work in CPS (Core Persistence Services) enabled orgs but not in non-CPS orgs. You can check your org by calling the management API:

GET {{MGMTSVR}}/v1/o/{{ORG}}

In CPS enabled orgs, the result will contain:

{
   "name": "features.isCpsEnabled",
   "value": "true"
}

Eventually all orgs will be CPS enabled.

https://apidocs.apigee.com/api-reference/content/api-reference-getting-started#cps

https://docs.apigee.com/release/deprecated-features#cps