Skip to content

Batches method 📢 Webhooks

Retrieves paged webhook batches associated with the customer. The time range specified by createdAfter and createdBefore must not exceed 31 days. If neither is specified, the default time range is the last 3 days.

Usage

ts
import { MailChannelsClient, Webhooks } from 'mailchannels-sdk'

const mailchannels = new MailChannelsClient('your-api-key')
const webhooks = new Webhooks(mailchannels)

const { data, error } = await webhooks.batches()
ts
import { MailChannels } from 'mailchannels-sdk'

const mailchannels = new MailChannels('your-api-key')

const { data, error } = await mailchannels.webhooks.batches()

Params

  • createdAfter string optional: Inclusive lower bound (UTC) for filtering webhook batches by creation time. Formats: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SSZ.
  • createdBefore string optional: Exclusive upper bound (UTC) for filtering webhook batches by creation time. Formats: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SSZ.
  • statuses WebhooksBatchStatus[] optional: Filters webhook batches by webhook response status category. If not provided, batches with all categories are returned. Possible values: 1xx, 2xx, 3xx, 4xx, 5xx, no_response.
  • webhook string optional: Filters webhook batches by the webhook endpoint to which events in the batch were posted.
  • limit number optional: The maximum number of webhook batches to return. Must be between 1 and 500. Default is 500.
  • offset number optional: The number of webhook batches to skip before starting to collect the result set. Default is 0.

Response

  • data WebhooksBatch[] | null nullable
    • batchId number guaranteed: Unique identifier for the webhook batch.
    • createdAt string guaranteed: Timestamp of when the webhook batch was created.
    • customerHandle string guaranteed: The customer handle associated with the webhook batch.
    • duration object optional: Duration of the webhook batch, measured from the time the request was sent to the webhook endpoint until the response was received.
      • unit string guaranteed: The unit of time for the duration. Possible values: milliseconds.
      • value number guaranteed: The value of the duration in the specified unit.
    • eventCount number guaranteed: Number of events in the webhook batch.
    • status WebhooksBatchResponseStatus guaranteed: Status of the webhook batch. Possible values: 1xx_response, 2xx_response, 3xx_response, 4xx_response, 5xx_response, no_response.
    • statusCode number | null nullable: HTTP status code returned by the webhook endpoint.
    • webhook string guaranteed: Webhook endpoint to which events in the batch were posted.
  • error ErrorResponse | null nullable: Error information if the operation failed.
    • message string guaranteed: A human-readable description of the error.
    • statusCode number | null nullable: The HTTP status code from the API, or null if the error is not related to an HTTP request. This field is intended for diagnostic use only and should not be relied upon.
    • type string guaranteed: 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 batches (options?: WebhooksBatchesOptions): Promise<WebhooksBatchesResponse>

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;
};

Batches type declarations

ts
type WebhooksBatchStatus = "1xx" | "2xx" | "3xx" | "4xx" | "5xx" | "no_response";
ts
interface WebhooksBatchesOptions {
  createdAfter?: string;
  createdBefore?: string;
  statuses?: WebhooksBatchStatus[];
  webhook?: string;
  limit?: number;
  offset?: number;
}
ts
type WebhooksBatchResponseStatus = "1xx_response" | "2xx_response" | "3xx_response" | "4xx_response" | "5xx_response" | "no_response";
ts
interface WebhooksBatch {
  batchId: number;
  createdAt: string;
  customerHandle: string;
  duration?: {
    unit: "milliseconds";
    value: number;
  };
  eventCount: number;
  status: WebhooksBatchResponseStatus;
  statusCode: number | null;
  webhook: string;
}
ts
type WebhooksBatchesResponse = DataResponse<WebhooksBatch[]>;

Source

SourcePlaygroundDocsTests

Released under the MIT License.