Webhook map
bouncescreated(bounces.created)
campaignscreated(campaigns.created)
groupscreated(groups.created)subscriberAdded(groups.subscriberAdded)subscriberUnsubscribed(groups.subscriberUnsubscribed)
subscriberscreated(subscribers.created)unsubscribed(subscribers.unsubscribed)updated(subscribers.updated)
HTTP handler setup
app/api/webhook/route.ts
import { processWebhook } from "corsair";
import { corsair } from "@/server/corsair";
export async function POST(request: Request) {
const headers = Object.fromEntries(request.headers);
// With multiTenancy, give each tenant its own URL (/api/webhook?tenantId=acme):
// the query says whose account, secret and hooks handle the delivery.
const query = Object.fromEntries(new URL(request.url).searchParams);
// The raw text, not request.json(): signatures are checked over the exact bytes sent.
const body = await request.text();
const result = await processWebhook(corsair, headers, body, query);
if (!result.plugin) {
return Response.json({ success: false }, { status: 404 });
}
// A refusal (bad signature) carries no status and answers 400; a handler
// that threw comes back with 500, so the sender retries it.
const status =
result.response?.success === false ? (result.response.statusCode ?? 400) : 200;
return Response.json(result.response ?? { success: true }, {
status,
headers: result.responseHeaders,
});
}
Events
Bounces
Created
bounces.created
A campaign or transactional email bounced (bounces/new), with the SMTP response.
Payload
| Name | Type | Required | Description |
|---|---|---|---|
email_id | string | null | No | — |
subscriber | object | null | No | — |
email_campaign_data | object | null | No | — |
transactional_campaign_id | string | number | null | No | — |
transactional_campaign_data | object | null | No | — |
subscriber full type
subscriber full type
{
id?: string | number,
email?: string | null,
firstname?: string | null,
lastname?: string | null,
phone?: string | null,
phone_country?: {
phone_code?: number | null,
country_code?: string | null
} | null,
created?: string | null,
status?: Record<string, any> | null,
ip_address?: string | null,
bounced_at?: string | null,
unsubscribed_at?: string | null,
unsubscribed?: boolean | number | null,
bounced?: boolean | number | null,
spam_reported?: boolean | number | null,
location?: any,
source?: string | null,
subscriber_tags?: (
{
id?: string | number | null,
title?: string | null
} | string
)[] | null,
columns?: {
id?: string | number | null,
title?: string | null,
type?: string | null,
default?: boolean | number | null,
value?: any
}[] | Record<string, any> | null,
sms_campaign?: Record<string, any> | null,
email_campaign?: Record<string, any> | null
} | null
email_campaign_data full type
email_campaign_data full type
{
campaign_id?: string | number | null,
smtp_response?: string | null
} | null
transactional_campaign_data full type
transactional_campaign_data full type
{
domain_id?: string | number | null,
smtp_response?: string | null,
variables?: Record<string, any> | null
} | null
Response data full type
Response data full type
{
email_id?: string | null,
subscriber?: {
id?: string | number,
email?: string | null,
firstname?: string | null,
lastname?: string | null,
phone?: string | null,
phone_country?: {
phone_code?: number | null,
country_code?: string | null
} | null,
created?: string | null,
status?: Record<string, any> | null,
ip_address?: string | null,
bounced_at?: string | null,
unsubscribed_at?: string | null,
unsubscribed?: boolean | number | null,
bounced?: boolean | number | null,
spam_reported?: boolean | number | null,
location?: any,
source?: string | null,
subscriber_tags?: (
{
id?: string | number | null,
title?: string | null
} | string
)[] | null,
columns?: {
id?: string | number | null,
title?: string | null,
type?: string | null,
default?: boolean | number | null,
value?: any
}[] | Record<string, any> | null,
sms_campaign?: Record<string, any> | null,
email_campaign?: Record<string, any> | null
} | null,
email_campaign_data?: {
campaign_id?: string | number | null,
smtp_response?: string | null
} | null,
transactional_campaign_id?: string | number | null,
transactional_campaign_data?: {
domain_id?: string | number | null,
smtp_response?: string | null,
variables?: Record<string, any> | null
} | null
}
webhookHooks example
sender({
webhookHooks: {
bounces: {
created: {
before(ctx, args) {
return { ctx, args };
},
after(ctx, response) {
},
},
},
},
})
Campaigns
Created
campaigns.created
A campaign was created (campaigns/new).
Payload
| Name | Type | Required | Description |
|---|---|---|---|
id | string | number | Yes | — |
title | string | null | No | — |
subject | string | null | No | — |
from | string | null | No | — |
reply_to | string | null | No | — |
Response data full type
Response data full type
{
id: string | number,
title?: string | null,
subject?: string | null,
from?: string | null,
reply_to?: string | null
}
webhookHooks example
sender({
webhookHooks: {
campaigns: {
created: {
before(ctx, args) {
return { ctx, args };
},
after(ctx, response) {
},
},
},
},
})
Groups
Created
groups.created
A group was created (groups/new).
Payload
| Name | Type | Required | Description |
|---|---|---|---|
id | string | number | Yes | — |
title | string | null | No | — |
Response data full type
Response data full type
{
id: string | number,
title?: string | null
}
webhookHooks example
sender({
webhookHooks: {
groups: {
created: {
before(ctx, args) {
return { ctx, args };
},
after(ctx, response) {
},
},
},
},
})
Subscriber Added
groups.subscriberAdded
A subscriber joined the group the webhook watches (groups/new-subscriber).
Payload
| Name | Type | Required | Description |
|---|---|---|---|
id | string | number | Yes | — |
email | string | null | No | — |
firstname | string | null | No | — |
lastname | string | null | No | — |
phone | string | null | No | — |
phone_country | object | null | No | — |
created | string | null | No | — |
status | Record<string, any> | null | No | — |
ip_address | string | null | No | — |
bounced_at | string | null | No | — |
unsubscribed_at | string | null | No | — |
unsubscribed | boolean | number | null | No | — |
bounced | boolean | number | null | No | — |
spam_reported | boolean | number | null | No | — |
location | any | No | — |
source | string | null | No | — |
subscriber_tags | object[] | null | No | — |
columns | object[] | Record<string, any> | null | No | — |
sms_campaign | Record<string, any> | null | No | — |
email_campaign | Record<string, any> | null | No | — |
phone_country full type
phone_country full type
{
phone_code?: number | null,
country_code?: string | null
} | null
subscriber_tags full type
subscriber_tags full type
(
{
id?: string | number | null,
title?: string | null
} | string
)[] | null
columns full type
columns full type
{
id?: string | number | null,
title?: string | null,
type?: string | null,
default?: boolean | number | null,
value?: any
}[] | Record<string, any> | null
Response data full type
Response data full type
{
id: string | number,
email?: string | null,
firstname?: string | null,
lastname?: string | null,
phone?: string | null,
phone_country?: {
phone_code?: number | null,
country_code?: string | null
} | null,
created?: string | null,
status?: Record<string, any> | null,
ip_address?: string | null,
bounced_at?: string | null,
unsubscribed_at?: string | null,
unsubscribed?: boolean | number | null,
bounced?: boolean | number | null,
spam_reported?: boolean | number | null,
location?: any,
source?: string | null,
subscriber_tags?: (
{
id?: string | number | null,
title?: string | null
} | string
)[] | null,
columns?: {
id?: string | number | null,
title?: string | null,
type?: string | null,
default?: boolean | number | null,
value?: any
}[] | Record<string, any> | null,
sms_campaign?: Record<string, any> | null,
email_campaign?: Record<string, any> | null
}
webhookHooks example
sender({
webhookHooks: {
groups: {
subscriberAdded: {
before(ctx, args) {
return { ctx, args };
},
after(ctx, response) {
},
},
},
},
})
Subscriber Unsubscribed
groups.subscriberUnsubscribed
A subscriber left the group the webhook watches (groups/unsubscribed).
Payload
| Name | Type | Required | Description |
|---|---|---|---|
id | string | number | Yes | — |
email | string | null | No | — |
firstname | string | null | No | — |
lastname | string | null | No | — |
phone | string | null | No | — |
phone_country | object | null | No | — |
created | string | null | No | — |
status | Record<string, any> | null | No | — |
ip_address | string | null | No | — |
bounced_at | string | null | No | — |
unsubscribed_at | string | null | No | — |
unsubscribed | boolean | number | null | No | — |
bounced | boolean | number | null | No | — |
spam_reported | boolean | number | null | No | — |
location | any | No | — |
source | string | null | No | — |
subscriber_tags | object[] | null | No | — |
columns | object[] | Record<string, any> | null | No | — |
sms_campaign | Record<string, any> | null | No | — |
email_campaign | Record<string, any> | null | No | — |
phone_country full type
phone_country full type
{
phone_code?: number | null,
country_code?: string | null
} | null
subscriber_tags full type
subscriber_tags full type
(
{
id?: string | number | null,
title?: string | null
} | string
)[] | null
columns full type
columns full type
{
id?: string | number | null,
title?: string | null,
type?: string | null,
default?: boolean | number | null,
value?: any
}[] | Record<string, any> | null
Response data full type
Response data full type
{
id: string | number,
email?: string | null,
firstname?: string | null,
lastname?: string | null,
phone?: string | null,
phone_country?: {
phone_code?: number | null,
country_code?: string | null
} | null,
created?: string | null,
status?: Record<string, any> | null,
ip_address?: string | null,
bounced_at?: string | null,
unsubscribed_at?: string | null,
unsubscribed?: boolean | number | null,
bounced?: boolean | number | null,
spam_reported?: boolean | number | null,
location?: any,
source?: string | null,
subscriber_tags?: (
{
id?: string | number | null,
title?: string | null
} | string
)[] | null,
columns?: {
id?: string | number | null,
title?: string | null,
type?: string | null,
default?: boolean | number | null,
value?: any
}[] | Record<string, any> | null,
sms_campaign?: Record<string, any> | null,
email_campaign?: Record<string, any> | null
}
webhookHooks example
sender({
webhookHooks: {
groups: {
subscriberUnsubscribed: {
before(ctx, args) {
return { ctx, args };
},
after(ctx, response) {
},
},
},
},
})
Subscribers
Created
subscribers.created
A subscriber was added (subscribers/new).
Payload
| Name | Type | Required | Description |
|---|---|---|---|
id | string | number | Yes | — |
email | string | null | No | — |
firstname | string | null | No | — |
lastname | string | null | No | — |
phone | string | null | No | — |
phone_country | object | null | No | — |
created | string | null | No | — |
status | Record<string, any> | null | No | — |
ip_address | string | null | No | — |
bounced_at | string | null | No | — |
unsubscribed_at | string | null | No | — |
unsubscribed | boolean | number | null | No | — |
bounced | boolean | number | null | No | — |
spam_reported | boolean | number | null | No | — |
location | any | No | — |
source | string | null | No | — |
subscriber_tags | object[] | null | No | — |
columns | object[] | Record<string, any> | null | No | — |
sms_campaign | Record<string, any> | null | No | — |
email_campaign | Record<string, any> | null | No | — |
phone_country full type
phone_country full type
{
phone_code?: number | null,
country_code?: string | null
} | null
subscriber_tags full type
subscriber_tags full type
(
{
id?: string | number | null,
title?: string | null
} | string
)[] | null
columns full type
columns full type
{
id?: string | number | null,
title?: string | null,
type?: string | null,
default?: boolean | number | null,
value?: any
}[] | Record<string, any> | null
Response data full type
Response data full type
{
id: string | number,
email?: string | null,
firstname?: string | null,
lastname?: string | null,
phone?: string | null,
phone_country?: {
phone_code?: number | null,
country_code?: string | null
} | null,
created?: string | null,
status?: Record<string, any> | null,
ip_address?: string | null,
bounced_at?: string | null,
unsubscribed_at?: string | null,
unsubscribed?: boolean | number | null,
bounced?: boolean | number | null,
spam_reported?: boolean | number | null,
location?: any,
source?: string | null,
subscriber_tags?: (
{
id?: string | number | null,
title?: string | null
} | string
)[] | null,
columns?: {
id?: string | number | null,
title?: string | null,
type?: string | null,
default?: boolean | number | null,
value?: any
}[] | Record<string, any> | null,
sms_campaign?: Record<string, any> | null,
email_campaign?: Record<string, any> | null
}
webhookHooks example
sender({
webhookHooks: {
subscribers: {
created: {
before(ctx, args) {
return { ctx, args };
},
after(ctx, response) {
},
},
},
},
})
Unsubscribed
subscribers.unsubscribed
A subscriber unsubscribed (subscribers/unsubscribed).
Payload
| Name | Type | Required | Description |
|---|---|---|---|
id | string | number | Yes | — |
email | string | null | No | — |
firstname | string | null | No | — |
lastname | string | null | No | — |
phone | string | null | No | — |
phone_country | object | null | No | — |
created | string | null | No | — |
status | Record<string, any> | null | No | — |
ip_address | string | null | No | — |
bounced_at | string | null | No | — |
unsubscribed_at | string | null | No | — |
unsubscribed | boolean | number | null | No | — |
bounced | boolean | number | null | No | — |
spam_reported | boolean | number | null | No | — |
location | any | No | — |
source | string | null | No | — |
subscriber_tags | object[] | null | No | — |
columns | object[] | Record<string, any> | null | No | — |
sms_campaign | Record<string, any> | null | No | — |
email_campaign | Record<string, any> | null | No | — |
phone_country full type
phone_country full type
{
phone_code?: number | null,
country_code?: string | null
} | null
subscriber_tags full type
subscriber_tags full type
(
{
id?: string | number | null,
title?: string | null
} | string
)[] | null
columns full type
columns full type
{
id?: string | number | null,
title?: string | null,
type?: string | null,
default?: boolean | number | null,
value?: any
}[] | Record<string, any> | null
Response data full type
Response data full type
{
id: string | number,
email?: string | null,
firstname?: string | null,
lastname?: string | null,
phone?: string | null,
phone_country?: {
phone_code?: number | null,
country_code?: string | null
} | null,
created?: string | null,
status?: Record<string, any> | null,
ip_address?: string | null,
bounced_at?: string | null,
unsubscribed_at?: string | null,
unsubscribed?: boolean | number | null,
bounced?: boolean | number | null,
spam_reported?: boolean | number | null,
location?: any,
source?: string | null,
subscriber_tags?: (
{
id?: string | number | null,
title?: string | null
} | string
)[] | null,
columns?: {
id?: string | number | null,
title?: string | null,
type?: string | null,
default?: boolean | number | null,
value?: any
}[] | Record<string, any> | null,
sms_campaign?: Record<string, any> | null,
email_campaign?: Record<string, any> | null
}
webhookHooks example
sender({
webhookHooks: {
subscribers: {
unsubscribed: {
before(ctx, args) {
return { ctx, args };
},
after(ctx, response) {
},
},
},
},
})
Updated
subscribers.updated
A subscriber was changed (subscribers/updated).
Payload
| Name | Type | Required | Description |
|---|---|---|---|
id | string | number | Yes | — |
email | string | null | No | — |
firstname | string | null | No | — |
lastname | string | null | No | — |
phone | string | null | No | — |
phone_country | object | null | No | — |
created | string | null | No | — |
status | Record<string, any> | null | No | — |
ip_address | string | null | No | — |
bounced_at | string | null | No | — |
unsubscribed_at | string | null | No | — |
unsubscribed | boolean | number | null | No | — |
bounced | boolean | number | null | No | — |
spam_reported | boolean | number | null | No | — |
location | any | No | — |
source | string | null | No | — |
subscriber_tags | object[] | null | No | — |
columns | object[] | Record<string, any> | null | No | — |
sms_campaign | Record<string, any> | null | No | — |
email_campaign | Record<string, any> | null | No | — |
phone_country full type
phone_country full type
{
phone_code?: number | null,
country_code?: string | null
} | null
subscriber_tags full type
subscriber_tags full type
(
{
id?: string | number | null,
title?: string | null
} | string
)[] | null
columns full type
columns full type
{
id?: string | number | null,
title?: string | null,
type?: string | null,
default?: boolean | number | null,
value?: any
}[] | Record<string, any> | null
Response data full type
Response data full type
{
id: string | number,
email?: string | null,
firstname?: string | null,
lastname?: string | null,
phone?: string | null,
phone_country?: {
phone_code?: number | null,
country_code?: string | null
} | null,
created?: string | null,
status?: Record<string, any> | null,
ip_address?: string | null,
bounced_at?: string | null,
unsubscribed_at?: string | null,
unsubscribed?: boolean | number | null,
bounced?: boolean | number | null,
spam_reported?: boolean | number | null,
location?: any,
source?: string | null,
subscriber_tags?: (
{
id?: string | number | null,
title?: string | null
} | string
)[] | null,
columns?: {
id?: string | number | null,
title?: string | null,
type?: string | null,
default?: boolean | number | null,
value?: any
}[] | Record<string, any> | null,
sms_campaign?: Record<string, any> | null,
email_campaign?: Record<string, any> | null
}
webhookHooks example
sender({
webhookHooks: {
subscribers: {
updated: {
before(ctx, args) {
return { ctx, args };
},
after(ctx, response) {
},
},
},
},
})