Meters via API
This tutorial will guide you through the steps to create meters via Billing APIs.
Create a meter
Call the Create Meter API with the following required fields:
aggregation_method: The mathematical operation used to calculate the billable quantity from received usage events:- SUM - Adds all values received
- COUNT - Counts the total number of usage events received
- UNIQUE - Counts the number of distinct values received
- MAX - Records the highest single value received
- LAST - Uses the most recent value received
aggregation_property: The specific field within the usage event's properties that contains the value to be aggregated- Note: This field is required for all aggregation methods except COUNT. Values must be >=0 else the event will be rejected.
event_name: The name of the usage event this meter monitors. Corresponds with theevent_namefield in Usage Event.name: A descriptive name for the meter
The example code below shows how to create a meter to measure the number of API calls made.
1curl -X POST https://api-demo.airwallex.com/api/v1/meters/create \2 -H 'Content-Type: application/json' \3 -H 'Authorization: Bearer {{ACCESS_TOKEN}}' \4 -d '{5 "aggregation_method": "SUM",6 "aggregation_property": "quantity",7 "description": "Tracks API requests made by customers",8 "event_name": "api_call",9 "metadata": {10 "foo": "bar"11 },12 "name": "API Requests",13 "request_id": "ee939540-3203-4a2c-9172-89a566485dd9"14 }'
Get usage summary
You can retrieve aggregated usage data for a specific meter to monitor a customer's consumption levels.
Call the Get summaries of a Meter API with the following required fields:
billing_customer_id: The ID of the customer whose usage you are querying.from_happened_at: The start of the period for which you want to retrieve usage.to_happened_at: The end of the period for which you want to retrieve usage.
Archive a meter
Archiving deprecates a meter, making it unavailable for linking to any new usage-based prices. Archiving a meter does not affect finalised invoices or existing subscriptions containing its linked prices.
Call the Archive a Meter API and with the id of the meter you wish to archive.
1curl -X POST https://api-demo.airwallex.com/api/v1/meters/mtr_1234567890abcdef/archive \2 -H 'Authorization: Bearer {{ACCESS_TOKEN}}'
Restore a meter
Restoring a meter reverses the archival, making the meter active again. Once restored, the meter can be linked to new prices.
Call the Restore a Meter API and with the id of the meter you wish to restore.