How to extract developer app custom attributes from an API Key

The AccessEntity policy can be used to extract certain entities from Apigee Edge. This post will focus on Developer Apps, but the same technique can be applied to other types.

The first policy to apply should be the verify API Key policy, to ensure the API key is valid. Then we can use the AccessEntity policy to extract the Developer App as follows:

 
<AccessEntity async="false" continueOnError="false" enabled="true" name="GetApp">  
  <DisplayName>GetAppProfile</DisplayName>  
  <EntityType value="app"></EntityType>  
  <EntityIdentifier ref="request.header.apikey" type="consumerkey"/> 
</AccessEntity> 

Now we have the Developer App available as a flow variable. The XML-formatted profile is stored in the variable named AccessEntity.GetApp. The XML-formatted profile can then be parsed using an XPath expression defined in an ExtractVariables policy that specifies AccessEntity.GetApp as its source.

To understand the XML structure to write XPath expressions, you can inspect an example app via the management API:

curl -u $USERID:$USERPASSWORD \
"https://api.enterprise.apigee.com/v1/o/${org}/apps/${appId}" \
-H "Accept: application/xml" 

Replace all the ${VARIABLES} above, and it should give the XML output. From there, it should be clear which XPath to use to extract that specific attribute.

For example:

<App name="test_app"> 
  --snip-- 
  <Attributes>  
    <Attribute>  
      <Name>key</Name>  
      <Value>value</Value>  
    </Attribute> 
  </Attributes> 
  --snip-- 
</App> 

To extract the attribute with name "key", we can leverage the ‘@Name=’value’ selector:

<ExtractVariables name="ExtractAppAttributes">
   <Source>AccessEntity.GetApp</Source>
   <XMLPayload>
      <Variable name="key" type="string">
         <XPath>/Attributes/Attribute[@Name='key']/Value</XPath>
      </Variable>
      <Variable name="location" type="string">
         <XPath>/Attributes/Attribute[@Name='location']/Value</XPath>
      </Variable>
   </XMLPayload>
   <VariablePrefix>AppAttribute</VariablePrefix>
</ExtractVariables>
Version history
Last update:
‎06-23-2019 06:48 AM
Updated by: