Skip to main content
An app extends Attio by pulling data from a third-party service into Attio, or extracting Attio data to use with an external tool. Apps can surface custom UI directly inside Attio’s interface using React components, run server-side logic in Attio’s sandbox, and call the REST API to read and write Attio data. This page walks through a complete example to show how the pieces fit together. For a higher-level map of what you can build, see the App SDK overview. Let’s look at an example. Let’s imagine a hypothetical service called Acme Lead Checker (ALC) that has an API to receive potential leads, an AI agent initiates an SMS chat with the lead, and then needs to update the lead’s record in Attio about how interested the person is in whatever product we are selling. Our app needs:
  • A button inside Attio that will call a server function
  • A server function to actually send the data to ALC
  • A webhook to receive the lead status back from ALC sometime in the future
App UI components cannot directly communicate with the outside world. They can only call custom app server functions, which can communicate with the outside world via fetch(), and communicate with Attio’s REST API via ATTIO_API_TOKEN.

Sequence

The general sequence of how the app will work is:

Installation

  1. User clicks to install the app.
  2. User is prompted to add a connection to Acme Lead Checker
  3. User logs into Acme Lead Checker to complete the OAuth flow.
  4. User is redirected back to Attio. The app is now installed.
  5. The connection-added event handler the app registered is fired.
  6. Event Handler calls createWebhookHandler() to register a webhook handler.
  7. Event Handler registers the new webhook with Acme Lead Checker.

Usage

  1. App provides a record action which will manifest itself in Attio’s UI as - a button on the People record page - in the CMD+K quick action palette.
  2. User views the record page
  3. User clicks button
  4. Attio’s UI fires the onTrigger() function provided by the record action
  5. Record Action notifies the user that async things are happening with showToast().
  6. Record Action loads the phone number of the person whose record page we are on asynchronously via GraphQL using runQuery(). - If no phone numbers are found, the user is notified via an alert(). Otherwise…
  7. Record Action calls a server function called sendToALC().
  8. Server function uses fetch() to send a POST request to api.acmeleadchecker.ai.
  9. Server function calls the Attio REST API with ATTIO_API_TOKEN to mark the record as “Pending”.
  10. Server function returns success.
  11. Record Action hides first toast with hideToast().
  12. Record Action notifies the user that the process was successful with showToast().
…some time later…
  1. Acme Lead Checker’s server calls a webhook provided by the app.
  2. Webhook Handler calls the Attio REST API with ATTIO_API_TOKEN to mark the record as “Complete”.

Implementation

App structure

An app is organized by folder convention under src/app/: the CLI discovers every entry point from the file layout (see App structure). Our finished app will look like this:

Record action

Our record action lives in its own folder under src/app/extensions/, as the default export of that folder’s extension.tsx:
src/app/extensions/send-to-alc/extension.tsx

GraphQL query

Now let’s write that GraphQL query we’re importing:
src/app/extensions/send-to-alc/get-person-phone-numbers.graphql

Server function

Server function file names MUST:
  • have a .server.ts suffix
  • contain an export default async function
The suffix is how Attio knows to execute them on the server. However, they are imported as if they were in the same bundle as the client side code, even though they are not.
Because they live in different bundles and runtimes, everything passed to, returned from, or thrown by server functions MUST be serializable.
send-to-alc.server.ts

Webhook handler

Our webhook handler is going to be called by Acme Lead Checker when they have processed our lead that we sent them. Webhook handler files MUST:
  • Live under the src/app/webhooks directory
  • Have a .webhook.ts suffix.
  • Contain an export default async function that:
src/app/webhooks/lead-processed.webhook.ts

Connection event handlers

In order to let Acme Lead Checker know how to call our app’s webhook, we need to tell them as soon as our user creates an authorized connection; we accomplish this with event handlers. Connection Event Handler files MUST:
  • Live in src/app/events
  • Have a .event.ts suffix.
  • Contain an export default async function that:
    • Takes a { connection: Connection } argument
    • Returns void

Connection added event handler

When a connection is added, we need to:
  1. Create a webhook
  2. Register our webhook with Acme Lead Checker
  3. Update our webhook with the unique identifier of our webhook on ALC’s side
src/app/events/connection-added.event.ts

Connection removed event handler

When a connection is removed, we need to:
  1. Load all our app’s webhook handlers (there should only be one)
  2. For each handler, tell ALC to stop calling it
  3. Delete the webhook from Attio
src/app/events/connection-removed.event.ts

Workflow blocks

The example above shows how apps surface UI and call external APIs. Apps can also extend Attio Workflows with custom triggers and steps.
  • A trigger block starts a workflow run when an external event arrives, for example a webhook from a third-party service.
  • A step block runs as part of an in-progress workflow run, for example calling an external API, transforming data, or waiting on an async callback.
Workflow blocks use the same server sandbox as server functions and have full access to fetch(), ATTIO_API_TOKEN, and connections. See the Workflow blocks overview and the reference pages for full details.