1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
|
---
title: "Google Drive Connector"
description: "Connect Google Drive to sync documents into your Supermemory knowledge base"
icon: "google-drive"
---
Connect Google Drive to sync documents into your Supermemory knowledge base with OAuth authentication and custom app support.
## Quick Setup
### 1. Create Google Drive Connection
<Tabs>
<Tab title="TypeScript">
```typescript
import Supermemory from 'supermemory';
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);
```
</Tab>
<Tab title="Python">
```python
from supermemory import Supermemory
import os
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}')
```
</Tab>
<Tab title="cURL">
```bash
curl -X POST "https://api.supermemory.ai/v3/connections/google-drive" \
-H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"redirectUrl": "https://yourapp.com/auth/google-drive/callback",
"containerTags": ["user-123", "gdrive-sync"],
"documentLimit": 3000,
"metadata": {
"source": "google-drive",
"department": "engineering"
}
}'
```
</Tab>
</Tabs>
### 2. Handle OAuth Callback
After user grants permissions, Google redirects to your callback URL. The connection is automatically established.
### 3. Check Connection Status
<Tabs>
<Tab title="TypeScript">
```typescript
// Get connection details
const connection = await client.connections.getByTags('google-drive', {
containerTags: ['user-123', 'gdrive-sync']
});
```
</Tab>
<Tab title="Python">
```python
# Get connection details
connection = client.connections.get_by_tags(
'google-drive',
container_tags=['user-123', 'gdrive-sync']
)
# List synced documents
documents = client.connections.list_documents(
'google-drive',
container_tags=['user-123', 'gdrive-sync']
)
```
</Tab>
<Tab title="cURL">
```bash
# Get connections by provider and tags
curl -X POST "https://api.supermemory.ai/v3/connections/list" \
-H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"containerTags": ["user-123", "gdrive-sync"],
"provider": "google-drive"
}'
# 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"
}'
```
</Tab>
</Tabs>
## Supported Document Types
Based on the API type definitions, Google Drive documents are identified with these types:
- `google_doc` - Google Docs
- `google_slide` - Google Slides
- `google_sheet` - Google Sheets
## Connection Management
### List All Connections
<Tabs>
<Tab title="TypeScript">
```typescript
// List all connections for specific container tags
const connections = await client.connections.list({
containerTags: ['user-123']
});
connections.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('---');
});
```
</Tab>
<Tab title="Python">
```python
# List all connections for specific container tags
connections = client.connections.list(
container_tags=['user-123']
)
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('---')
```
</Tab>
<Tab title="cURL">
```bash
# List all connections for specific container tags
curl -X POST "https://api.supermemory.ai/v3/connections/list" \
-H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"containerTags": ["user-123"]
}'
# Response example:
# [
# {
# "id": "conn_gd123",
# "provider": "google-drive",
# "email": "[email protected]",
# "createdAt": "2024-01-15T10:30:00.000Z",
# "documentLimit": 3000
# }
# ]
```
</Tab>
</Tabs>
### Delete Connection
<Tabs>
<Tab title="TypeScript">
```typescript
// Delete by connection ID
const result = await client.connections.deleteByID('connection_id_123');
console.log('Deleted connection:', result.id);
// Delete by provider and container tags
const providerResult = await client.connections.deleteByProvider('google-drive', {
containerTags: ['user-123']
});
console.log('Deleted provider connection:', providerResult.id);
```
</Tab>
<Tab title="Python">
```python
# Delete by connection ID
result = client.connections.delete_by_id('connection_id_123')
print(f'Deleted connection: {result.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}')
```
</Tab>
<Tab title="cURL">
```bash
# Delete by connection ID
curl -X DELETE "https://api.supermemory.ai/v3/connections/connection_id_123" \
-H "Authorization: Bearer $SUPERMEMORY_API_KEY"
# 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"}
```
</Tab>
</Tabs>
<Note>
Deleting a connection will:
- Stop all future syncs from Google Drive
- Remove the OAuth authorization
- Keep existing synced documents in Supermemory (they won't be deleted)
</Note>
### Manual Sync
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');
```
</Tab>
<Tab title="Python">
```python
# Trigger sync for Google Drive connections
client.connections.import_('google-drive')
# Trigger sync for specific container tags
client.connections.import_(
'google-drive',
container_tags=['user-123']
)
print('Manual sync initiated')
```
</Tab>
<Tab title="cURL">
```bash
# Trigger sync for all Google Drive connections
curl -X POST "https://api.supermemory.ai/v3/connections/google-drive/import" \
-H "Authorization: Bearer $SUPERMEMORY_API_KEY"
# 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"}
```
</Tab>
</Tabs>
## Advanced Configuration
### Custom OAuth Application
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);
```
</Tab>
<Tab title="Python">
```python
# Update organization settings with your Google OAuth app
client.settings.update(
google_drive_custom_key_enabled=True,
google_drive_client_id='your-google-client-id.googleusercontent.com',
google_drive_client_secret='your-google-client-secret'
)
# 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)}')
```
</Tab>
<Tab title="cURL">
```bash
# Update organization settings
curl -X PATCH "https://api.supermemory.ai/v3/settings" \
-H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"googleDriveCustomKeyEnabled": true,
"googleDriveClientId": "your-google-client-id.googleusercontent.com",
"googleDriveClientSecret": "your-google-client-secret"
}'
# Get current settings
curl -X GET "https://api.supermemory.ai/v3/settings" \
-H "Authorization: Bearer $SUPERMEMORY_API_KEY"
```
</Tab>
</Tabs>
### Document Filtering
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": {...}
# }
```
</Tab>
</Tabs>
<Warning>
**Important Notes:**
- OAuth tokens may expire - check `expiresAt` field
- Document processing happens asynchronously
- Use container tags consistently for filtering
- Monitor document status for failed syncs
</Warning>
|