> ## Documentation Index
> Fetch the complete documentation index at: https://docs.corsair.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Dub webhooks

> Dub incoming webhooks in Corsair: the event paths to subscribe to, the payload each event carries, and the response data.

The Dub plugin handles incoming webhooks. Point your provider’s subscription URL at your Corsair HTTP handler (see [Overview](https://docs.corsair.dev/plugins/dub/overview.md) for setup context and the exact URL shape).

> [!NOTE]
>
> **New to Corsair?** See [webhooks](https://docs.corsair.dev/concepts/webhooks.md) and [hooks](https://docs.corsair.dev/concepts/hooks.md).

## Webhook map

* `commission`
  * `created` (`commission.created`)
* `discountCode`
  * `created` (`discountCode.created`)
  * `deleted` (`discountCode.deleted`)
* `lead`
  * `created` (`lead.created`)
* `link`
  * `clicked` (`link.clicked`)
  * `created` (`link.created`)
  * `deleted` (`link.deleted`)
  * `updated` (`link.updated`)
* `message`
  * `received` (`message.received`)
* `partner`
  * `applicationSubmitted` (`partner.applicationSubmitted`)
  * `enrolled` (`partner.enrolled`)
  * `merged` (`partner.merged`)
* `programApplication`
  * `created` (`programApplication.created`)
* `sale`
  * `created` (`sale.created`)

## HTTP handler setup

```ts app/api/webhook/route.ts theme={null}
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

## Commission

### Created

`commission.created`

A commission was created for a partner (event commission.created)

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | — |
| `event` | `commission.created` | Yes | — |
| `createdAt` | `string \| null` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   id: string,
>   event: commission.created,
>   createdAt?: string | null,
>   data: {
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
dub({
    webhookHooks: {
        commission: {
            created: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

## Discount Code

### Created

`discountCode.created`

A discount code was created (event discount\_code.created)

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | — |
| `event` | `discount_code.created` | Yes | — |
| `createdAt` | `string \| null` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   id: string,
>   event: discount_code.created,
>   createdAt?: string | null,
>   data: {
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
dub({
    webhookHooks: {
        discountCode: {
            created: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

### Deleted

`discountCode.deleted`

A discount code was deleted (event discount\_code.deleted)

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | — |
| `event` | `discount_code.deleted` | Yes | — |
| `createdAt` | `string \| null` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   id: string,
>   event: discount_code.deleted,
>   createdAt?: string | null,
>   data: {
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
dub({
    webhookHooks: {
        discountCode: {
            deleted: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

## Lead

### Created

`lead.created`

A lead conversion was tracked (event lead.created)

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | — |
| `event` | `lead.created` | Yes | — |
| `createdAt` | `string \| null` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   id: string,
>   event: lead.created,
>   createdAt?: string | null,
>   data: {
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
dub({
    webhookHooks: {
        lead: {
            created: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

## Link

### Clicked

`link.clicked`

A short link was clicked (event link.clicked)

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | — |
| `event` | `link.clicked` | Yes | — |
| `createdAt` | `string \| null` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   id: string,
>   event: link.clicked,
>   createdAt?: string | null,
>   data: {
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
dub({
    webhookHooks: {
        link: {
            clicked: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

### Created

`link.created`

A short link was created (event link.created)

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | — |
| `event` | `link.created` | Yes | — |
| `createdAt` | `string \| null` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   id: string,
>   event: link.created,
>   createdAt?: string | null,
>   data: {
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
dub({
    webhookHooks: {
        link: {
            created: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

### Deleted

`link.deleted`

A short link was deleted (event link.deleted)

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | — |
| `event` | `link.deleted` | Yes | — |
| `createdAt` | `string \| null` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   id: string,
>   event: link.deleted,
>   createdAt?: string | null,
>   data: {
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
dub({
    webhookHooks: {
        link: {
            deleted: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

### Updated

`link.updated`

A short link was changed (event link.updated)

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | — |
| `event` | `link.updated` | Yes | — |
| `createdAt` | `string \| null` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   id: string,
>   event: link.updated,
>   createdAt?: string | null,
>   data: {
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
dub({
    webhookHooks: {
        link: {
            updated: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

## Message

### Received

`message.received`

A partner sent the program a message (event message.received)

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | — |
| `event` | `message.received` | Yes | — |
| `createdAt` | `string \| null` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   id: string,
>   event: message.received,
>   createdAt?: string | null,
>   data: {
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
dub({
    webhookHooks: {
        message: {
            received: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

## Partner

### Application Submitted

`partner.applicationSubmitted`

A partner applied to the program (event partner.application\_submitted)

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | — |
| `event` | `partner.application_submitted` | Yes | — |
| `createdAt` | `string \| null` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   id: string,
>   event: partner.application_submitted,
>   createdAt?: string | null,
>   data: {
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
dub({
    webhookHooks: {
        partner: {
            applicationSubmitted: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

### Enrolled

`partner.enrolled`

A partner joined the program (event partner.enrolled)

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | — |
| `event` | `partner.enrolled` | Yes | — |
| `createdAt` | `string \| null` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   id: string,
>   event: partner.enrolled,
>   createdAt?: string | null,
>   data: {
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
dub({
    webhookHooks: {
        partner: {
            enrolled: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

### Merged

`partner.merged`

Two partner accounts were merged (event partner.merged)

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | — |
| `event` | `partner.merged` | Yes | — |
| `createdAt` | `string \| null` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   id: string,
>   event: partner.merged,
>   createdAt?: string | null,
>   data: {
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
dub({
    webhookHooks: {
        partner: {
            merged: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

## Program Application

### Created

`programApplication.created`

A program application was created (event program\_application.created)

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | — |
| `event` | `program_application.created` | Yes | — |
| `createdAt` | `string \| null` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   id: string,
>   event: program_application.created,
>   createdAt?: string | null,
>   data: {
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
dub({
    webhookHooks: {
        programApplication: {
            created: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

## Sale

### Created

`sale.created`

A sale conversion was tracked (event sale.created)

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | — |
| `event` | `sale.created` | Yes | — |
| `createdAt` | `string \| null` | No | — |
| `data` | `object` | Yes | — |

> [accordion] data full type
>
> ```ts theme={null}
> {
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   id: string,
>   event: sale.created,
>   createdAt?: string | null,
>   data: {
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
dub({
    webhookHooks: {
        sale: {
            created: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.