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.
How to use server functions in your app
To use a server function in your app, follow these steps:- Create a new
.server.tsfile anywhere in your folder structure. - Create an async function within the file. Implement any data fetching and logic required for your app.
- Expose the function as the default export of the file.
- 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
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
try/catch or .catch
promise chaining.
Debugging server functions
To check output ofconsole.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.envin server-side code. - Connections for performing actions on behalf of the Attio user or workspace, with built-in support for OAuth 2.0.