Key Value map not working

Not applicable

Hi,

I'm trying to use a key-value map in my application. I've tried creating apiproxy scoped maps and organization maps, but no matter what I seem to do, the values are never returned for the data. I've tried using the examples from the docs and I face the same issue. I asked a stackoverflow question on it here http://stackoverflow.com/questions/27850597/organization-level-key-value-map-operation-in-apigee but as of yet I've had no response. But basically I can use

   <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="Key-Value-Map-Operations-2" mapIdentifier="newkey">
<DisplayName>Key Value Map Operations 2</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>

<Get assignTo="mynewvar" index="1">
    <Key>
        <Parameter ref="k1"></Parameter>
    </Key>
</Get>

<Scope>apiproxy</Scope>
</KeyValueMapOperations> 


And mynewvar is always empty. If use a PUT field in the same policy it will return what I set in the PUT field. After this I created another policy just to try and return the key value map that was initialised here but it still doesn't work e.g

   <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="Key-Value-Map-Operations-2" mapIdentifier="newkey">
<DisplayName>Key Value Map Operations 2</DisplayName>
<FaultRules/>
<Properties/>
<ExclusiveCache>false</ExclusiveCache>
<ExpiryTimeInSecs>-1</ExpiryTimeInSecs>
<Get assignTo="mynewnewvar" index="1">
    <Key>
        <Parameter ref="k1"></Parameter>
    </Key>
</Get>

<Scope>apiproxy</Scope>
</KeyValueMapOperations> 

I'm unsure as to what I'm doing wrong here and no matter what I try,nothing seems to work. If I use the tools in the docs to list all my keyvaluemaps they appear, but as soon as I use the tool to query for 1 of them, it returns a 404. I feel like this should be really easy but I've been banging my head against a brick wall for 2 days now

Solved Solved
0 10 2,254
1 ACCEPTED SOLUTION

Not applicable

For anyone else who has this problem, the issue was I was using

   <Parameter ref="k1"></Parameter>

To retrieve the value when in fact it should be

   <Parameter>k1</Parameter>

But unfortunately this doesn't seem to be shown in the docs,so not sure if I'm still doing something wrong

View solution in original post

10 REPLIES 10

Not applicable

For anyone else who has this problem, the issue was I was using

   <Parameter ref="k1"></Parameter>

To retrieve the value when in fact it should be

   <Parameter>k1</Parameter>

But unfortunately this doesn't seem to be shown in the docs,so not sure if I'm still doing something wrong

Hey Tom -- Please note that the policy reference section "Specifying key names" says that the parameter value must be retrieved in the same way it was set -- either as a literal or as a variable reference.

http://apigee.com/docs/api-services/reference/key-value-map-operations-policy#specifying_key_names

There are two ways to specify a parameter value. One is as a literal, as in this example:

<Parameter>k1<Parameter>

The other is as a variable reference:

<Parameter ref="k1"><Parameter>

In the second case, K1 is merely the name of a variable available to your policy -- a variable probably set to some value other than "K1". So the literal "K1" and the variable "K1" are very different things.

The docs aren't very clear about the alternatives. I'll see if I can improve that.

Thanks,

Steve

@docs

Naturally, While using KVM people tend to provide key in the ref due the default template structure. I was wondering what's wrong with the policy till I land up here. Can we highlight this as a note in KVM policy doc ? Thank you.

@Anil Sagar - I hesitate documenting the current state of the policy template, because it may very well change. In the KVM policy topic, we make multiple mentions of literal vs. reference values. One example of this is in this section http://docs.apigee.com/api-services/reference/key-value-map-operations-policy#specifying_key_names.

Not applicable

Hello Tom,

Thanks for the feedback. This was forwarded to our docs team who happen to be working on that section this week. We appreciate you getting back to us on this.

This still appears to be a problem in the documentation.

@Floyd Jones Looking at the docs, there are tons of Parameter entries, and I agree with @James Gaythwaite that they don't clearly explain the difference between

<Parameter>value</Parameter

and

<Parameter ref="varContainingValue"/>

and

<Parameter ref="varContainingValue">valueIfVariableIsNullOrNonexistent</Parameter>

Maybe this pattern (which exists many other places in Edge) can be explained well somewhere, or maybe it already is somewhere and should be linked from the KVM page.

Thanks James and Mike. Agreed. See Steve Traut's comments above.

I've updated the docs. See if what's there helps sort this out.

http://apigee.com/docs/node/249

Steve

We got another question from a user having troubles grokking this, so I did some testing and made some more doc tweaks. Bottom line, all said and done, a literal key name gets created (which contains literal values). The key name comes from somewhere, whether you set a literal name in the policy or use a variable containing a value that gets used for the key name.

On retrieve or delete, you need to ask for the exact name of the key that exists in the KVM, whether you specify that name with a literal or with a variable that contains the correct value.

When specifying a name, use *either* the literal OR the variable reference. Not both.

Following is the update I made in the docs:

----

Specifying and retrieving key names

With the <Parameter> and <Value> elements, you can specify either a literal value (where the value is between the opening and closing tags) or use the ref attribute to specify the name of a variable whose value should be used at runtime.

The Parameter element deserves special mention, because it determines the name of the key that gets created, as well as the key name you want to retrieve or delete. Following are two examples. The first specifies a key name literally, and the second specifies a key name using a variable. Let's assume the following are used to create keys in a KVM:

<Parameter>key_name_literal</Parameter>
<Parameter ref="key.name.variable"></Parameter>

In the first instance, the literal value of "key_name_literal" is stored in the KVM as the key name. In the second instance, whatever value is in the key.name.variable becomes the name of the key in the KVM. For example, if the key.name.variable contained the value foo, the key would be named "foo".

When you want to retrieve the key and a key value with a GET operation (or delete with a DELETE operation), the <Parameter> setting needs to match the key name in the KVM. For example, if the key name in the KVM is "foo", you can either specify the literal value with <Parameter>foo</Parameter> or specify a variable that contains the exact value "foo", like this: <Parameter ref="variable.containing.foo"/>.

----

Interesting side note. I also found that when using the <InitialEntries> element, as soon as I saved my proxy in the UI (assuming it's deployed), the keys get created. The proxy doesn't need to be executed.