apps/docs/connectors/google-drive.mdx
Connect Google Drive to sync documents into your Supermemory knowledge base with OAuth authentication and custom app support.
const client = new Supermemory({
apiKey: process.env.SUPERMEMORY_API_KEY!
});
const connection = await client.connections.create('google-drive', {
redirectUrl: 'https://yourapp.com/auth/google-drive/callback',
containerTags: ['user-123', 'gdrive-sync'],
documentLimit: 3000,
metadata: {
source: 'google-drive',
department: 'engineering'
}
});
// Redirect user to Google OAuth
window.location.href = connection.authLink;
console.log('Auth expires in:', connection.expiresIn);
```
client = Supermemory(api_key=os.environ.get("SUPERMEMORY_API_KEY"))
connection = client.connections.create(
'google-drive',
redirect_url='https://yourapp.com/auth/google-drive/callback',
container_tags=['user-123', 'gdrive-sync'],
document_limit=3000,
metadata={
'source': 'google-drive',
'department': 'engineering'
}
)
# Redirect user to Google OAuth
print(f'Redirect to: {connection.auth_link}')
print(f'Expires in: {connection.expires_in}')
```
After user grants permissions, Google redirects to your callback URL. The connection is automatically established.
# List synced documents
documents = client.connections.list_documents(
'google-drive',
container_tags=['user-123', 'gdrive-sync']
)
```
# List synced documents
curl -X POST "https://api.supermemory.ai/v3/documents/list" \
-H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"containerTags": ["user-123", "gdrive-sync"],
"source": "google-drive"
}'
```
Based on the API type definitions, Google Drive documents are identified with these types:
google_doc - Google Docsgoogle_slide - Google Slidesgoogle_sheet - Google Sheetsconnections.forEach(conn => {
console.log(`Provider: ${conn.provider}`);
console.log(`ID: ${conn.id}`);
console.log(`Email: ${conn.email}`);
console.log(`Created: ${conn.createdAt}`);
console.log(`Document limit: ${conn.documentLimit}`);
console.log('---');
});
```
for conn in connections:
print(f'Provider: {conn.provider}')
print(f'ID: {conn.id}')
print(f'Email: {conn.email}')
print(f'Created: {conn.created_at}')
print(f'Document limit: {conn.document_limit}')
print('---')
```
# Response example:
# [
# {
# "id": "conn_gd123",
# "provider": "google-drive",
# "email": "[email protected]",
# "createdAt": "2024-01-15T10:30:00.000Z",
# "documentLimit": 3000
# }
# ]
```
// Delete by provider and container tags
const providerResult = await client.connections.deleteByProvider('google-drive', {
containerTags: ['user-123']
});
console.log('Deleted provider connection:', providerResult.id);
```
# Delete by provider and container tags
provider_result = client.connections.delete_by_provider(
'google-drive',
container_tags=['user-123']
)
print(f'Deleted provider connection: {provider_result.id}')
```
# Response: {"id": "connection_id_123", "provider": "google-drive"}
# Delete by provider and container tags
curl -X DELETE "https://api.supermemory.ai/v3/connections/google-drive" \
-H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"containerTags": ["user-123"]
}'
# Response: {"id": "conn_gd123", "provider": "google-drive"}
```
Trigger a manual synchronization:
<Tabs> <Tab title="TypeScript"> ```typescript // Trigger sync for Google Drive connections await client.connections.import('google-drive');// Trigger sync for specific container tags
await client.connections.import('google-drive', {
containerTags: ['user-123']
});
console.log('Manual sync initiated');
```
# Trigger sync for specific container tags
client.connections.import_(
'google-drive',
container_tags=['user-123']
)
print('Manual sync initiated')
```
# Trigger sync for specific container tags
curl -X POST "https://api.supermemory.ai/v3/connections/google-drive/import" \
-H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"containerTags": ["user-123"]
}'
# Response: {"message": "Manual sync initiated", "provider": "google-drive"}
```
Configure your own Google OAuth app using the settings API:
<Tabs> <Tab title="TypeScript"> ```typescript // Update organization settings with your Google OAuth app await client.settings.update({ googleDriveCustomKeyEnabled: true, googleDriveClientId: 'your-google-client-id.googleusercontent.com', googleDriveClientSecret: 'your-google-client-secret' });// Get current settings
const settings = await client.settings.get();
console.log('Google Drive custom key enabled:', settings.googleDriveCustomKeyEnabled);
console.log('Client ID configured:', !!settings.googleDriveClientId);
```
# Get current settings
settings = client.settings.get()
print(f'Google Drive custom key enabled: {settings.google_drive_custom_key_enabled}')
print(f'Client ID configured: {bool(settings.google_drive_client_id)}')
```
# Get current settings
curl -X GET "https://api.supermemory.ai/v3/settings" \
-H "Authorization: Bearer $SUPERMEMORY_API_KEY"
```
Configure filtering using the settings API:
<Tabs> <Tab title="TypeScript"> ```typescript await client.settings.update({ shouldLLMFilter: true, filterPrompt: "Only sync important business documents", includeItems: { // Your include patterns }, excludeItems: { // Your exclude patterns } }); ``` </Tab> <Tab title="Python"> ```python client.settings.update( should_llm_filter=True, filter_prompt="Only sync important business documents", include_items={ # Your include patterns }, exclude_items={ # Your exclude patterns } ) ``` </Tab> <Tab title="cURL"> ```bash # Configure document filtering curl -X PATCH "https://api.supermemory.ai/v3/settings" \ -H "Authorization: Bearer $SUPERMEMORY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "shouldLLMFilter": true, "filterPrompt": "Only sync important business documents", "includeItems": { "patterns": ["*.pdf", "*.docx"], "folders": ["Important Documents", "Projects"] }, "excludeItems": { "patterns": ["*.tmp", "*.backup"], "folders": ["Archive", "Trash"] } }'# Response: {
# "shouldLLMFilter": true,
# "filterPrompt": "Only sync important business documents",
# "includeItems": {...},
# "excludeItems": {...}
# }
```