How can I add values from an encrypted KVM to my request's queryparams?

Not applicable

I'm trying to assign encrypted values from a KVM to a request's query params, however, I get the following error message on the assign message policyL

{"fault":{"faultstring":"Unresolved variable : private.var1","detail":{"errorcode":"messaging.runtime.UnresolvedVariable"}}}

When I check the kvm policy I see it only assigned a timetaken variable.

My KVM policy:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="get-kvm" mapIdentifier="kvm">
    <DisplayName>get kvm</DisplayName>
    <Properties/>
    <ExclusiveCache>false</ExclusiveCache>
    <ExpiryTimeInSecs>300</ExpiryTimeInSecs>
    <Get assignTo="private.var1" index="1">
        <Key>
            <Parameter>key1</Parameter>
        </Key>
    </Get>
    <Get assignTo="private.var2" index="1">
        <Key>
            <Parameter>key2</Parameter>
        </Key>
    </Get>
    <Scope>environment</Scope>
</KeyValueMapOperations>
My KVM:
{
    "encrypted": true,
    "entry": [
        {
            "name": "key2",
            "value": "*****"
        },
        {
            "name": "key1",
            "value": "*****"
        }
    ],
    "name": "kvm"
}

My policy trying to use the values:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="assign-kvm">
    <DisplayName>assign kvm</DisplayName>
    <Properties/>
    <Set>
        <QueryParams>
            <QueryParam name="var1">{private.var1}</QueryParam>
            <QueryParam name="var2">{private.var2}</QueryParam>
        </QueryParams>
    </Set>
</AssignMessage>

I created the KVM by making an API call to https://api.enterprise.apigee.com/v1/organizations/{{org_name}}/keyvaluemaps/ with this JSON body:

{  
 "name" : "kvm",
 "encrypted" : "true",
 "entry" : [ 
  {
   "name" : "key1",
   "value" : "value1"
  },
  {
   "name" : "key2",
   "value" : "value2"
  } 
 ]
}
0 8 961
8 REPLIES 8

@Friso Denijs I see no issues with those policy configurations. Did you create "kvm" in the right environment?

I used the management API to create it, but I didn't see an option to select an environment for it.

Hi @Friso Denijs

Can you please confirm the scope of the KVM that you have created. Also one method of checking if the KVM is being hit or not is to remove the word private and execute the API. It will fail with error saying it failed to set variable <variable name>.

In worst case - Please redeploy the proxy and try.

Regards,

Santosh

Hi @Friso Denijs -

Couple of things:

  • Your closing key1 Parameter element is misspelled. Should be
    <Parameter>key1</Parameter>
  • Be sure your kvm is created in the right environment.
    If you're creating the environment via the UI, be sure the environment you want is selected before creating the KVM. This is really, really easy to miss, especially since the default selection is "prod" whenever you go to that page.

    5396-kvm.png

I fixed the spelling mistake, but it still doesn't work. I created the KVM using the Management API

Hi @Friso Denijs ,

Can you please provide the API call that you used to create KVM. There are different calls for creating KVM at apiproxy, environment and org level. We should use appropriate value of scope element in the policy.

Thanks,

Santosh

Hi @Friso Denijs ,

I see that this API call will create the KVM at organization level -

http://docs.apigee.com/management/apis/post/organizations/%7Borg_name%7D/keyvaluemaps

Can you please change the value of scope field in the KVM Operations policy to organization and see if it works. Explanation about scopes can be found here -

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

Thanks,

Santosh