Tuesday, October 6, 2020

SAP API Management - Quota Policy - Flow Variables

Scenario: You want to pass the quota available count and quota used count in response

Steps:

1. Add an instance of Quota in Preflow for incoming request.


2. Modify the code as per requirement.

Code (Allow 2 calls/1 min.)

<Quota async="false" continueOnError="false" enabled="true" xmlns="http://www.sap.com/apimgmt">

  <Allow count="2"/>

  <Interval>1</Interval>

<Distributed>true</Distributed>

<Synchronous>true</Synchronous>

  <TimeUnit>minute</TimeUnit>

</Quota>

3. Add an instance of Assign Message in preflow for outgoing response.




4. Modify the code as per requirement. Now while defining flow variable, you have to specify identifier to identify the start of variable and end of variable and differentiate it from normal text. For this purpose, you have to use variablePrefix (default value:{) and variableSuffix (default value:}).

Flow variable for used quota countratelimit.{policy_name}.used.count
Flow variable for available quota count: ratelimit.{policy_name}.available.count

<!-- This policy can be used to create or modify the standard HTTP request and response messages -->

<AssignMessage async="false" continueOnError="false" enabled="true" xmlns='http://www.sap.com/apimgmt'>

 

<!-- Sets a new value to the existing parameter -->

<Set>

<Payload contentType="application/json" variablePrefix="@" variableSuffix="#">

    {"Quota Available": "@ratelimit.QuotaPolicy.available.count#",

    "Quota Used": "@ratelimit.QuotaPolicy.used.count#"}

</Payload>

</Set>

<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>

<AssignTo createNew="false" type="response">response</AssignTo>

</AssignMessage>

5. Test the API. 






No comments:

Post a Comment