Performance method 📊 Metrics
Retrieve performance metrics for messages sent from your account, including counts of processed, delivered, hard-bounced events. Supports optional filters for time range, and campaign ID.
Usage
ts
import { MailChannelsClient, Metrics } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const metrics = new Metrics(mailchannels)
const { data, error } = await metrics.performance()ts
import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { data, error } = await mailchannels.metrics.performance()Params
optionsMetricsOptionsoptional: Optional filter options.startTimestringoptional: The beginning of the time range for retrieving message performance metrics (inclusive). Formats:YYYY-MM-DDorYYYY-MM-DDTHH:MM:SSZ. Defaults to one month ago if not provided.endTimestringoptional: The end of the time range for retrieving message performance metrics (exclusive). Formats:YYYY-MM-DDorYYYY-MM-DDTHH:MM:SSZ. Defaults to the current time if not provided.campaignIdstringoptional: The ID of the campaign to filter metrics by. If not provided, metrics for all campaigns will be returned.interval"hour" | "day" | "week" | "month"optional: The interval for aggregating metrics data. Defaults today.
Response
dataMetricsPerformance | nullnullablebouncednumberguaranteed: Count of messages bounced during the specified time range.bucketsobjectguaranteed: A series of metrics aggregations bucketed by time interval (e.g. hour, day).bouncedMetricsBucket[]guaranteedcountnumberguaranteed: The number of events or occurrences aggregated within this time period.periodStartstringguaranteed: The starting date and time of the time period this bucket represents.
deliveredMetricsBucket[]guaranteedcountnumberguaranteed: The number of events or occurrences aggregated within this time period.periodStartstringguaranteed: The starting date and time of the time period this bucket represents.
processedMetricsBucket[]guaranteedcountnumberguaranteed: The number of events or occurrences aggregated within this time period.periodStartstringguaranteed: The starting date and time of the time period this bucket represents.
deliverednumberguaranteed: Count of messages delivered during the specified time range.endTimestringguaranteed: The end of the time range for retrieving message performance metrics (exclusive).processednumberguaranteed: Count of messages processed during the specified time range.startTimestringguaranteed: The beginning of the time range for retrieving message performance metrics (inclusive).
errorErrorResponse | nullnullable: Error information if the operation failed.messagestringguaranteed: A human-readable description of the error.statusCodenumber | nullnullable: The HTTP status code from the API, ornullif the error is not related to an HTTP request. This field is intended for diagnostic use only and should not be relied upon.typestringguaranteed: A string identifier for the type of error. This field is intended for diagnostic use only and should not be relied upon.
Type declarations
Signature
ts
async function performance (options?: MetricsOptions): Promise<MetricsPerformanceResponse>Response type declarations
ts
interface ErrorResponse {
message: string;
statusCode: number | null;
type: ErrorType;
}ts
type DataResponse<T> = {
data: T;
error: null;
} | {
data: null;
error: ErrorResponse;
};Shared metrics type declarations
ts
interface MetricsOptions {
startTime?: string;
endTime?: string;
campaignId?: string;
interval?: "hour" | "day" | "week" | "month";
}ts
interface MetricsBucket {
count: number;
periodStart: string;
}Performance type declarations
ts
interface MetricsPerformance {
bounced: number;
buckets: {
bounced: MetricsBucket[];
delivered: MetricsBucket[];
processed: MetricsBucket[];
};
delivered: number;
endTime: string;
processed: number;
startTime: string;
}ts
type MetricsPerformanceResponse = DataResponse<MetricsPerformance>;Source
Source • Playground • Docs • Tests