How to perform throttling based on api endpoint

Not applicable

I have two api products for an api proxy. The resource path in those products is api/v1/* . The two api products have different quota policy. One has 5 calls per hour and another has 10 calls per hour. I decide the api product based on a header value "account". I have 20 different endpoints such as api/v1/users, api/v1/employees and api/v1/accounts.

Now I want to perform throttling based on a single api endpoint. For GET api request for the path api/v1/contacts alone I want to give 100 calls per hour. How to do this?

1 7 770
7 REPLIES 7

@chockalingam

Check this video, let me know if it helps.

https://www.youtube.com/watch?v=z8Rj_VzSbh4

where is the link?

I updated the link.

did you figure out the issue?

I tried it but didn't find any way. Can you let me know if you got any. As of now i changed the quota limit to maximum till i find the definite solution.

Check my answer.

I want to perform throttling based on a single api endpoint. For GET api request for the path api/v1/contacts alone I want to give 100 calls per hour. How to do this?

The Quota policy accepts an Identifier element for configuration. You can use THAT to apply a quota to a particular path, if you use, as identifier, the proxy.pathsuffix context variable, and a fixed value of 100.

Typically in Apigee, you would configure your Quota limits (number and time interval) on the API Product. And then the Quota policy refers to the variables on the product for the count and time interval. But there's no requirement that you must refer to the variables set from the API Product.

One way to do what you want is to have a set of quota settings like this:

{
  "/api/v1/contacts" : 100,
  "/api/v1/employees" : 50,
  "/api/v1/accounts" : 40
}

In other words this data maps from path suffix to the quota limit.

We need both of these data items in order to enforce the quota. The quota policy will look like this:

<Quota name='Q-1'>
  <Interval>1</Interval>
  <TimeUnit>hour</TimeUnit>
  <Allow countRef='SOME_VARIABLE_HERE'/>
  <Identifier ref='proxy.pathsuffix'/>
</Quota>

The variable proxy.pathsuffix variable will hold "/api/v1/contacts" or whatever the path suffix is. How do we get the number into a variable?

Maybe with a jsonPath in AssignMessage

<AssignMessage name='AM-JSONPath'>
  <AssignVariable>
    <Name>quota_limits</Name>
    <Value>
{
  "/api/v1/contacts" : 100,
  "/api/v1/employees" : 50,
  "/api/v1/accounts" : 40
}
    </Value>
  </AssignVariable>


  <AssignVariable>
    <Name>json_path_1</Name>
    <Template>$['{proxy.pathsuffix}']</Template>
  </AssignVariable>


  <AssignVariable>
    <Name>mapped_quota</Name>
    <Template>{jsonPath(json_path_1,quota_limits)}</Template>
  </AssignVariable>


</AssignMessage>

And then a Quota policy like this:

<Quota name='Q-1'>
  <Interval>1</Interval>
  <TimeUnit>hour</TimeUnit>
  <Allow countRef='mapped_quota'/>
  <Identifier ref='proxy.pathsuffix'/>
</Quota