Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.attio.com/llms.txt

Use this file to discover all available pages before exploring further.

This event is triggered whenever a user removes a connection. The registered handler runs before the connection is deleted, meaning that if the handler throws an error, the connection will not be removed. You can use the handler to perform any necessary teardown work.

Example

Here’s an example that cleans up a webhook handler.
TypeScript
// src/events/connection-removed.event.ts
import {listWebhookHandlers, deleteWebhookHandler} from "attio/server"
import type {Connection} from "attio/server"

export default async function connectionRemoved({connection}: {connection: Connection}) {
  const webhookHandlers = await listWebhookHandlers()

  for (const webhookHandler of webhookHandlers) {
    const acmeResponse = await fetch(
      `https://api.acmeinc.com/api/v1/webhooks${webhookHandler.externalWebhookId}`,
      {
        method: "DELETE",
        headers: {
          Authorization: `Bearer ${connection.value}`,
        },
      },
    )

    if (!acmeResponse.ok) {
      throw new Error("Failed to register webhook")
    }

    await deleteWebhookHandler(webhookHandler.id)
  }
}