How to use connections in your app
- Head to the Connections tab in your app’s settings, found in the developer dashboard.
- Configure a workspace and/or user connection for your app. Choose the type of connection that best suits the authentication requirements of your external service.
- Retrieve the connection value in your server-side app code by calling either
getUserConnectionorgetWorkspaceConnection. - Use the connection value to authenticate to the external service when making HTTP requests.
Workspace vs user connections
Connections may be configured for either a specific user or the entire workspace.- Workspace connections provide authentication for the entire workspace. When you call
getWorkspaceConnection, you’ll always receive the same shared connection value. Only admins may configure workspace connections. - User connections provide authentication for a specific user. When you call
getUserConnection, you’ll receive a connection value for the specific user who triggered the current execution. Both admins and non-admins may configure user connections.
It’s possible to enable both a user and a workspace connection in the same app, although most apps only require one or the other.
Connection types
Attio currently supports the following authentication types:- Secret - Stores a string secret, such as an API key.
- OAuth 2.0 - Stores an OAuth 2.0 access token. Authentication to external services which support the OAuth 2.0 authorization code flow is managed automatically by Attio.
Handling unauthenticated states
If eithergetUserConnection or
getWorkspaceConnection is called when a user is yet to set a connection,
Attio will automatically throw an error and prompt the user to authenticate.
When writing app code, you do not need to handle missing connection states. Attio will do this for you.
Bad example of handling unauthenticated states
Good example of handling unauthenticated states
Example: Authenticating to an external mail sequencing API
Once you have enabled a connection for your app, you can retrieve the connection value in your server functions. We can modify the example from Making HTTP requests to use a connection to authenticate to the external mail sequencing API, instead of using a hardcoded API key.add-to-sequence.server.ts