Example
Here’s an example that creates a webhook handler.TypeScript
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
The legacy app.ts layout is deprecated. New apps use the folder-based layout under src/app/; convert existing apps with the migration guide.
Fires when a connection is added to an app
// src/app/events/connection-added.event.ts
import {createWebhookHandler, updateWebhookHandler} from "attio/server"
import type {Connection} from "attio/server"
export default async function connectionAdded({connection}: {connection: Connection}) {
// You can create multiple webhook handlers for the same file
const webhookHandler = await createWebhookHandler({
fileName: "acme-webhook",
})
// create Webhook in third party system, with webhook handler URL
const acmeResponse = await fetch(`https://api.acmeinc.com/api/v1/registerWebhook`, {
method: "POST",
headers: {
"Content-Type": "application/vnd.api+json",
Authorization: `Bearer ${connection.value}`,
},
body: JSON.stringify({
name: "prospect-enrolled",
url: webhookHandler.url,
}),
})
if (!acmeResponse.ok) {
throw new Error("Failed to register webhook")
}
const body = await acmeResponse.json()
// We store the external webhook ID in Attio so we can clean it later
await updateWebhookHandler(webhookHandler.id, {
externalWebhookId: body.webhookId,
})
}
getUserConnection() /
getWorkspaceConnection()).Was this page helpful?