cURL
curl --request POST \
--url https://us.api.flexprice.io/v1/subscriptions/usage \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"subscription_id": "123",
"end_time": "2024-03-20T00:00:00Z",
"lifetime_usage": false,
"start_time": "2024-03-13T00:00:00Z"
}
'from flexprice import Flexprice
from flexprice.utils import parse_datetime
with Flexprice(
api_key_auth="<YOUR_API_KEY_HERE>",
) as f_client:
res = f_client.subscriptions.get_subscription_usage(subscription_id="123", end_time=parse_datetime("2024-03-20T00:00:00Z"), lifetime_usage=False, start_time=parse_datetime("2024-03-13T00:00:00Z"))
# Handle response
print(res)import { Flexprice } from "@flexprice/sdk";
const flexprice = new Flexprice({
apiKeyAuth: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await flexprice.subscriptions.getSubscriptionUsage({
endTime: new Date("2024-03-20T00:00:00Z"),
lifetimeUsage: false,
startTime: new Date("2024-03-13T00:00:00Z"),
subscriptionId: "123",
});
console.log(result);
}
run();package main
import(
"context"
flexprice "github.com/flexprice/go-sdk/v2"
"github.com/flexprice/go-sdk/v2/types"
"github.com/flexprice/go-sdk/v2/models/types"
"log"
)
func main() {
ctx := context.Background()
s := flexprice.New(
flexprice.WithSecurity("<YOUR_API_KEY_HERE>"),
)
res, err := s.Subscriptions.GetSubscriptionUsage(ctx, types.GetUsageBySubscriptionRequest{
EndTime: types.MustNewTimeFromString("2024-03-20T00:00:00Z"),
LifetimeUsage: flexprice.Pointer(false),
StartTime: types.MustNewTimeFromString("2024-03-13T00:00:00Z"),
SubscriptionID: "123",
})
if err != nil {
log.Fatal(err)
}
if res.GetUsageBySubscriptionResponse != nil {
// handle response
}
}{
"amount": 123,
"charges": [
{
"amount": 123,
"currency": "<string>",
"display_amount": "<string>",
"filter_values": {},
"is_overage": true,
"meter_display_name": "<string>",
"meter_id": "<string>",
"overage_factor": 123,
"price": {
"amount": "<string>",
"billing_cadence": "RECURRING",
"billing_model": "FLAT_FEE",
"billing_period": "MONTHLY",
"billing_period_count": 123,
"bucket_size": "MINUTE",
"conversion_rate": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"created_by": "<string>",
"currency": "<string>",
"description": "<string>",
"display_amount": "<string>",
"display_name": "<string>",
"display_price_unit_amount": "<string>",
"end_date": "2023-11-07T05:31:56Z",
"entity_id": "<string>",
"entity_type": "PLAN",
"environment_id": "<string>",
"group_id": "<string>",
"id": "<string>",
"invoice_cadence": "ARREAR",
"lookup_key": "<string>",
"metadata": {},
"meter_id": "<string>",
"min_quantity": "<string>",
"parent_price_id": "<string>",
"price_unit": "<string>",
"price_unit_amount": "<string>",
"price_unit_id": "<string>",
"price_unit_tiers": [
{
"flat_amount": "<string>",
"unit_amount": "<string>",
"up_to": 123
}
],
"price_unit_type": "FIAT",
"sequence": 123,
"start_date": "2023-11-07T05:31:56Z",
"status": "published",
"tenant_id": "<string>",
"tier_mode": "VOLUME",
"tiers": [
{
"flat_amount": "<string>",
"unit_amount": "<string>",
"up_to": 123
}
],
"transform_quantity": {
"divide_by": 123,
"round": "up"
},
"trial_period_days": 123,
"type": "USAGE",
"updated_at": "2023-11-07T05:31:56Z",
"updated_by": "<string>"
},
"quantity": 123,
"subscription_line_item_id": "<string>"
}
],
"commitment_amount": 123,
"commitment_utilized": 123,
"currency": "<string>",
"display_amount": "<string>",
"end_time": "2023-11-07T05:31:56Z",
"has_overage": true,
"overage_amount": 123,
"overage_factor": 123,
"start_time": "2023-11-07T05:31:56Z"
}{
"code": "http_client_error",
"http_status_code": 123,
"message": "<string>"
}{
"code": "http_client_error",
"http_status_code": 123,
"message": "<string>"
}Subscriptions
Get usage by subscription
Use when showing usage for a subscription (e.g. in a portal or for overage checks). Supports time range and filters.
POST
/
subscriptions
/
usage
cURL
curl --request POST \
--url https://us.api.flexprice.io/v1/subscriptions/usage \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"subscription_id": "123",
"end_time": "2024-03-20T00:00:00Z",
"lifetime_usage": false,
"start_time": "2024-03-13T00:00:00Z"
}
'from flexprice import Flexprice
from flexprice.utils import parse_datetime
with Flexprice(
api_key_auth="<YOUR_API_KEY_HERE>",
) as f_client:
res = f_client.subscriptions.get_subscription_usage(subscription_id="123", end_time=parse_datetime("2024-03-20T00:00:00Z"), lifetime_usage=False, start_time=parse_datetime("2024-03-13T00:00:00Z"))
# Handle response
print(res)import { Flexprice } from "@flexprice/sdk";
const flexprice = new Flexprice({
apiKeyAuth: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await flexprice.subscriptions.getSubscriptionUsage({
endTime: new Date("2024-03-20T00:00:00Z"),
lifetimeUsage: false,
startTime: new Date("2024-03-13T00:00:00Z"),
subscriptionId: "123",
});
console.log(result);
}
run();package main
import(
"context"
flexprice "github.com/flexprice/go-sdk/v2"
"github.com/flexprice/go-sdk/v2/types"
"github.com/flexprice/go-sdk/v2/models/types"
"log"
)
func main() {
ctx := context.Background()
s := flexprice.New(
flexprice.WithSecurity("<YOUR_API_KEY_HERE>"),
)
res, err := s.Subscriptions.GetSubscriptionUsage(ctx, types.GetUsageBySubscriptionRequest{
EndTime: types.MustNewTimeFromString("2024-03-20T00:00:00Z"),
LifetimeUsage: flexprice.Pointer(false),
StartTime: types.MustNewTimeFromString("2024-03-13T00:00:00Z"),
SubscriptionID: "123",
})
if err != nil {
log.Fatal(err)
}
if res.GetUsageBySubscriptionResponse != nil {
// handle response
}
}{
"amount": 123,
"charges": [
{
"amount": 123,
"currency": "<string>",
"display_amount": "<string>",
"filter_values": {},
"is_overage": true,
"meter_display_name": "<string>",
"meter_id": "<string>",
"overage_factor": 123,
"price": {
"amount": "<string>",
"billing_cadence": "RECURRING",
"billing_model": "FLAT_FEE",
"billing_period": "MONTHLY",
"billing_period_count": 123,
"bucket_size": "MINUTE",
"conversion_rate": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"created_by": "<string>",
"currency": "<string>",
"description": "<string>",
"display_amount": "<string>",
"display_name": "<string>",
"display_price_unit_amount": "<string>",
"end_date": "2023-11-07T05:31:56Z",
"entity_id": "<string>",
"entity_type": "PLAN",
"environment_id": "<string>",
"group_id": "<string>",
"id": "<string>",
"invoice_cadence": "ARREAR",
"lookup_key": "<string>",
"metadata": {},
"meter_id": "<string>",
"min_quantity": "<string>",
"parent_price_id": "<string>",
"price_unit": "<string>",
"price_unit_amount": "<string>",
"price_unit_id": "<string>",
"price_unit_tiers": [
{
"flat_amount": "<string>",
"unit_amount": "<string>",
"up_to": 123
}
],
"price_unit_type": "FIAT",
"sequence": 123,
"start_date": "2023-11-07T05:31:56Z",
"status": "published",
"tenant_id": "<string>",
"tier_mode": "VOLUME",
"tiers": [
{
"flat_amount": "<string>",
"unit_amount": "<string>",
"up_to": 123
}
],
"transform_quantity": {
"divide_by": 123,
"round": "up"
},
"trial_period_days": 123,
"type": "USAGE",
"updated_at": "2023-11-07T05:31:56Z",
"updated_by": "<string>"
},
"quantity": 123,
"subscription_line_item_id": "<string>"
}
],
"commitment_amount": 123,
"commitment_utilized": 123,
"currency": "<string>",
"display_amount": "<string>",
"end_time": "2023-11-07T05:31:56Z",
"has_overage": true,
"overage_amount": 123,
"overage_factor": 123,
"start_time": "2023-11-07T05:31:56Z"
}{
"code": "http_client_error",
"http_status_code": 123,
"message": "<string>"
}{
"code": "http_client_error",
"http_status_code": 123,
"message": "<string>"
}Authorizations
Enter your API key in the format x-api-key <api-key>*
Body
application/json
Usage request
Response
OK
Show child attributes
Show child attributes
Amount of commitment used
Whether any usage exceeded commitment
Amount charged at overage rate

