Node.js
import { MailChannels } from "mailchannels-sdk";
const { PARENT_API_KEY, SUB_ACCOUNT_HANDLE } = process.env;
if (!PARENT_API_KEY) throw new Error("Set PARENT_API_KEY (a parent-account API key) before running");
if (!SUB_ACCOUNT_HANDLE) throw new Error("Set SUB_ACCOUNT_HANDLE (the sub-account to query)");
const mailchannels = new MailChannels(PARENT_API_KEY);
const { data, error } = await mailchannels.subAccounts.getUsage(SUB_ACCOUNT_HANDLE);
if (error) {
console.error("Get sub-account usage failed:", error);
process.exit(1);
}
console.log(data);import os
import sys
import mailchannels
parent_api_key = os.environ.get("PARENT_API_KEY")
handle = os.environ.get("SUB_ACCOUNT_HANDLE")
if not parent_api_key:
sys.exit("Set PARENT_API_KEY (a parent-account API key) before running")
if not handle:
sys.exit("Set SUB_ACCOUNT_HANDLE (the sub-account to query)")
mailchannels.api_key = parent_api_key
response = mailchannels.SubAccounts.retrieve_usage(handle)
print(response)<?php
require_once __DIR__ . '/vendor/autoload.php';
use MailChannels\Client;
$parent_api_key = getenv('PARENT_API_KEY') or exit("Error: PARENT_API_KEY is not set\n");
$sub_account_handle = getenv('SUB_ACCOUNT_HANDLE') or exit("Error: SUB_ACCOUNT_HANDLE is not set\n");
$client = new Client(apiKey: $parent_api_key);
$response = $client->subAccounts->retrieveUsage($sub_account_handle);
print_r($response->toArray());curl --request GET \
--url https://api.mailchannels.net/tx/v1/sub-account/{handle}/usage \
--header 'X-Api-Key: <x-api-key>'{
"monthly_limit": 10000,
"total_usage": 5000,
"period_end_date": "2025-04-11",
"period_start_date": "2025-03-12"
}Retrieve Sub-account Usage Stats
Retrieves usage statistics for the specified sub-account during the current billing period.
GET
/
sub-account
/
{handle}
/
usage
Node.js
import { MailChannels } from "mailchannels-sdk";
const { PARENT_API_KEY, SUB_ACCOUNT_HANDLE } = process.env;
if (!PARENT_API_KEY) throw new Error("Set PARENT_API_KEY (a parent-account API key) before running");
if (!SUB_ACCOUNT_HANDLE) throw new Error("Set SUB_ACCOUNT_HANDLE (the sub-account to query)");
const mailchannels = new MailChannels(PARENT_API_KEY);
const { data, error } = await mailchannels.subAccounts.getUsage(SUB_ACCOUNT_HANDLE);
if (error) {
console.error("Get sub-account usage failed:", error);
process.exit(1);
}
console.log(data);import os
import sys
import mailchannels
parent_api_key = os.environ.get("PARENT_API_KEY")
handle = os.environ.get("SUB_ACCOUNT_HANDLE")
if not parent_api_key:
sys.exit("Set PARENT_API_KEY (a parent-account API key) before running")
if not handle:
sys.exit("Set SUB_ACCOUNT_HANDLE (the sub-account to query)")
mailchannels.api_key = parent_api_key
response = mailchannels.SubAccounts.retrieve_usage(handle)
print(response)<?php
require_once __DIR__ . '/vendor/autoload.php';
use MailChannels\Client;
$parent_api_key = getenv('PARENT_API_KEY') or exit("Error: PARENT_API_KEY is not set\n");
$sub_account_handle = getenv('SUB_ACCOUNT_HANDLE') or exit("Error: SUB_ACCOUNT_HANDLE is not set\n");
$client = new Client(apiKey: $parent_api_key);
$response = $client->subAccounts->retrieveUsage($sub_account_handle);
print_r($response->toArray());curl --request GET \
--url https://api.mailchannels.net/tx/v1/sub-account/{handle}/usage \
--header 'X-Api-Key: <x-api-key>'{
"monthly_limit": 10000,
"total_usage": 5000,
"period_end_date": "2025-04-11",
"period_start_date": "2025-03-12"
}Headers
Path Parameters
Handle of the sub-account to query usage stats for.
Response
Successfully returned the usage stats.
The effective monthly limit for the current billing period. A limit of zero means the account cannot send any messages. For sub-accounts with no explicit limit set (i.e., -1), the monthly limit for the parent account is returned.
Example:
10000
The total usage for the current billing period.
Example:
5000
The end date of the current billing period (ISO 8601 format).
Example:
"2025-04-11"
The start date of the current billing period (ISO 8601 format).
Example:
"2025-03-12"
Was this page helpful?

