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

# Webhooks

> PDFMonkey incoming webhooks: event paths, payloads, and response data.

The PDFMonkey plugin handles incoming webhooks. Point your provider’s subscription URL at your Corsair HTTP handler (see [Overview](/plugins/pdfmonkey/overview) for setup context and the exact URL shape).

<Info>
  **New to Corsair?** See [webhooks](/concepts/webhooks) and [hooks](/concepts/hooks).
</Info>

## Webhook map

* `documents`
  * `generationFailure` (`documents.generationFailure`)
  * `generationSuccess` (`documents.generationSuccess`)

## 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);
    const body = await request.json();
    const result = await processWebhook(corsair, headers, body);
    return result.response;
}
```

## Events

## Documents

### Generation Failure

`documents.generationFailure`

A document failed to generate

**Payload**

| Name       | Type                           | Required | Description |
| ---------- | ------------------------------ | -------- | ----------- |
| `type`     | `documents.generation.failure` | No       | —           |
| `document` | `object`                       | Yes      | —           |

<AccordionGroup>
  <Accordion title="document full type">
    ```ts theme={null}
    {
      id: string,
      app_id: string,
      document_template_id?: string,
      document_template_identifier?: string,
      status: failure,
      filename?: string | null,
      download_url?: string | null,
      preview_url?: string | null,
      public_share_link?: string | null,
      failure_cause?: string | null,
      meta?: any | null,
      output_type?: pdf | image,
      created_at: string,
      updated_at: string
    }
    ```
  </Accordion>
</AccordionGroup>

<AccordionGroup>
  <Accordion title="Response data full type">
    ```ts theme={null}
    {
      type?: documents.generation.failure,
      document: {
        id: string,
        app_id: string,
        document_template_id?: string,
        document_template_identifier?: string,
        status: failure,
        filename?: string | null,
        download_url?: string | null,
        preview_url?: string | null,
        public_share_link?: string | null,
        failure_cause?: string | null,
        meta?: any | null,
        output_type?: pdf | image,
        created_at: string,
        updated_at: string
      }
    }
    ```
  </Accordion>
</AccordionGroup>

**`webhookHooks` example**

```ts theme={null}
pdfmonkey({
    webhookHooks: {
        documents: {
            generationFailure: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***

### Generation Success

`documents.generationSuccess`

A document finished generating successfully

**Payload**

| Name       | Type                           | Required | Description |
| ---------- | ------------------------------ | -------- | ----------- |
| `type`     | `documents.generation.success` | No       | —           |
| `document` | `object`                       | Yes      | —           |

<AccordionGroup>
  <Accordion title="document full type">
    ```ts theme={null}
    {
      id: string,
      app_id: string,
      document_template_id?: string,
      document_template_identifier?: string,
      status: success,
      filename?: string | null,
      download_url?: string | null,
      preview_url?: string | null,
      public_share_link?: string | null,
      failure_cause?: string | null,
      meta?: any | null,
      output_type?: pdf | image,
      created_at: string,
      updated_at: string
    }
    ```
  </Accordion>
</AccordionGroup>

<AccordionGroup>
  <Accordion title="Response data full type">
    ```ts theme={null}
    {
      type?: documents.generation.success,
      document: {
        id: string,
        app_id: string,
        document_template_id?: string,
        document_template_identifier?: string,
        status: success,
        filename?: string | null,
        download_url?: string | null,
        preview_url?: string | null,
        public_share_link?: string | null,
        failure_cause?: string | null,
        meta?: any | null,
        output_type?: pdf | image,
        created_at: string,
        updated_at: string
      }
    }
    ```
  </Accordion>
</AccordionGroup>

**`webhookHooks` example**

```ts theme={null}
pdfmonkey({
    webhookHooks: {
        documents: {
            generationSuccess: {
                before(ctx, args) {
                    return { ctx, args };
                },
                after(ctx, response) {
                },
            },
        },
    },
})
```

***
