Dynamic MapIdentifier in KVM

I have below KVM policy in shared flow. Each proxy will access this KVM in the shared flow.

I came to know that we cannot pass dynamic mapIdentifier.

I have 6 proxies. Out of 6 proxies there are 4 proxies who wants to use ClientID entryvalue and other 2 proxies wants to use employeeID entry value of the KVM.

How can this be achieved using parameter reference.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations name="ABC" mapIdentifier="ABC">
    <Scope>environment</Scope>
    <Get assignTo="private.ClientId">
        <Key>
            <Parameter>ClientId</Parameter>
        </Key>
    </Get>
    <Get assignTo="private.refresh_token">
        <Key>
            <Parameter>refresh_token</Parameter>
        </Key>
    </Get>
    <Scope>environment</Scope>
</KeyValueMapOperations>
Solved Solved
0 13 1,423
1 ACCEPTED SOLUTION

Not applicable

see, the clientid is already a private variable in Apigee. It comes as asterisk in trace. So, I will suggest to use another variable name like client_key.

This is the reason you are able to see in private but not in normal assign to

View solution in original post

13 REPLIES 13

Not applicable

You can set the key parameter into a variable before the KVM policy, like client id or employee id. Then use the reference for parameter like below code.

<KeyValueMapOperations async="false" continueOnError="false"

enabled="true" name="Key-Value-Map-Operations-1"

mapIdentifier="urlMapper" >

<DisplayName>Key Value Map Operations 1</DisplayName>

<Scope>environment</Scope>

<Get assignTo="myvar" index="1">

<Key>

<Parameter ref="variable_name"/>

</Key>

</Get>

</KeyValueMapOperations>

Thanks !!

I will set variable using AM before calling this policy in the shared flow.

I hope when ver we call AM from another proxy, the clientID value will be available in the variable as this policy will be in the shared flow

In shared flow also for policy you can put condition for proxy.

You can store that in KVM also and can extract as well.

You implement any better option if you have.

Hi

I am getting error as below when I use <Get assignTo="ClientId" index="1">


  • { "fault": { "faultstring": "Failed to set variable ClientId in KeyValueMapStepDefinition GetKVM", "detail": { "errorcode": "steps.keyvaluemapoperations.SetVariableFailed" } } }

However, when I use <Get assignTo="private.ClientId" index="1"> I get 200 OK response, but I cannot see the value of private.ClientId in trace.

So, I am unable to check if correct value is fetched.

My code is

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations mapIdentifier="ABC" async="false" continueOnError="false" enabled="true" name="GetKVM">
    <DisplayName>GetKVM</DisplayName>
    <ExpiryTimeInSecs>864000</ExpiryTimeInSecs>
    <Scope>environment</Scope>
    <Get assignTo="ClientId" index="1">
        <Key>
            <Parameter ref="request.header.x-api-key"/>
        </Key>
    </Get>   
</KeyValueMapOperations>

I Believe its encrypted KVM, that's the reason your are getting the error when its assign to variable without prefix- "private"

Variable with prefix "private" is a special in apigee runtime, value of the variable is not be shown in UI during trace.

For testing purpose you can print the variable using JS

 print(context.getVariable("private.ClientId"));

Yes I used private.client_key and it worked when I printed in using javascript

when I use <Get assignTo="private.ClientId" index="1"> I get 200 OK response, but I cannot see the value of private.ClientId in trace.

This is expected. That is the point of using the private. prefix for a variable. It tells Apigee to not display the variable in trace. This is to protect sensitive data, like keys or secrets, when performing tracing.

If you want to see a private variable during development, you can introduce a JavaScript policy (as you did) and print the variable, or just use AssignMessage/AssignVariable to assign from one variable to another.

<AssignMessage name='AM-Diags'>
  <AssignVariable>
    <Name>assigned</Name>
    <Ref>private.ClientId</Ref>
    <Value>-unset-</Value>
  </AssignVariable>
</AssignMessage>

The above policy just sets one variable to the value contained in private.ClientId. The value will therefore show in Trace.

The moment we started using below code the calling application started getting CORS error. This error was not appearing earlier when I was not using Parameter ref.

I am not sure how this is related to CORS.

Any Idea ?

<Get assignTo="ClientId" index="1">
        <Key>
            <Parameter ref="request.header.x-api-key"/>
        </Key>
    </Get>   

This is a separate problem, answered separately in the new question you asked.

Not applicable

see, the clientid is already a private variable in Apigee. It comes as asterisk in trace. So, I will suggest to use another variable name like client_key.

This is the reason you are able to see in private but not in normal assign to

I tried using "client_key" but I get below error.

{ "fault": { "faultstring": "Failed to set variable client_key in KeyValueMapStepDefinition GetKVM", "detail": { "errorcode": "steps.keyvaluemapoperations.SetVariableFailed" } } }

since its encrypted KVM, you must use private. as a prefix for the variable.

The KVM policy should look like this:

    <Get assignTo="private.client_key">
        <Key>
           <Parameter ref="request.header.x-api-key"/>
        </Key>
    </Get>
<br>

I am getting error when I use

The OPTIONS call fails because it doesnt get value of request.header.x-api-key

This value is set in verify access token policy and I have condition to execute verifyaccess token only when VERB != OPTIONS.

<Get assignTo="private.client_key">
        <Key>
           <Parameter ref="request.header.x-api-key"/>
        </Key>
    </Get>