Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { AuthScheme, Composio } from '@composio/core'; |
| 2 | |
| 3 | const composio = new Composio({ |
| 4 | apiKey: process.env.COMPOSIO_API_KEY, |
| 5 | }); |
| 6 | |
| 7 | const authConfigId = process.env.COMPOSIO_EXAMPLES_APIKEY_AUTH_CONFIG_ID; // an API-key-scheme auth config ID |
| 8 | const apiKey = process.env.COMPOSIO_EXAMPLES_APIKEY_PLACEHOLDER; // the service API key to store |
| 9 | const userId = process.env.COMPOSIO_EXAMPLES_USER_ID; // the user id from your database |
| 10 | if (!authConfigId || !apiKey || !userId) { |
| 11 | throw new Error( |
| 12 | 'Set COMPOSIO_EXAMPLES_APIKEY_AUTH_CONFIG_ID, COMPOSIO_EXAMPLES_APIKEY_PLACEHOLDER and COMPOSIO_EXAMPLES_USER_ID' |
| 13 | ); |
| 14 | } |
| 15 | |
| 16 | const connectionRequest = await composio.connectedAccounts.initiate(userId, authConfigId, { |
| 17 | // Allow more than one connected account per user for this auth config |
| 18 | allowMultiple: true, |
| 19 | config: AuthScheme.APIKey({ |
| 20 | generic_api_key: apiKey, |
| 21 | }), |
| 22 | }); |
| 23 | |
| 24 | console.log(connectionRequest); |