Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 19 lines 729 Bytes
Raw
1 import { Composio } from '@composio/core';
2
3 const composio = new Composio();
4
5 const userId = process.env.COMPOSIO_EXAMPLES_USER_ID; // the user id from your database
6 if (!userId) {
7 throw new Error('Set COMPOSIO_EXAMPLES_USER_ID');
8 }
9
10 const session = await composio.create(userId, { toolkits: ['gmail'] });
11 const connectionRequest = await session.authorize('gmail', {
12 callbackUrl: 'https://google.com',
13 });
14
15 console.log(`Visit this URL to authorize: ${connectionRequest.redirectUrl}`);
16
17 const connectedAccount = await connectionRequest.waitForConnection();
18 // Print identifying fields only: the full object carries live OAuth credentials.
19 console.log(`Connected account ${connectedAccount.id} is ${connectedAccount.status}`);