Subscriptions
Get Subscription Usage History
Retrieve the complete usage history for a subscription with usage-based billing.
GET
/
subscriptions
/
{subscription_id}
/
usage-history
JavaScript
import DodoPayments from 'dodopayments';
const client = new DodoPayments({
bearerToken: 'My Bearer Token',
});
// Automatically fetches more pages as needed.
for await (const subscriptionRetrieveUsageHistoryResponse of client.subscriptions.retrieveUsageHistory(
'subscription_id',
)) {
console.log(subscriptionRetrieveUsageHistoryResponse.end_date);
}from dodopayments import DodoPayments
client = DodoPayments(
bearer_token="My Bearer Token",
)
page = client.subscriptions.retrieve_usage_history(
subscription_id="subscription_id",
)
page = page.items[0]
print(page.end_date)package main
import (
"context"
"fmt"
"github.com/dodopayments/dodopayments-go"
"github.com/dodopayments/dodopayments-go/option"
)
func main() {
client := dodopayments.NewClient(
option.WithBearerToken("My Bearer Token"),
)
page, err := client.Subscriptions.GetUsageHistory(
context.TODO(),
"subscription_id",
dodopayments.SubscriptionGetUsageHistoryParams{
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", page)
}
package com.dodopayments.api.example;
import com.dodopayments.api.client.DodoPaymentsClient;
import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient;
import com.dodopayments.api.models.subscriptions.SubscriptionRetrieveUsageHistoryPage;
import com.dodopayments.api.models.subscriptions.SubscriptionRetrieveUsageHistoryParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
DodoPaymentsClient client = DodoPaymentsOkHttpClient.fromEnv();
SubscriptionRetrieveUsageHistoryPage page = client.subscriptions().retrieveUsageHistory("subscription_id");
}
}package com.dodopayments.api.example
import com.dodopayments.api.client.DodoPaymentsClient
import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient
import com.dodopayments.api.models.subscriptions.SubscriptionRetrieveUsageHistoryPage
import com.dodopayments.api.models.subscriptions.SubscriptionRetrieveUsageHistoryParams
fun main() {
val client: DodoPaymentsClient = DodoPaymentsOkHttpClient.fromEnv()
val page: SubscriptionRetrieveUsageHistoryPage = client.subscriptions().retrieveUsageHistory("subscription_id")
}require "dodopayments"
dodo_payments = Dodopayments::Client.new(
bearer_token: "My Bearer Token",
environment: "test_mode" # defaults to "live_mode"
)
page = dodo_payments.subscriptions.retrieve_usage_history("subscription_id")
puts(page)curl --request GET \
--url https://test.dodopayments.com/subscriptions/{subscription_id}/usage-history \
--header 'Authorization: Bearer <token>'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://test.dodopayments.com/subscriptions/{subscription_id}/usage-history",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}{
"items": [
{
"end_date": "2023-11-07T05:31:56Z",
"meters": [
{
"chargeable_units": "<string>",
"consumed_units": "<string>",
"currency": "AED",
"free_threshold": 123,
"id": "<string>",
"name": "<string>",
"price_per_unit": "<string>",
"total_price": 123
}
],
"start_date": "2023-11-07T05:31:56Z"
}
]
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Path Parameters
Unique subscription identifier
Query Parameters
Filter by start date (inclusive)
Filter by end date (inclusive)
Filter by specific meter ID
Page size (default: 10, max: 100)
Required range:
x >= 0Page number (default: 0)
Required range:
x >= 0Response
Usage history retrieved successfully
List of usage history items
Show child attributes
Show child attributes
Was this page helpful?
⌘I
JavaScript
import DodoPayments from 'dodopayments';
const client = new DodoPayments({
bearerToken: 'My Bearer Token',
});
// Automatically fetches more pages as needed.
for await (const subscriptionRetrieveUsageHistoryResponse of client.subscriptions.retrieveUsageHistory(
'subscription_id',
)) {
console.log(subscriptionRetrieveUsageHistoryResponse.end_date);
}from dodopayments import DodoPayments
client = DodoPayments(
bearer_token="My Bearer Token",
)
page = client.subscriptions.retrieve_usage_history(
subscription_id="subscription_id",
)
page = page.items[0]
print(page.end_date)package main
import (
"context"
"fmt"
"github.com/dodopayments/dodopayments-go"
"github.com/dodopayments/dodopayments-go/option"
)
func main() {
client := dodopayments.NewClient(
option.WithBearerToken("My Bearer Token"),
)
page, err := client.Subscriptions.GetUsageHistory(
context.TODO(),
"subscription_id",
dodopayments.SubscriptionGetUsageHistoryParams{
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", page)
}
package com.dodopayments.api.example;
import com.dodopayments.api.client.DodoPaymentsClient;
import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient;
import com.dodopayments.api.models.subscriptions.SubscriptionRetrieveUsageHistoryPage;
import com.dodopayments.api.models.subscriptions.SubscriptionRetrieveUsageHistoryParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
DodoPaymentsClient client = DodoPaymentsOkHttpClient.fromEnv();
SubscriptionRetrieveUsageHistoryPage page = client.subscriptions().retrieveUsageHistory("subscription_id");
}
}package com.dodopayments.api.example
import com.dodopayments.api.client.DodoPaymentsClient
import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient
import com.dodopayments.api.models.subscriptions.SubscriptionRetrieveUsageHistoryPage
import com.dodopayments.api.models.subscriptions.SubscriptionRetrieveUsageHistoryParams
fun main() {
val client: DodoPaymentsClient = DodoPaymentsOkHttpClient.fromEnv()
val page: SubscriptionRetrieveUsageHistoryPage = client.subscriptions().retrieveUsageHistory("subscription_id")
}require "dodopayments"
dodo_payments = Dodopayments::Client.new(
bearer_token: "My Bearer Token",
environment: "test_mode" # defaults to "live_mode"
)
page = dodo_payments.subscriptions.retrieve_usage_history("subscription_id")
puts(page)curl --request GET \
--url https://test.dodopayments.com/subscriptions/{subscription_id}/usage-history \
--header 'Authorization: Bearer <token>'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://test.dodopayments.com/subscriptions/{subscription_id}/usage-history",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}{
"items": [
{
"end_date": "2023-11-07T05:31:56Z",
"meters": [
{
"chargeable_units": "<string>",
"consumed_units": "<string>",
"currency": "AED",
"free_threshold": 123,
"id": "<string>",
"name": "<string>",
"price_per_unit": "<string>",
"total_price": 123
}
],
"start_date": "2023-11-07T05:31:56Z"
}
]
}