import { MailChannels } from "mailchannels-sdk";
const { MAILCHANNELS_API_KEY } = process.env;
if (!MAILCHANNELS_API_KEY) throw new Error("Set MAILCHANNELS_API_KEY before running");
const mailchannels = new MailChannels(MAILCHANNELS_API_KEY);
const { data, error } = await mailchannels.metrics.recipientBehaviour({
startTime: "2026-01-01T00:00:00Z",
endTime: "2026-01-31T23:59:59Z",
});
if (error) {
console.error("Get recipient behaviour metrics failed:", error);
process.exit(1);
}
console.log(data);import os
import sys
import mailchannels
if not os.environ.get("MAILCHANNELS_API_KEY"):
sys.exit("Set MAILCHANNELS_API_KEY before running")
# Retrieve weekly unsubscribe activity for a single campaign.
response = mailchannels.Metrics.recipient_behaviour(
campaign_id="weekly_newsletter",
interval="week",
)
print(response)<?php
require_once __DIR__ . '/vendor/autoload.php';
use MailChannels\Client;
$api_key = getenv('MAILCHANNELS_API_KEY') or exit("Error: MAILCHANNELS_API_KEY is not set\n");
$client = new Client(apiKey: $api_key);
// Retrieve weekly unsubscribe activity for a single campaign.
$response = $client->metrics->recipientBehaviour(
campaignId: 'weekly_newsletter',
interval: 'week',
);
print_r($response->toArray());curl --request GET \
--url https://api.mailchannels.net/tx/v1/metrics/recipient-behaviour \
--header 'X-Api-Key: <x-api-key>'{
"buckets": {
"unsubscribe_delivered": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
],
"unsubscribed": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
]
},
"unsubscribe_delivered": 1,
"unsubscribed": 1,
"end_time": "2023-11-07T05:31:56Z",
"start_time": "2023-11-07T05:31:56Z"
}{
"errors": [
"<string>"
]
}Retrieve Recipient Behaviour Metrics
Retrieve recipient behaviour metrics for messages sent from your account, including counts of unsubscribed events. Supports optional filters for time range, and campaign ID.
import { MailChannels } from "mailchannels-sdk";
const { MAILCHANNELS_API_KEY } = process.env;
if (!MAILCHANNELS_API_KEY) throw new Error("Set MAILCHANNELS_API_KEY before running");
const mailchannels = new MailChannels(MAILCHANNELS_API_KEY);
const { data, error } = await mailchannels.metrics.recipientBehaviour({
startTime: "2026-01-01T00:00:00Z",
endTime: "2026-01-31T23:59:59Z",
});
if (error) {
console.error("Get recipient behaviour metrics failed:", error);
process.exit(1);
}
console.log(data);import os
import sys
import mailchannels
if not os.environ.get("MAILCHANNELS_API_KEY"):
sys.exit("Set MAILCHANNELS_API_KEY before running")
# Retrieve weekly unsubscribe activity for a single campaign.
response = mailchannels.Metrics.recipient_behaviour(
campaign_id="weekly_newsletter",
interval="week",
)
print(response)<?php
require_once __DIR__ . '/vendor/autoload.php';
use MailChannels\Client;
$api_key = getenv('MAILCHANNELS_API_KEY') or exit("Error: MAILCHANNELS_API_KEY is not set\n");
$client = new Client(apiKey: $api_key);
// Retrieve weekly unsubscribe activity for a single campaign.
$response = $client->metrics->recipientBehaviour(
campaignId: 'weekly_newsletter',
interval: 'week',
);
print_r($response->toArray());curl --request GET \
--url https://api.mailchannels.net/tx/v1/metrics/recipient-behaviour \
--header 'X-Api-Key: <x-api-key>'{
"buckets": {
"unsubscribe_delivered": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
],
"unsubscribed": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
]
},
"unsubscribe_delivered": 1,
"unsubscribed": 1,
"end_time": "2023-11-07T05:31:56Z",
"start_time": "2023-11-07T05:31:56Z"
}{
"errors": [
"<string>"
]
}Headers
Query Parameters
The beginning of the time range for retrieving recipient behaviour metrics (inclusive). Formats: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SSZ. Defaults to one month ago if not provided.
The end of the time range for retrieving recipient behaviour metrics (exclusive). Formats: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SSZ. Defaults to the current time if not provided.
The ID of the campaign to filter metrics by. If not provided, metrics for all campaigns will be returned.
The interval for aggregating metrics data. Allowed values:
- hour: Hourly breakdown
- day: Daily breakdown (default)
- week: Weekly breakdown
- month: Monthly breakdown
hour, day, week, month Response
Successfully retrieved recipient behaviour metrics
A series of metrics aggregations bucketed by time interval (e.g. hour, day)
Show child attributes
Show child attributes
Count of recipients of delivered messages that include at least one of the unsubscribe link or unsubscribe headers. Since the unsubscribe feature requires exactly one recipient per message, this count also represents the total number of delivered messages.
x >= 0Count of unsubscribed events by recipients.
x >= 0The end of the time range for retrieving recipient behaviour metrics (exclusive).
The beginning of the time range for retrieving recipient behaviour metrics (inclusive).
Was this page helpful?

