Policies
Amberflo Metering / Billing Policy
Amberflo amberflo.com is a usage metering and billing service. This policy allows you to meter API calls going through Zuplo and send them to your Amberflo account using your Amberflo API key.
Add the policy to each route you want to meter. Note you can specify the Meter API Name and Meter Value (meter increment) at the policy level.
Configuration
The configuration shows how to configure the policy in the 'policies.json' document.
Policy Options
The options for this policy are specified below. All properties are optional unless specifically marked as required.
apiKey
<string> (Required) -The API key to use when sending metering calls to Amberflo.meterApiName
<string> -The name of the meter to use when sending metering calls to Amberflo (overridable in code).meterValue
<number> -The value to use when sending metering calls to Amberflo (overridable in code).customerIdPropertyPath
<string> -The path to the property onDefaults torequest.user
contains the customer ID. For example.data.accountNumber
would read therequest.user.data.accountNumber
property.".sub"
.customerId
<string> -The default customerId for all metering calls - overridable in code and bycustomerIdPropertyPath
.dimensions
<object> -A dictionary of dimensions to be sent to Amberflo (extensible in code).statusCodes
<string | number[]> -A list of successful status codes and ranges "200-299, 304" that should trigger a metering call to Amberflo.Defaults to"200-299"
.url
<string> -The URL to send metering events. This is useful for testing purposes.Defaults to" https://app.amberflo.io/ingest"
.
Using the Policy
You can set the customerId globally (not recommended) by setting it at the
policy level or use the customerIdPropertyPath
to read the customerId from the
user object on each request. For example, if you're using API Key auth or JWT
auth and want to use the sub
property as the customerId, you would set the
value as follows
"customerIdPropertyPath" : ".sub"
You can also dive into the properties of the metadata. Imagine the
request.user
property is as follows (either based on contents of a JWT token
or API Key metadata)
You could access the accountNumber
property as follows. Note the required
preceding '.'
.
"customerIdPropertyPath" : ".data.accountNumber"
You can also set many of the properties of the meter payload programmatically, either in a custom policy or handler. Here is some example code in a custom inbound policy:
Read more about how policies work