hi folks
I have two Apps named to test and prod. and I want my test app to be able to hit proxy only 10 times and prod apps are able to hit API proxy only 20 times we have quota attribute in product level but I don't want to use that I want to use custom attributes like set a value in custom attribute as
counter = 10 (for test app)
counter = 20 (for prod app)
so how I refer to these custom attribute values in quota policy for I can be restricted users to hit proxy
for now, I have two policy
verify access key = verify the app
quota policy with below code
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Quota async="false" continueOnError="false" enabled="true" name="Quota-1">
<DisplayName>Quota-1</DisplayName>
<Properties/>
<Allow count="3"/>
<Interval>1</Interval>
<TimeUnit>minute</TimeUnit>
</Quota>
any guidance or help would be really helpful
@anilsagar @Former Community Member @Former Community Member please have a look
Solved! Go to Solution.
@rohanjangid - Yes, this is simple. Make sure the VerifyAccessToken or VerifyAPIKey policy gets executed. Once its verified the token or API Key, then it automatically populates many variables. The app's custom attribute also gets populated.
Flow variables for Verify API Key policy is documented here
Flow variables for VerifyAccessToken is documented here
Depending on which policy you are using, you can use the appropriate flow variable name in the Quota policy. I would recommend you to use the Apigee Trace/Debug UI to see the name of the variable and see if its getting populated correctly and then use that in the Quota policy.
@rohanjangid - Yes, this is simple. Make sure the VerifyAccessToken or VerifyAPIKey policy gets executed. Once its verified the token or API Key, then it automatically populates many variables. The app's custom attribute also gets populated.
Flow variables for Verify API Key policy is documented here
Flow variables for VerifyAccessToken is documented here
Depending on which policy you are using, you can use the appropriate flow variable name in the Quota policy. I would recommend you to use the Apigee Trace/Debug UI to see the name of the variable and see if its getting populated correctly and then use that in the Quota policy.
@ssvaidyanathan thanks i able to do so here is my code for quota policy
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Quota async="false" continueOnError="false" enabled="true" name="Quota-1">
<DisplayName>Quota-1</DisplayName>
<Properties/>
<Allow countRef="verifyapikey.Verify-API-Key-1.counter"/>
<Interval>1</Interval>
<Distributed>true</Distributed>
<Synchronous>true</Synchronous>
<TimeUnit>minute</TimeUnit>
<Indentifier>verifyapikey.Quota-1.app.name</Indentifier>
</Quota>
Good to know - Similarly you can use attributes for TimeUnit and Interval as well
I created one test proxy to evaluate this process and added below custom attributes in apps
counter = 4(for test app),
counter = 2 (for prod app)
so when I tried to test the traffic it took the max counter limit only. for example if I test the proxy by prod app it allows 2 requests and after that it fails. At the same time I tested the proxy by test app it allowed only 2 calls and failed the 3rd call. vice versa. if I made first call by using test app it allowed 4 calls and after that it failed. At the same time I tried to send requests by using the prod app It also failed. expected it should fail after the 2nd call.
I have used only two policy in the proxy 1) verify API key -
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<VerifyAPIKey async="false" continueOnError="false" enabled="true" name="Verify-API-Key-1">
<DisplayName>Verify API Key-1</DisplayName>
<Properties/>
<APIKey ref="request.queryparam.apikey"/>
</VerifyAPIKey>
2. Quota policy.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Quota async="false" continueOnError="false" enabled="true" name="Quota-1">
<DisplayName>Quota-1</DisplayName>
<Properties/>
<Allow countRef="verifyapikey.Verify-API-Key-1.counter"/>
<Interval>1</Interval>
<Distributed>true</Distributed>
<Synchronous>true</Synchronous>
<TimeUnit>minute</TimeUnit>
<Indentifier>verifyapikey.Quota-1.app.name</Indentifier>
</Quota>
I created a test proxy and added below custom attributes in apps
counter = 4(for test app),
counter = 2 (for prod app)
so when I tried to test the traffic it took the max counter limit only. for example if I test the proxy by prod app it allows 2 requests and after that it fails. At the same time I tested the proxy by test app it allowed only 2 calls and failed the 3rd call. vice versa. if I made first call by using test app it allowed 4 calls and after that it failed. At the same time I tried to send requests by using the prod app It also failed. expected it should fail after the 2nd call.
I have used only two policy in the proxy 1) verify API key -
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<VerifyAPIKey async="false" continueOnError="false" enabled="true" name="Verify-API-Key-1">
<DisplayName>Verify API Key-1</DisplayName>
<Properties/>
<APIKey ref="request.queryparam.apikey"/>
</VerifyAPIKey>
2. Quota policy.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Quota async="false" continueOnError="false" enabled="true" name="Quota-1">
<DisplayName>Quota-1</DisplayName>
<Properties/>
<Allow countRef="verifyapikey.Verify-API-Key-1.counter"/>
<Interval>1</Interval>
<Distributed>true</Distributed>
<Synchronous>true</Synchronous>
<TimeUnit>minute</TimeUnit>
<Indentifier>verifyapikey.Quota-1.app.name</Indentifier>
</Quota>
@majjik98 - shouldnt your Identifier be
<Indentifier>verifyapikey.Verify-API-Key-1.app.name</Indentifier> ??
oh, yes, that too!
But Identifier. Not Indentifier.
Thank you,
yes I have modified it to Identifier but still same behaviour. still could see same behaviour--- when I tried to test the traffic it took the max counter limit only. for example if I test the proxy by prod app it allows 2 requests and after that it fails. At the same time I tested the proxy by test app it allowed only 2 calls and failed the 3rd call. vice versa. if I made first call by using test app it allowed 4 calls and after that it failed. At the same time I tried to send requests by using the prod app It also failed. expected it should fail after the 2nd call.
Haaa.. didn’t see that..
should’ve been Identifier
Not sure but one thing you should check - Indentifier should be Identifier.
You need to fix that to get the right identifier.
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |