Iron Plans
Search…
Tracking usage-based metrics
There are two ways to track usage-based metrics using the Iron Plans server-side API.

Increment usage-based metrics as they happen

We handle incremental reporting so that you can increment usage-based metrics as they happen.
Pros: No cron job to manage, no time window logic to be done by you.
By Customer Email
1
# Provided a customer email:
3
4
# Get the subscriptions this customer is subscribed to.
5
# Note, the user <-> subscription_id relationship is cachable as
6
# the subscription_id will never change, even after the
7
# subscription has been canceled.
8
subscriptions = requests.get(
9
f"https://api.ironplans.com/subscriptions/v1?customer_email={email}",
10
headers={"Authorization": "Bearer my-private-token"}
11
).json()
12
13
# Determine which subscription/team to report usage for.
14
subscription = # ...
15
16
# Report the customer has consumed 1 `requests` unit:
17
data = {"op": "inc", "slug": "requests", "value": 1}
18
requests.post(
19
f"https://api.ironplans.com/subscriptions/v1/{subscription['id']}/report/",
20
data=data,
21
headers={"Authorization": "Bearer my-private-token"}
22
).json()
Copied!

Set usage-based metrics periodically

Send us the current counts of usage-based metrics periodically.
Pros: Idempotent, Iron Plans server-side logic in one place in codebase.
1
subscriptions = requests.get(
2
"https://api.ironplans.com/subscriptions/v1/",
3
headers={"Authorization": "Bearer my-private-token"}
4
).json()
5
6
for subscription in subscriptions:
7
usage = your_app.get_usage(
8
start_at=subscription["start_at"],
9
end_at=subscription["end_at"],
10
user=subscription["owner_email"],
11
)
12
13
data = {"op": "set", "slug": "requests", "value": usage}
14
15
requests.post(
16
f"https://api.ironplans.com/subscriptions/v1/{subscription['id']}/report/",
17
data=data,
18
headers={"Authorization": "Bearer my-private-token"}
19
).json()
Copied!