Collect usage data for a subscription for quantity-based and metered billing.

Prerequisites

1

Create measurement

Make sure you have a quantity-based or metered measurement. You can create those measurements using the API.

A default measurement for quantity-based billing is already available in your account with the code “quantity”.

2

Create product

Make sure you have a product that uses the measurement you want to collect usage data for. You can create a product using the API.

3

Create subscription

Make sure you have a subscription with a subscription item that uses the measurement you want to collect usage data for. You can create a subscription using the API.

You can collect usage data before activating a subscription for historical reasons. The usage data will be taken into account from the provided billingStart on subscription creation.

Usage

You can collect usage data at any time for a subscription. Subscriptions can have multiple subscription items, each with its own usage data.

You can combine multiple subscriptions and subscription items in the same batch. Using the batch API is recommended for collecting usage data for multiple subscription items, as it processes their values asynchronously.

curl -X POST \
 /subscription-measurements/batch \
 --header "Content-Type: application/json" \
 --header "Authorization: Bearer <token>" \
 --data '{
    "values": [
        {
            "subscription": "1QEHKTJY9097X91J78YRJEA9E8",
            "subscriptionItem": "1QEHKTJY9097X91J78YRJEA9E8",
            "measurementCode": "used_traffic",
            "quantity": "1",
            "measuredAt": "2021-01-01T00:00:00Z"
        },
        {
            "subscription": "1QEHKTJY9097X91J78YRJEA9E8",
            "subscriptionItem": "1QEHKTJY9097X91J78YRJEA9E8",
            "measurementCode": "used_storage",
            "quantity": "23.09",
            "measuredAt": "2021-01-01T00:00:00Z"
        }
    ]
}'

See: API Reference.

Detailed usage breakdown

When a subscription is billed, a link in the invoice is provided for a detailed usage breakdown. In the invoice itself, the quantity is set to 1 and the price is the sum of all usage data for the subscription item. We’re currently working on making this swappable, so you can choose to show the usage breakdown in the invoice itself.

Click here to see usage breakdown example

If you are interested to show the usage breakdown in your application, please contact us at developer@fynn.eu.