Subscriptions
获取订阅使用历史
检索具有基于使用的计费的订阅的完整使用历史。
GET
/
subscriptions
/
{subscription_id}
/
usage-history
JavaScript
import DodoPayments from 'dodopayments';
const client = new DodoPayments({
bearerToken: process.env['DODO_PAYMENTS_API_KEY'], // This is the default and can be omitted
});
// Automatically fetches more pages as needed.
for await (const subscriptionRetrieveUsageHistoryResponse of client.subscriptions.retrieveUsageHistory(
'sub_Iuaq622bbmmfOGrVTqdXv',
)) {
console.log(subscriptionRetrieveUsageHistoryResponse.end_date);
}import os
from dodopayments import DodoPayments
client = DodoPayments(
bearer_token=os.environ.get("DODO_PAYMENTS_API_KEY"), # This is the default and can be omitted
)
page = client.subscriptions.retrieve_usage_history(
subscription_id="sub_Iuaq622bbmmfOGrVTqdXv",
)
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(),
"sub_Iuaq622bbmmfOGrVTqdXv",
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("sub_Iuaq622bbmmfOGrVTqdXv");
}
}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("sub_Iuaq622bbmmfOGrVTqdXv")
}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("sub_Iuaq622bbmmfOGrVTqdXv")
puts(page)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Dodopayments\Client;
use Dodopayments\Core\Exceptions\APIException;
$client = new Client(
bearerToken: getenv('DODO_PAYMENTS_API_KEY') ?: 'My Bearer Token',
environment: 'test_mode',
);
try {
$page = $client->subscriptions->retrieveUsageHistory(
'sub_Iuaq622bbmmfOGrVTqdXv',
endDate: new \DateTimeImmutable('2019-12-27T18:11:19.117Z'),
meterID: 'meter_id',
pageNumber: 0,
pageSize: 0,
startDate: new \DateTimeImmutable('2019-12-27T18:11:19.117Z'),
);
var_dump($page);
} catch (APIException $e) {
echo $e->getMessage();
}using System;
using DodoPayments.Client;
using DodoPayments.Client.Models.Subscriptions;
DodoPaymentsClient client = new();
SubscriptionRetrieveUsageHistoryParams parameters = new()
{
SubscriptionID = "sub_Iuaq622bbmmfOGrVTqdXv"
};
var page = await client.Subscriptions.RetrieveUsageHistory(parameters);
await foreach (var item in page.Paginate())
{
Console.WriteLine(item);
}use dodopayments::Client;
#[tokio::main]
async fn main() -> dodopayments::Result<()> {
let client = Client::from_env()?;
let subscription_id = "subscription_id";
let result = client
.subscriptions()
.retrieve_usage_history()
.subscription_id(subscription_id)
.query(serde_json::json!({}))
.await?;
println!("{result:?}");
Ok(())
}curl --request GET \
--url https://test.dodopayments.com/subscriptions/{subscription_id}/usage-history \
--header 'Authorization: Bearer <token>'{
"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"
}
]
}授权
Send your API key as a bearer token: Authorization: Bearer <api_key>. A test mode key starts with dodo_test_, for example dodo_test_AbCd1234EfGh5678.<secret>. A live mode key starts with dodo_live_. Use a test mode key on test.dodopayments.com and a live mode key on live.dodopayments.com. Keys from before these tags have no tag and operate as before.
路径参数
Unique subscription identifier
查询参数
Filter by start date (inclusive)
Filter by end date (inclusive)
Filter by specific meter ID
Page size (default: 10, max: 100)
必填范围:
x >= 0Page number (default: 0)
必填范围:
x >= 0响应
Usage history retrieved successfully
List of usage history items
Show child attributes
Show child attributes
最后修改于 2026年4月1日
此页面对您有帮助吗?
⌘I
JavaScript
import DodoPayments from 'dodopayments';
const client = new DodoPayments({
bearerToken: process.env['DODO_PAYMENTS_API_KEY'], // This is the default and can be omitted
});
// Automatically fetches more pages as needed.
for await (const subscriptionRetrieveUsageHistoryResponse of client.subscriptions.retrieveUsageHistory(
'sub_Iuaq622bbmmfOGrVTqdXv',
)) {
console.log(subscriptionRetrieveUsageHistoryResponse.end_date);
}import os
from dodopayments import DodoPayments
client = DodoPayments(
bearer_token=os.environ.get("DODO_PAYMENTS_API_KEY"), # This is the default and can be omitted
)
page = client.subscriptions.retrieve_usage_history(
subscription_id="sub_Iuaq622bbmmfOGrVTqdXv",
)
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(),
"sub_Iuaq622bbmmfOGrVTqdXv",
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("sub_Iuaq622bbmmfOGrVTqdXv");
}
}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("sub_Iuaq622bbmmfOGrVTqdXv")
}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("sub_Iuaq622bbmmfOGrVTqdXv")
puts(page)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Dodopayments\Client;
use Dodopayments\Core\Exceptions\APIException;
$client = new Client(
bearerToken: getenv('DODO_PAYMENTS_API_KEY') ?: 'My Bearer Token',
environment: 'test_mode',
);
try {
$page = $client->subscriptions->retrieveUsageHistory(
'sub_Iuaq622bbmmfOGrVTqdXv',
endDate: new \DateTimeImmutable('2019-12-27T18:11:19.117Z'),
meterID: 'meter_id',
pageNumber: 0,
pageSize: 0,
startDate: new \DateTimeImmutable('2019-12-27T18:11:19.117Z'),
);
var_dump($page);
} catch (APIException $e) {
echo $e->getMessage();
}using System;
using DodoPayments.Client;
using DodoPayments.Client.Models.Subscriptions;
DodoPaymentsClient client = new();
SubscriptionRetrieveUsageHistoryParams parameters = new()
{
SubscriptionID = "sub_Iuaq622bbmmfOGrVTqdXv"
};
var page = await client.Subscriptions.RetrieveUsageHistory(parameters);
await foreach (var item in page.Paginate())
{
Console.WriteLine(item);
}use dodopayments::Client;
#[tokio::main]
async fn main() -> dodopayments::Result<()> {
let client = Client::from_env()?;
let subscription_id = "subscription_id";
let result = client
.subscriptions()
.retrieve_usage_history()
.subscription_id(subscription_id)
.query(serde_json::json!({}))
.await?;
println!("{result:?}");
Ok(())
}curl --request GET \
--url https://test.dodopayments.com/subscriptions/{subscription_id}/usage-history \
--header 'Authorization: Bearer <token>'{
"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"
}
]
}