How to customize response of quota policy before it reaches limit ?

I have a quota policy set to 200 calls per hour per user.I would like to send response from proxy when the user reaches 150 calls, saying that you have only 50 calls left ,180 saying only 20 left and the end sorry reached wait an hour ?how to i achieve this ?using assign or extract policy?

Solved Solved
1 2 637
1 ACCEPTED SOLUTION

Hi @Archana,

You can use the flow variables of quota policy.

ratelimit.{policy_name}.allowed.count for getting total allowed count in your case 200.

ratelimit.{policy_name}.used.count will give you the used request by users like 150 or 180

And ratelimit.{policy_name}.available.count will give remaining number of requests for user like 50 or 20.

Please refer quota policy flow Variables documentation for details here.

Thanks!

View solution in original post

2 REPLIES 2

Hi @Archana,

You can use the flow variables of quota policy.

ratelimit.{policy_name}.allowed.count for getting total allowed count in your case 200.

ratelimit.{policy_name}.used.count will give you the used request by users like 150 or 180

And ratelimit.{policy_name}.available.count will give remaining number of requests for user like 50 or 20.

Please refer quota policy flow Variables documentation for details here.

Thanks!

@archana ,

Yes, You can implement same in Apigee Edge very quickly. You have full control of request / response payloads in Apigee. Use Javascript Policy to add additional data to the response payload using flow variables that show quota limits.

For example, Let's take the "http://mocktarget.apigee.net/json" as target backend & add quota alerts to the response payload using javascript policy in the response. To answer second part of your question, i.e sending the custom response when limits are reached, You need to use fault rules to set a custom response message when limits are reached.

Please find video below that explains same.

Hope it helps. Keep us posted if any. Attached is the sample proxy for your reference. Make sure you update the quota product references if you are using below code.

demoquota-rev1-2016-09-19-1.zip

Note : Video shows response as "consumed" instead of "available". Response shows Total Quota & Available Quota. Same has been updated in above code.