KeyValueMap (KVMAP) operations

2 6 1,241

There is a docs issue and the "Key Value Map Operations" policy itself seems to be incomplete (as of 04/24/2015).

This is what I wanted to do:

  1. Create a new KVMap List using the KeyValueMapOperations policy
  2. Add new keys in my KVMap list - I thought I should be able to call KVMap with InitialEntries and pass the key be reference
  3. Retrieve keys by reference

Creating a new KVMap List

Well, I thought this would work:

<KeyValueMapOperations async="false" continueOnError="false" enabled="true" >
    <DisplayName>KV_Default_Missing_MapID</DisplayName>
    <FaultRules/>
    <Properties/>
    <ExclusiveCache>false</ExclusiveCache>
    <ExpiryTimeInSecs>-1</ExpiryTimeInSecs>
    <InitialEntries>
        <Entry>
            <Key>
                <Parameter>k1</Parameter>
            </Key>
            <Value>v1</Value>
        </Entry>
        <Entry>
            <Key>
                <Parameter>k2</Parameter>
            </Key>
            <Value>v3</Value>
            <Value>v4</Value>
        </Entry>
    </InitialEntries>
    <Scope>organization</Scope>
</KeyValueMapOperations>

Yeah, that's the KVMap policy you drag over....but where is the mapID?

OK, so changing it:

<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="KV_CreateNewEntry" mapIdentifier="DynamicCreationKVMapper">
    <DisplayName>KV_CreateNewEntry</DisplayName>
    <FaultRules/>
    <Properties/>
    <ExclusiveCache>false</ExclusiveCache>
    <ExpiryTimeInSecs>-1</ExpiryTimeInSecs>
    <InitialEntries>
        <Entry>
            <Key>
                <Parameter>JamesBrown</Parameter>
            </Key>
            <Value>InitialEntries_section</Value>
        </Entry>
    </InitialEntries>
    <Scope>organization</Scope>
</KeyValueMapOperations>

...works. Now, this will create a NEW KVMap list called 'DynamicCreationKVmapper'.

Creating new Entries and Keys by Reference

The docs(http://apigee.com/docs/api-services/reference/key-value-map-operations-policy#elementreference) lead you to believe that you can create InitialEntries by reference i.e. key is a reference parameter. That doesn't work.

But, you can PUT new entries into the KVMap List:

<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="KV-Update-Key" mapIdentifier="DynamicCreationKVMapper">
    <DisplayName>KV Update Key</DisplayName>
    <FaultRules/>
    <Properties/>
    <ExclusiveCache>false</ExclusiveCache>
    <ExpiryTimeInSecs>-1</ExpiryTimeInSecs>
    <Put override="true">
        <Key>
            <Parameter ref="key2_ev_policy"></Parameter>
        </Key>
        <Value ref="myvalvar1"/>
    </Put>
    <Scope>organization</Scope>
</KeyValueMapOperations>

Docs match...just wasn't clear that a PUT will create a new entry vs. expect it to be there and error out if not present.

Updating the entry requires that "Put override='true'"!!!

Get the Entry using Key by reference

Well, this is the most straightforward and the docs were correct but the policy was missing the mapID. So, this works:

<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="KV-Get-Key" mapIdentifier="DynamicCreationKVMapper">
    <DisplayName>KV Get Key</DisplayName>
    <FaultRules/>
    <Properties/>
    <ExclusiveCache>false</ExclusiveCache>
    <ExpiryTimeInSecs>-1</ExpiryTimeInSecs>
    <Get assignTo="VALUE_key2_ev_policy_first_entry" index="1">
        <Key>
            <Parameter ref="key2_ev_policy"></Parameter>
        </Key>
    </Get>
    <Scope>organization</Scope>
</KeyValueMapOperations>

@Tom Berwick - hope this helps.

hmmm...Maybe, I should create a video with these flows....let's see what the community says!

Comments
Not applicable

Just updated the article since I had missed the UPDATE of a key path.

Not applicable

You can go here and download a working API Proxy that uses the policies above:

https://github.com/rmdave/se-share/tree/master/kvmap

Not applicable

One of the questions on StackOverflow was to build a composite Key and use that.

<Parameter ref="key1-key2"></Parameter>

Will not work.

You will have to use a Javascript policy with Javascript to build out that composite key. https://github.com/rmdave/se-share/tree/master/kvmap has been updated to show how to do that.

Former Community Member
Not applicable
Not applicable

Hi Dave,

Basically, I have the following kvm structure created via apigee KVM Mgmt apis and I would like to know how to retrieve list of all entries using kvm policy? Please advise

KVM stored at org level:

{

"entry" : [

{ "name" : "Australia", "value" : "AU" }, { "name" : "Canada", "value" : "CA" }, { "name" : "Hong Kong", "value" : "HK" }, { "name" : "Japan", "value" : "JP" }, { "name" : "United States", "value" : "US" }

],

"name" : "Cntry_Of_Domicile"

}

@rdave , @Tom Berwick

Not applicable

@nagesh,

Please go to the github (as mentioned above) and see if the proxy addresses your needs:

https://github.com/rmdave/se-share/tree/master/kvmap

Version history
Last update:
‎04-24-2015 05:36 PM
Updated by: