Skip to main content
Server functions let you make HTTP requests from your app, whether it’s to a third-party API, or to the Attio REST API using ATTIO_API_TOKEN. The App SDK does not allow client-side fetch requests, so all HTTP requests must go through server functions which run inside a secure sandbox within the Attio infrastructure. The server function runtime is not Node.js compatible, meaning some libraries that work in Node.js might not work in our environment.
While they do have some similarities, Attio’s server functions are not to be confused with React Server Functions. Attio server functions have different capabilities and therefore do not follow the React Server Components protocol.
The globals available to you are listed in Available Globals.

How to use server functions in your app

To use a server function in your app, follow these steps:
  1. Create a new .server.ts file anywhere in your folder structure.
  2. Create an async function within the file. Implement any data fetching and logic required for your app.
  3. Expose the function as the default export of the file.
  4. Import and use the server function from client-side code.

Example: Add a prospect to an external mail sequencing API

This example shows a server function being used to call an external mail sequencing API and add a prospect to a sequence. First, we create a file with the .server.ts suffix. The file can be placed anywhere in your app, but it must export default a function which returns a promise. This function acts as the entry point for the server function.
add-to-sequence.server.ts
Then, this addToSequence() function can be called from your client by simply importing it and calling it with the required arguments.
src/app/extensions/add-to-sequence/extension.tsx
As you can see, it’s possible to pass arguments to a server function and access its return value. Each call to a server function sends a request to Attio’s infrastructure, where the server function runs in a sandboxed environment. Because the function call crosses a network boundary, only JSON-serializable data can be passed between client and server functions.
Whatever you pass to or return from a server function will go through JSON.stringify(JSON.parse(...)).
As you can see in the example code, if a server function throws an error, it is re-thrown on the client side and can be handled with try/catch or .catch promise chaining.

Debugging server functions

To check output of console.log() placed inside the server functions, open the Logs tab for your app in the Developer console.

Accessing secrets from server functions

By enforcing the use of server functions, the App SDK keeps secrets hidden from the client and ensures they are managed securely. In the example above, we used a hardcoded API token. This may be sufficient for testing, but in a real app you should use one of the following instead:
  • Environment variables for app-level secrets and configuration, such as an API key for a vendor account owned by your app. They are read via process.env in server-side code.
  • Connections for performing actions on behalf of the Attio user or workspace, with built-in support for OAuth 2.0.