How to Extract Information from Verify API Key Variables.

Not applicable

Team,

I want to extract some information from verifyAPIKey flow variables . My verifyApiKey policy is located in the preflow and so I used 'ExtractVariable" policy to get the below information , i am not sure what value I need to provide in the "Source" attribute in this case. I tried "request" & "message" but both are notworking and still i am not able to get the values of the below flow variables. Please advice

Examples:

verifyapikey.VerifyAPIKey.apiproduct.access public
verifyapikey.VerifyAPIKey.apiproduct.consumer-application-name abc
verifyapikey.VerifyAPIKey.apiproduct.name efg
verifyapikey.VerifyAPIKey.client_id E5fJ43i08Lk3fVRBPgyd10DdzgAUJp9r
  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="ExtractConsumerApplicationName">
    <DisplayName>ExtractConsumerApplicationName</DisplayName>
    <Properties/>
    <Variable name="consumer-application-name">
        <Pattern>{verifyapikey.VerifyAPIKey.apiproduct.consumer-application-name}</Pattern>
    </Variable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <Source clearPayload="false">message</Source>
    <VariablePrefix>productinfo</VariablePrefix>
</ExtractVariables>

Note:- VerifyApiKey & ExtractConsumerApplicationName polices located in the preflow and  I want to use the new flow variable(ConsumerApplicationName) in polices located in Request/Response flow 
0 5 1,210
5 REPLIES 5

Not applicable

Hello @Murali,

I would say the easiest way would be to do the following in a javascript policy just after the verify key policy.

context.setVariable("ConsumerApplicationName",context.getVariable("verifyapikey.VerifyAPIKey.apiproduct.consumer-application-name"));

Hope this help.

HI @Murali

My first question to you would be - Why do you need to copy to a new variable if its already available as a flow variable ? This should be available across the flows. I would recommend using the same variable

If you still want to use the new variable - You can either do what @MEGHDEEP BASU suggested or you could do an AssignVariable within Assign Message policy

<AssignVariable>
  <Name>ConsumerApplicationName</Name>
  <Ref>verifyapikey.VerifyAPIKey.apiproduct.consumer-application-name</Ref>
  <Value>somedefaultvalue</Value>
</AssignVariable> 

Refer to the doc here

@Thanks Basu/Sai - yes both JS/AssignMessage approach worked..

verifyapikey.VerifyAPIKey.apiproduct.consumer-application-name is really a long name , so i dont want to use as it is.

@Murali

I would still use the long name as its generated by Apigee. It also eliminates the execution of a policy (which does not do any thing else but sets the value to another variable)

Please accept the answer by clicking the "Accept" button so that this post is useful for others as well

Yes as meghdeep as already already easiest way would be to use context.getVaribale in java script to fetch the flow variable value and assign that value to new variable using context.setVariable.