How to get custom attribute value with out oauth and verifyAPIKey

knandigam
Participant I

Hi,

I am trying to access API product custom attribute value in javascript with out oauth and verifyAPIKey ploicy.

Solved Solved
0 9 725
1 ACCEPTED SOLUTION

Hi @knandigam,

Here you go, a sample proxy which extract the value of custom attribute custom_attr_product on the api product. It uses AccessEntity and ExtractVariables using xpath; AccessEntity returns the data in xml only.

First, the AccessEntity policy. In the AccessEntity policy you have to configure Entitytype properly for the product. Have a look here in the sample.

<AccessEntity name="AE-Product-Detail">
    <EntityType value="apiproduct"/>
    <EntityIdentifier ref="app_name_ref" type="appname"/>
</AccessEntity>

With that policy, Apigee Edge sets a context variable to contain an XML document describing the information associated to the API Product. Then, you can use ExtractVariables to extract one item of interest from that XML document.

<ExtractVariables name="EV-ProductAttr">
    <Source clearPayload="false">AccessEntity.AE-Product-Detail</Source>
    <XMLPayload stopPayloadProcessing="false">
        <Namespaces/>
        <Variable name="custom_attr_product" type="string">
            <XPath>/ApiProduct/Attributes/Attribute[Name='custom_attr_product']/Value/text()</XPath>
        </Variable>
    </XMLPayload>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</ExtractVariables>

access-entity-demo-rev2-2019-07-22.zip


Note - in the attached example, I have added assign message policy to setup the product name in the variable; you can make it dynamic as per your need.

I hope this will be helpful for you.

Thanks,

Ravindra

View solution in original post

9 REPLIES 9

That is possible, you need to pass the product reference like product id in access entity policy so it can load the information of that specific product.

let me know if you need a working sample of this.

Hi Ravindra,

I tired using access entity with apiproduct and developerId from the documentation, but it didn't work for me. Could you provide me the sample of it.

Thanks!!

sidd-harth
Participant V

You need to use Access entity policy, extract the required attributes and then user them in Javascript policy,

https://docs.apigee.com/api-platform/reference/policies/access-entity-policy

Hi @knandigam,

Here you go, a sample proxy which extract the value of custom attribute custom_attr_product on the api product. It uses AccessEntity and ExtractVariables using xpath; AccessEntity returns the data in xml only.

First, the AccessEntity policy. In the AccessEntity policy you have to configure Entitytype properly for the product. Have a look here in the sample.

<AccessEntity name="AE-Product-Detail">
    <EntityType value="apiproduct"/>
    <EntityIdentifier ref="app_name_ref" type="appname"/>
</AccessEntity>

With that policy, Apigee Edge sets a context variable to contain an XML document describing the information associated to the API Product. Then, you can use ExtractVariables to extract one item of interest from that XML document.

<ExtractVariables name="EV-ProductAttr">
    <Source clearPayload="false">AccessEntity.AE-Product-Detail</Source>
    <XMLPayload stopPayloadProcessing="false">
        <Namespaces/>
        <Variable name="custom_attr_product" type="string">
            <XPath>/ApiProduct/Attributes/Attribute[Name='custom_attr_product']/Value/text()</XPath>
        </Variable>
    </XMLPayload>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</ExtractVariables>

access-entity-demo-rev2-2019-07-22.zip


Note - in the attached example, I have added assign message policy to setup the product name in the variable; you can make it dynamic as per your need.

I hope this will be helpful for you.

Thanks,

Ravindra

Thank you Ravindra. I was able access custom attributes.

Hi Ravindra,

Is there any way I can pass dynamically the apiProduct name with out hardcoding in assign message or in access entity policy. I tried multiple ways but didn't work.

<EntityIdentifier ref="appid" type="appid"/> <SecondaryIdentifier ref="apiResource" type="apiresource"/> <EntityType value="apiproduct"/>

<EntityIdentifier ref="apiproductname" type="apiproductname"/> <SecondaryIdentifier ref="apiResource" type="apiresource"/> <EntityType value="apiproduct"/>

there should be some reference you must be passing in the request body or query param but you do not want apikey verification so either you send api product name in the query string or request body (Not recommended) then . only you can get the api product. may I know what is your usecase may be we can help you to find some better solution.

So that means we can't get API product name as a variable.It has to be provided by user.