How can I extract a variable from an apiproxy kvm?

Not applicable

I've used this management api call to create a KVM inside a proxy and when I make a get call to check if it's there it shows that it is:

{  
 "name" : "map_name",
 "encrypted" : "false",
 "entry" : [ 
  {
   "name" : "key",
   "value" : "*****"
  } 
 ]
}

So in that proxy I have the following two policies:

KVM policy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="get-token">
    <DisplayName>get token</DisplayName>
    <Get assignTo="token" index="1">
        <Key>
            <Parameter>map_name</Parameter> //I've tried both "map_name" and "key"
        </Key>
    </Get>
    <Scope>apiproxy</Scope>
</KeyValueMapOperations>

Service callout:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="Service-Callout-1">
    <DisplayName>Service Callout-1</DisplayName>
    <Properties/>
    <Request clearPayload="true" variable="myRequest">
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
        <Set>
            <Headers>
                <Header name="Authorization">{token}</Header>
            </Headers>
        </Set>
    </Request>
    <Response>calloutResponse</Response>
    <HTTPTargetConnection>
        <Properties/>
        <URL>https://mocktarget.apigee.net/apigee</URL>
    </HTTPTargetConnection>
</ServiceCallout>

When I try to make a call to my proxy I get the following error message:

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

When I use trace I saw that the variable "token" isn't assigned.

What can I do to fix this?

Solved Solved
1 2 1,478
1 ACCEPTED SOLUTION

hadleena
Participant III

Hi @Friso Denijs,

You have missed the 'mapIdentifier' attribute in the KVM policy.

Can you try giving the KVM name as value for 'mapIdentifier' like this and check once:

<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="get-token" mapIdentifier="map_name"> 

Hope it helps!

View solution in original post

2 REPLIES 2

hadleena
Participant III

Hi @Friso Denijs,

You have missed the 'mapIdentifier' attribute in the KVM policy.

Can you try giving the KVM name as value for 'mapIdentifier' like this and check once:

<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="get-token" mapIdentifier="map_name"> 

Hope it helps!

Hi @Friso Denijs - Also, if you're getting an encrypted value, you need to a private. prefix on your variable, like this:

<GetassignTo="private.token"index="1">