Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How can I use the JavaScript policy to examine custom attributes from multiple API Products

I am trying to get all custom attributes under a API-product using JavaScript policy.

Scenario - My App might have multiple products and each product will have its own custom attributes.

I tried

 context.getVariable('verifyapikey-{policy_name}.app.apiproducts) ;

which gives me Ljava.lang.String087@10. But when I iterate through that object I got list of product

names. Then I loop through list with product names and tried to get custom attribute value using below

code, but i got empty value.

context.getVariable('verifyapikey.{policy_name}.{product_name}.{custom_attribute}' )

Is there any other way or other policy in apigee to accomplish this.

Solved Solved
0 4 939
1 ACCEPTED SOLUTION

I think the pattern is

verifyapikey.{policy_name}.apiproduct.{custom_attribute_name}

In other words the variable name is not dependent upon the name of the API Product that contributes the attribute.

All the custom attributes are lumped into one bucket. Can you try that?

BUT, having said that...I'd like to detour into a related issue.

Why do you have a set of products for a single API Key. It's certainly valid and legal. But in my experience most people who do that are using the API Product concept incorrectly.

An API Product should wrap up all the API Proxies needed for a particular use case. In most cases there will be one API Product associated to an API Key.

View solution in original post

4 REPLIES 4