> ## 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.

# Close webhooks

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

The Close plugin handles incoming webhooks. Point your provider’s subscription URL at your Corsair HTTP handler (see [Overview](https://docs.corsair.dev/plugins/close/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

* `activityNote`
  * `created` (`activityNote.created`)
* `contact`
  * `created` (`contact.created`)
* `lead`
  * `created` (`lead.created`)
  * `updated` (`lead.updated`)
* `opportunity`
  * `created` (`opportunity.created`)
* `task`
  * `created` (`task.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

## Activity Note

### Created

`activityNote.created`

A note activity was created in Close CRM

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `subscription_id` | `string` | No | — |
| `event` | `object` | Yes | — |

> [accordion] event full type
>
> ```ts theme={null}
> {
>   id?: string,
>   object_type: activity.note,
>   object_id?: string,
>   action: created,
>   organization_id?: string,
>   data: {
>     id: string,
>     lead_id?: string,
>     note?: string,
>     user_id?: string | null,
>     organization_id?: string,
>     date_created?: string,
>     date_updated?: string
>   },
>   previous_data?: any,
>   changed_fields?: string[],
>   date_created?: string,
>   date_updated?: string,
>   user_id?: string,
>   lead_id?: string,
>   request_id?: string
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   subscription_id?: string,
>   event: {
>     id?: string,
>     object_type: activity.note,
>     object_id?: string,
>     action: created,
>     organization_id?: string,
>     data: {
>       id: string,
>       lead_id?: string,
>       note?: string,
>       user_id?: string | null,
>       organization_id?: string,
>       date_created?: string,
>       date_updated?: string
>     },
>     previous_data?: any,
>     changed_fields?: string[],
>     date_created?: string,
>     date_updated?: string,
>     user_id?: string,
>     lead_id?: string,
>     request_id?: string
>   }
> }
> ```

**`webhookHooks` example**

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

***

## Contact

### Created

`contact.created`

A contact was created in Close CRM

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `subscription_id` | `string` | No | — |
| `event` | `object` | Yes | — |

> [accordion] event full type
>
> ```ts theme={null}
> {
>   id?: string,
>   object_type: contact,
>   object_id?: string,
>   action: created,
>   organization_id?: string,
>   data: {
>     id: string,
>     lead_id?: string,
>     name?: string,
>     title?: string | null,
>     emails?: {
>       email: string,
>       type?: string
>     }[],
>     phones?: {
>       phone: string,
>       type?: string
>     }[],
>     organization_id?: string,
>     created_by?: string | null,
>     date_created?: string,
>     date_updated?: string
>   },
>   previous_data?: any,
>   changed_fields?: string[],
>   date_created?: string,
>   date_updated?: string,
>   user_id?: string,
>   lead_id?: string,
>   request_id?: string
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   subscription_id?: string,
>   event: {
>     id?: string,
>     object_type: contact,
>     object_id?: string,
>     action: created,
>     organization_id?: string,
>     data: {
>       id: string,
>       lead_id?: string,
>       name?: string,
>       title?: string | null,
>       emails?: {
>         email: string,
>         type?: string
>       }[],
>       phones?: {
>         phone: string,
>         type?: string
>       }[],
>       organization_id?: string,
>       created_by?: string | null,
>       date_created?: string,
>       date_updated?: string
>     },
>     previous_data?: any,
>     changed_fields?: string[],
>     date_created?: string,
>     date_updated?: string,
>     user_id?: string,
>     lead_id?: string,
>     request_id?: string
>   }
> }
> ```

**`webhookHooks` example**

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

***

## Lead

### Created

`lead.created`

A lead was created in Close CRM

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `subscription_id` | `string` | No | — |
| `event` | `object` | Yes | — |

> [accordion] event full type
>
> ```ts theme={null}
> {
>   id?: string,
>   object_type: lead,
>   object_id?: string,
>   action: created,
>   organization_id?: string,
>   data: {
>     id: string,
>     name?: string,
>     status_id?: string | null,
>     status_label?: string | null,
>     description?: string | null,
>     url?: string | null,
>     organization_id?: string,
>     contacts?: Record<string, any>[],
>     custom?: Record<string, any>,
>     created_by?: string | null,
>     updated_by?: string | null,
>     date_created?: string,
>     date_updated?: string
>   },
>   previous_data?: any,
>   changed_fields?: string[],
>   date_created?: string,
>   date_updated?: string,
>   user_id?: string,
>   lead_id?: string,
>   request_id?: string
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   subscription_id?: string,
>   event: {
>     id?: string,
>     object_type: lead,
>     object_id?: string,
>     action: created,
>     organization_id?: string,
>     data: {
>       id: string,
>       name?: string,
>       status_id?: string | null,
>       status_label?: string | null,
>       description?: string | null,
>       url?: string | null,
>       organization_id?: string,
>       contacts?: Record<string, any>[],
>       custom?: Record<string, any>,
>       created_by?: string | null,
>       updated_by?: string | null,
>       date_created?: string,
>       date_updated?: string
>     },
>     previous_data?: any,
>     changed_fields?: string[],
>     date_created?: string,
>     date_updated?: string,
>     user_id?: string,
>     lead_id?: string,
>     request_id?: string
>   }
> }
> ```

**`webhookHooks` example**

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

***

### Updated

`lead.updated`

A lead was updated in Close CRM

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `subscription_id` | `string` | No | — |
| `event` | `object` | Yes | — |

> [accordion] event full type
>
> ```ts theme={null}
> {
>   id?: string,
>   object_type: lead,
>   object_id?: string,
>   action: updated,
>   organization_id?: string,
>   data: {
>     id: string,
>     name?: string,
>     status_id?: string | null,
>     status_label?: string | null,
>     description?: string | null,
>     url?: string | null,
>     organization_id?: string,
>     contacts?: Record<string, any>[],
>     custom?: Record<string, any>,
>     created_by?: string | null,
>     updated_by?: string | null,
>     date_created?: string,
>     date_updated?: string
>   },
>   previous_data?: any,
>   changed_fields?: string[],
>   date_created?: string,
>   date_updated?: string,
>   user_id?: string,
>   lead_id?: string,
>   request_id?: string
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   subscription_id?: string,
>   event: {
>     id?: string,
>     object_type: lead,
>     object_id?: string,
>     action: updated,
>     organization_id?: string,
>     data: {
>       id: string,
>       name?: string,
>       status_id?: string | null,
>       status_label?: string | null,
>       description?: string | null,
>       url?: string | null,
>       organization_id?: string,
>       contacts?: Record<string, any>[],
>       custom?: Record<string, any>,
>       created_by?: string | null,
>       updated_by?: string | null,
>       date_created?: string,
>       date_updated?: string
>     },
>     previous_data?: any,
>     changed_fields?: string[],
>     date_created?: string,
>     date_updated?: string,
>     user_id?: string,
>     lead_id?: string,
>     request_id?: string
>   }
> }
> ```

**`webhookHooks` example**

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

***

## Opportunity

### Created

`opportunity.created`

An opportunity was created in Close CRM

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `subscription_id` | `string` | No | — |
| `event` | `object` | Yes | — |

> [accordion] event full type
>
> ```ts theme={null}
> {
>   id?: string,
>   object_type: opportunity,
>   object_id?: string,
>   action: created,
>   organization_id?: string,
>   data: {
>     id: string,
>     lead_id?: string,
>     lead_name?: string,
>     status_id?: string,
>     status_label?: string,
>     status_type?: string,
>     value?: number,
>     value_period?: string,
>     confidence?: number,
>     user_id?: string | null,
>     organization_id?: string,
>     date_won?: string | null,
>     date_lost?: string | null,
>     date_created?: string,
>     date_updated?: string
>   },
>   previous_data?: any,
>   changed_fields?: string[],
>   date_created?: string,
>   date_updated?: string,
>   user_id?: string,
>   lead_id?: string,
>   request_id?: string
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   subscription_id?: string,
>   event: {
>     id?: string,
>     object_type: opportunity,
>     object_id?: string,
>     action: created,
>     organization_id?: string,
>     data: {
>       id: string,
>       lead_id?: string,
>       lead_name?: string,
>       status_id?: string,
>       status_label?: string,
>       status_type?: string,
>       value?: number,
>       value_period?: string,
>       confidence?: number,
>       user_id?: string | null,
>       organization_id?: string,
>       date_won?: string | null,
>       date_lost?: string | null,
>       date_created?: string,
>       date_updated?: string
>     },
>     previous_data?: any,
>     changed_fields?: string[],
>     date_created?: string,
>     date_updated?: string,
>     user_id?: string,
>     lead_id?: string,
>     request_id?: string
>   }
> }
> ```

**`webhookHooks` example**

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

***

## Task

### Created

`task.created`

A task was created in Close CRM

**Payload**

| Name | Type | Required | Description |
| - | - | - | - |
| `subscription_id` | `string` | No | — |
| `event` | `object` | Yes | — |

> [accordion] event full type
>
> ```ts theme={null}
> {
>   id?: string,
>   object_type: string,
>   object_id?: string,
>   action: created,
>   organization_id?: string,
>   data: {
>     id: string,
>     lead_id?: string,
>     text?: string,
>     due_date?: string | null,
>     is_complete?: boolean,
>     assigned_to?: string | null,
>     type?: string,
>     organization_id?: string,
>     created_by?: string | null,
>     date_created?: string,
>     date_updated?: string
>   },
>   previous_data?: any,
>   changed_fields?: string[],
>   date_created?: string,
>   date_updated?: string,
>   user_id?: string,
>   lead_id?: string,
>   request_id?: string
> }
> ```

> [accordion] Response data full type
>
> ```ts theme={null}
> {
>   subscription_id?: string,
>   event: {
>     id?: string,
>     object_type: string,
>     object_id?: string,
>     action: created,
>     organization_id?: string,
>     data: {
>       id: string,
>       lead_id?: string,
>       text?: string,
>       due_date?: string | null,
>       is_complete?: boolean,
>       assigned_to?: string | null,
>       type?: string,
>       organization_id?: string,
>       created_by?: string | null,
>       date_created?: string,
>       date_updated?: string
>     },
>     previous_data?: any,
>     changed_fields?: string[],
>     date_created?: string,
>     date_updated?: string,
>     user_id?: string,
>     lead_id?: string,
>     request_id?: string
>   }
> }
> ```

**`webhookHooks` example**

```ts theme={null}
close({
    webhookHooks: {
        task: {
            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.