Skip to main content
Webhook handlers enable apps to receive incoming requests from third-party services. Unlike server functions, which are used to send requests, Webhook handlers are designed to listen for and process external requests. They can be used to sync data into Attio or respond with on-demand data to third-party services, making them essential for integrating external systems and automating workflows.

Example: Receiving prospect updated webhook from email sequencing API

You can use a webhook handler to receive a prospect updated event from the email sequencing API and update the corresponding record in Attio. To add a webhook handler to your app:
  • create a file with the .webhook.ts suffix.
  • The file must be placed under the src/app/webhooks directory, and it must export default an async function.
  • The function must take an HTTP Request argument and must return an HTTP Response.
src/app/webhooks/prospect-updated.webhook.ts
This webhook handler calls the Upsert Record endpoint to create or update a record in Attio. Whatever status code your handler returns will be passed back to the third-party service to indicate success or failure. If your handler doesn’t return a Response object, the App SDK will respond with a 500 status code by default. Defining a webhook handler isn’t enough to make it usable. You’ll need to enable it programmatically and register it with the third-party service. You can do this from any server function, but most of the time you’ll want to do it inside the connection-added event. The connection-added event runs whenever an Attio user connects to a third-party service through your app. If your event handler completes without throwing an error, the connection will be saved. If it throws, the user will be asked to authenticate again.
Be sure to test your connection-added events carefully. If something goes wrong, users won’t be able to connect to third-party services.
Now back to our example. We are going to add connection-added event handler to our app.
  • The file must live in src/app/events/connection-added.event.ts
  • The file must export default an async function that takes a { connection: Connection } argument.
src/app/events/connection-added.event.ts
And that’s it! Now whenever a prospect update webhook is received, the prospect-updated webhook handler will be called.
You can use the externalWebhookId to delete the webhook from the third-party service when the connection is removed inside the connection-removed event.