Validate method 📢 Webhooks
Validates whether your enrolled webhook(s) respond with an HTTP 2xx status code. Sends a test request to each webhook containing your customer handle, a hardcoded event type (test), a hardcoded sender email (test@mailchannels.com), a timestamp, a request ID (provided or generated), and an SMTP ID. The response includes the HTTP status code and body returned by each webhook.
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.validate('optional-request-id')ts
import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { data, error } = await mailchannels.webhooks.validate('optional-request-id')Params
requestIdstringoptional: Optional identifier in the webhook payload. If not provided, a value will be automatically generated.NOTE
The request id must not exceed 28 characters.
Response
dataobject | nullnullableallPassedbooleanguaranteed: Indicates whether all webhook validations passedresultsobject[]guaranteed: Detailed results for each tested webhook, including whether it returned a 2xx status code, along with its response status code and body.result"passed" | "failed"guaranteed: Indicates whether the webhook responded with a 2xx HTTP status code.webhookstringguaranteed: The webhook that was validated.responseobject | nullnullable: The HTTP response returned by the webhook, including status code and response body. A null value indicates no response was received. Possible reasons include timeouts, connection failures, or other network-related issues.bodystringoptional: Response body from webhook. Returns an error if unprocessable or too large.statusnumberguaranteed: HTTP status code returned by the webhook.
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 validate (requestId?: string): Promise<WebhooksValidateResponse>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;
};Validate type declarations
ts
type WebhooksValidateResponse = DataResponse<{
allPassed: boolean;
results: {
result: "passed" | "failed";
webhook: string;
response: {
body?: string;
status: number;
} | null;
}[];
}>;Source
Source • Playground • Docs • Tests