5

There is a custom attribute assigned to a developer called 'XYZ'. In the API proxy, how can the AccessEntity policy (along with the AssignMessage and ExtractVariable policies as given in the tutorial: http://apigee.com/docs/api-services/content/retrieve-entity-profiles-using-accessentity) be used to retrieve the value for it so that it can be accessed further in Javascript? The example given in the tutorial doc is not very clear.

I have the following configurations that are not working. 'XYZ' is the name of the developer's custom attribute:

AccessEntity policy-

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AccessEntity async="false" continueOnError="false" enabled="true" name="access-developer-attribute">
    <DisplayName>AccessEntity Developer Attribute</DisplayName>
    <FaultRules/>
    <Properties/>
    <EntityIdentifier ref="XYZ"></EntityIdentifier>
    <EntityType value="developer"></EntityType>
</AccessEntity>

AssignMessage policy -

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="convert-accessentity-xml-to-message-request">
    <DisplayName>Convert AccessEntity Xml To Message Request</DisplayName>
    <FaultRules/>
    <Properties/>
    <Set>
        <Headers/>
        <QueryParams/>
        <FormParams/>
        <Verb/>
        <Path/>
        <Payload type="text/xml">AccessEntity.access-developer-attribute</Payload>
    </Set>
    <AssignVariable>
        <Name>name</Name>
        <Value/>
        <Ref/>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="true" transport="http" type="request">accessentity.XYZ-attribute</AssignTo> 
</AssignMessage>

ExtractVariables policy -

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="retrieve-developer-attribute">
    <DisplayName>Retrieve Developer Domain</DisplayName>
    <FaultRules/>
    <Properties/>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <Source>accessentity.XYZ-attribute</Source> 
    <VariablePrefix>developer_attribute</VariablePrefix>
    <XMLPayload stopPayloadProcessing="false">
        <Namespaces/>
        <Variable name="xyz" type="string">
            <XPath>/Developer/Attributes/XYZ</XPath>
        </Variable>
    </XMLPayload>
</ExtractVariables>

Javascript -

var xyzValue = context.getVariable("developer_attribute.xyz");
Deepti N M
  • 143
  • 1
  • 8

1 Answers1

2

The EntityIdentifier ref in AccessEntity refers to a variable that identifies the developer to be referenced. There are multiple types of data you can pass in to identify the developer (developeremail, developerid, appid, consumerkey). It is best to include the type of data being used in the EntityIdentifier element. In the example below, the consumer key is stored in the variable client_id:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AccessEntity async="false" continueOnError="false" enabled="true" name="access-developer-attribute">
    <DisplayName>AccessEntity Developer Attribute</DisplayName>
    <EntityIdentifier ref="client_id" type="consumerkey"></EntityIdentifier>
    <EntityType value="developer"></EntityType>
</AccessEntity>

Also, your AssignMessage policy is not correctly retrieving from the AccessEntity.access-developer-attribute variable. You need curly braces around the variable name, otherwise the payload will be the text "AccessEntity.access-developer-attribute".

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="convert-accessentity-xml-to-message-request">
    <DisplayName>Convert AccessEntity Xml To Message Request</DisplayName>
    <Set>
        <Payload type="text/xml">{AccessEntity.access-developer-attribute}</Payload>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="true" transport="http" type="request">accessentity.XYZ-attribute</AssignTo> 
</AssignMessage>

You'll notice also that I've deleted unused fields in the policies. This makes the policies more readable.

Your ExtractVariables and JavaScript should work fine.

Mike Dunker
  • 1,830
  • 13
  • 17
  • Thank you for clarifying that the EntityIdentifier ref in AccessEntity refers to a variable that identifies the developer to be referenced. In my use case, I need to identify developers who have registered apps to use an API Product. Should I be using the appid to access the developer who is using that particular API Product? If so, where is the appid available? Or can the developer for a particular API product be identified by API Product name? – Deepti N M Feb 24 '14 at 19:33
  • 1
    It really depends on the information you have at the time the proxy is running. If you are using OAuth or API key validation (via the OAuthV2 and VerifyAPIKey policies), the custom attributes are automatically populated after the token or API key is validated. In practice I find that I rarely need to call AccessEntity. – Mike Dunker Feb 24 '14 at 21:00
  • Thank you for the answers. I corrected AccessEntity and AssignMessage as per your answer after I understood 'EntityIdentifier ref'. I also corrected the Xpath in ExtractVariables to '/Developer/Attributes/Attribute/Name' and included XPath '/Developer/Attributes/Attribute/Value' to get the value of the attribute. It all worked then. Thanks. – Deepti N M Feb 27 '14 at 18:57
  • This is a great thread! Is there any way to use this XYZ custom attribute as a query parameter? Basically, is the following scenario possible - developer with custom attribute accesses with his API key, we extract this custom attribute and then use it as one of the query parameters in a request sent to the endpoint? – Miroslav Lazovich Apr 10 '14 at 17:14
  • Hi Miroslav, absolutely you can! You can use the AssignMessage to set a query parameter on an existing payload. See the example AssignMessage named GenerateRequest at http://apigee.com/docs/api-services/content/generate-or-modify-messages-using-assignmessage , except that you would use createNew="false" to add the query parameter to the existing message. – Mike Dunker Apr 11 '14 at 04:50