const { result, error } = await unprice.analytics.getUsage({
projectId: "project_1234567890",
range: "24h",
customerId: "cus_1234567890" // optional
});
if (error) {
// handle potential network or bad request error
// a link to our docs will be in the `error.docs` field
console.error(error.message);
return;
}
console.log(result);
{
"usage": [
{
"projectId": "project_1234567890",
"customerId": "cus_1234567890",
"entitlementId": "ent_1234567890",
"featureSlug": "feature_1",
"count": 100,
"sum": 1000,
"max": 50,
"last_during_period": 30
}
]
}
Request
The ID of the project to get usage for
The time range to get usage for (last hour, day, week, month, or 3 months)
The ID of the customer to get usage for (optional)
Response
Array of usage data points
The ID of the entitlement
The number of usage events
The sum of all usage values
usage[].last_during_period
The last usage value during the period