How to use custom attributes in Apigee Edge?

Not applicable

I am using Apigee Edge to proxy my API. When connecting to the backend, I want to pass a parameter in the query string. My backend code reads this information from the query parameter.

I want to set this query parameter within the Apigee Edge proxy. The value should be retrieved from a custom attribute, which is set on the API product.

What is the way to achieve my objective using Apigee Edge?

Any help or hint will be appreciated.

1 6 10.8K
6 REPLIES 6

Not applicable

Welcome to the community, @Rakesh Jain.

Post available here talk about it.

Cheers,

Dear @Rakesh Jain ,

Welcome to Apigee Community 🙂

If you would like to have key / value pair specific to API Products & access them runtime based on access token, Apigee Edge has out of the box support for same. You can add API Product custom attributes while creating API product & access same as a flow variable in any of the flow once you add Verify API Key Policy. Find screenshot of same from API Product add screen. You can find more about same here.1544-screen-shot-2015-11-24-at-60952-pm.png

If you would like to store simple key, value pair & retrieve same in runtime during API calls, Apigee KVM policy helps you do that. It stores the key / value pair in Apigee Edge store & using same policy you can able to retrieve same in runtime.

You can also use Apigee Cache using Cache related policies to populate request / response as a cache in apigee Edge.

Hi @Rakesh Jain.

You can set your custom attributes on the API Product through the UI. It will be the last section on the create new API Product page. To set a custom attribute when you create an API Product through the Management API, you can include a JSON array with your attributes:

$ curl -H "Content-Type:application/json" -X POST -d \
'{
  "approvalType": "auto", 
  "displayName": "Test API Product",
  "name": "Test Product",
  "proxies": [ "weatherapi" ],
  "environments": [ "test" ],
  "attributes": [
     {
       "name": "customattribute1",
       "value": "value1"
     },
     {
       "name": "customattribute2",
       "value": "value2"
     }
  ]
}' \
https://api.enterprise.apigee.com/v1/o/{org_name}/apiproducts \
-u email:password 

At runtime, when you want to refer to the custom attribute, you need to use a "Verify API Key" policy in your API Proxy. To read the custom attribute in your policies, refer to:

  • Attach a VerifyAPIKey policy to your proxy:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><VerifyAPIKeyasync="false"continueOnError="false"enabled="true"name="Verify-API-Key">	<DisplayName>Verify API Key</DisplayName>	<Properties/>	<APIKeyref="request.queryparam.apikey"/></VerifyAPIKey>
  • Assuming you followed the above steps and use the exact same names (policy name & attribute name), then you should be able to reference your product custom variable as {verifyapikey.Verify-API-Key.apiproduct.customattribute1} in the remainder of your proxy

Or you can read the custom attribute in JavaScript code:

var customattr1 = context.getVariable("verifyapikey.Verify-API-Key.apiproduct.customattribute1");

@kbouwmeester Thanks, but I want to access custom attribute using JAVA.

It works the same from within Java. You only need to use the MessageContext to get the variable. The syntax is very similar to the syntax provided by Kevin for Javascript.

Thanks bud!