Query metered usage of a user
I'm wondering if it's possible to check the metered usage of a customer under the current billing period. I can't really tell from the API docs if the get billing entitlements provides this information (it seems it doesn't). But I have found this article suggesting it is possible for me to query usage records:
”Instead of building your own data aggregation and rating engine, you can leverage Kinde’s API-first architecture. Your application’s responsibility is to report usage events for each customer to the Kinde API. Kinde takes care of the rest:
It ingests and aggregates the usage data.
[...]
Your frontend application can then query Kinde for the rated usage and cost data needed to power your dashboard, without needing to build or maintain the underlying billing logic yourself.”
This is from https://kinde.com/learn/billing/ux/real-time-usage-dashboards/#how-kinde-helps
I also found a previous discord support thread saying:
To check or consume usage via the Management API, you need the agreement ID. Here’s how you can get it: […] Once you have the agreement ID, you can use it with the Management API to record or check usage. https://www.answeroverflow.com/m/1397247082305290431
I don't know if I'm understanding it right, but I take it there's both a management API and an account API to check current usage? If so what are the endpoints, and where in the response does usage data show?
The link between user_id and customer_id - Kinde
What is the link between user_id and customer_id and how do I get customer_id to then run Management API to check/consume usage?
Kinde Learning
Real-Time Usage Dashboards: Building the UI That Supports Billing T...
Explain how to develop customer-facing dashboards that display live usage, spending progress, alerts, and next bill estimates.
1 Reply
Hello Kaypay, thanks for reaching out.
Yes, you can report usage and also query a customer’s current-cycle usage, but it depends on which API you call. There are two paths:
1. Account API (used in the browser with a user token)
This is how you show a logged-in customer their entitlements and current usage directly in your app’s frontend. It returns only the data relevant to the signed-in customer. 2. Management API (server-to-server with an M2M token)
This is where you can look up a customer’s billing agreements, submit meter records, and access organization-level billing information. This is the API you use if you want to fetch or aggregate usage on your backend. Key Management API endpoints: • Get a customer’s agreements (this is how you find the agreement ID you need):
https://docs.kinde.com/kinde-apis/management/#tag/billing-agreements/get/api/v1/billing/agreements • Get entitlements server-side:
https://docs.kinde.com/kinde-apis/management/#tag/billing-entitlements/get/api/v1/billing/entitlements • Submit usage:
https://docs.kinde.com/kinde-apis/management/#tag/billing-meter-usage/post/api/v1/billing/meter_usage
Required fields: customer_agreement_id, billing_feature_code, meter_value.
Kinde applies the usage to the customer’s current billing cycle. Once usage is recorded, you can query the customer’s agreements or entitlements to see the updated usage values for the current period.
This is how you show a logged-in customer their entitlements and current usage directly in your app’s frontend. It returns only the data relevant to the signed-in customer. 2. Management API (server-to-server with an M2M token)
This is where you can look up a customer’s billing agreements, submit meter records, and access organization-level billing information. This is the API you use if you want to fetch or aggregate usage on your backend. Key Management API endpoints: • Get a customer’s agreements (this is how you find the agreement ID you need):
https://docs.kinde.com/kinde-apis/management/#tag/billing-agreements/get/api/v1/billing/agreements • Get entitlements server-side:
https://docs.kinde.com/kinde-apis/management/#tag/billing-entitlements/get/api/v1/billing/entitlements • Submit usage:
https://docs.kinde.com/kinde-apis/management/#tag/billing-meter-usage/post/api/v1/billing/meter_usage
Required fields: customer_agreement_id, billing_feature_code, meter_value.
Kinde applies the usage to the customer’s current billing cycle. Once usage is recorded, you can query the customer’s agreements or entitlements to see the updated usage values for the current period.