adding a value to kvm

I am pretty new to APIGEE and I am trying to use the KVM to store and retrieve some credentials. I will worry about encrypting the values at some point. Now I just want to store the values and be able to retrieve them later.

I have a post operation that I am calling to add a value to the KVM. It is returning with a success (200). I am then calling a GET operation to try and retrieve the value. It is returning a blank as it says it is undefined.

Here is the POST Flot

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="Add-KVM" mapIdentifier="TestKVM">
    <DisplayName>Add TestKVM</DisplayName>
    <Properties/>
    <ExclusiveCache>false</ExclusiveCache>
    <ExpiryTimeInSecs>-1</ExpiryTimeInSecs>
    <Put>
        <Key>
            <Parameter ref="testKey1"/>
        </Key>
        <Value>testValue1</Value>
    </Put>
    <Scope>environment</Scope>
</KeyValueMapOperations>

Here is the GET Flow

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="Get-KVM" mapIdentifier="TestKVM">
    <DisplayName>Get TestKVM</DisplayName>
    <Properties/>
    <ExclusiveCache>false</ExclusiveCache>
    <ExpiryTimeInSecs>-1</ExpiryTimeInSecs>
    <Get assignTo="kvmValue">
        <Key>
            <Parameter ref="testKey1"/>
        </Key>
    </Get>
    <Scope>environment</Scope>
</KeyValueMapOperations>

When I reference the kvmValue value in an assign message step in the response, I get a blank value.

Why is that? Any help would be greatly appreciated.

Solved Solved
1 7 1,545
1 ACCEPTED SOLUTION

Hi @Jamie Beauchamp,

In you populate cache policy you have used a parameter with a reference variable testKey1, where the value contained in this variable will be used to create a key in KVM.

<Parameter ref="testKey1"/>

If you want to give the parameter name as "testKey1" then use it as below in both of the cache policies.

<Parameter>testKey1</Parameter>

Hope this helps, Cheers!

View solution in original post

7 REPLIES 7

Hi @Jamie Beauchamp,

In you populate cache policy you have used a parameter with a reference variable testKey1, where the value contained in this variable will be used to create a key in KVM.

<Parameter ref="testKey1"/>

If you want to give the parameter name as "testKey1" then use it as below in both of the cache policies.

<Parameter>testKey1</Parameter>

Hope this helps, Cheers!

Thank you, that was the issue. Although, now it will only retrieve the value once. I will continue to look at this.

Interesting! What do you mean "it will only retrieve the value once." ?? The KVM-GET does not work the second time through? That's curious.

Actually, it will not add the value still. I can retrieve a value that already exists in the mapping but it will not add my new key/value pair to the map.

Here is the XML I am using to try and create the entry in the map.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-1">
    <DisplayName>Extract Variables-1</DisplayName>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <JSONPayload>
        <Variable name="key">
            <JSONPath>$.key</JSONPath>
        </Variable>
        <Variable name="value">
            <JSONPath>$.value</JSONPath>
        </Variable>
    </JSONPayload>
    <VariablePrefix>kvm</VariablePrefix>
</ExtractVariables>


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="Add-KVM" mapIdentifier="kvmap">
    <DisplayName>Add TestKVM</DisplayName>
    <Properties/>
    <ExpiryTimeInSecs>-1</ExpiryTimeInSecs>
    <Put override="true">
        <Key>
            <Parameter ref="{kvm.key}"/>
        </Key>
        <Value ref="{kvm.value}"/>
    </Put>
</KeyValueMapOperations>

Hi @Jamie Beauchamp,

You don't need to use curly brackets in ref attribute of Parameter. Use it like below and you shall be able to put and get the values in KVM using variable references.

<Key>
	<Parameter ref="kvm.key"/>
</Key>
<Value>{kvm.value}</Value>

Please refer the documentation on the use of KVM with variables and literals in Parameter here.

Yep, that was the issue, thanks for the assist.

I know the Extract Variables is working as I am sending a response that contains the parameter values in it and they are there. Just not sure why I am not able to create an entry. I have checked with my admins and I should have the correct access to do this. Maybe I don't have it but I can't tell what roles I do or do not have.