aboutsummaryrefslogtreecommitdiff
path: root/apps/docs/connectors/onedrive.mdx
blob: f94495208de18120cf109c1ebafd9a805bf9bd9c (plain) (blame)
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
---
title: "OneDrive Connector"
description: "Sync Microsoft Office documents from OneDrive with scheduled synchronization and business account support"
icon: "microsoft"
---


Connect OneDrive to automatically sync Word documents, Excel spreadsheets, and PowerPoint presentations into your Supermemory knowledge base. Supports both personal and business accounts with scheduled synchronization.

## Quick Setup

### 1. Create OneDrive Connection

<CodeGroup>

```typescript Typescript
import Supermemory from 'supermemory';

const client = new Supermemory({
  apiKey: process.env.SUPERMEMORY_API_KEY!
});

const connection = await client.connections.create('onedrive', {
  redirectUrl: 'https://yourapp.com/auth/onedrive/callback',
  containerTags: ['user-123', 'onedrive-sync'],
  documentLimit: 1500,
  metadata: {
    source: 'onedrive',
    accountType: 'business',
    department: 'marketing'
  }
});

// Redirect user to Microsoft OAuth
window.location.href = connection.authLink;
// Output: Redirects to OAuth provider
// Output: Redirects to https://login.microsoftonline.com/oauth2/authorize?...
```

```python Python
from supermemory import Supermemory
import os

client = Supermemory(api_key=os.environ.get("SUPERMEMORY_API_KEY"))

connection = client.connections.create(
    'onedrive',
    redirect_url='https://yourapp.com/auth/onedrive/callback',
    container_tags=['user-123', 'onedrive-sync'],
    document_limit=1500,
    metadata={
        'source': 'onedrive',
        'accountType': 'business',
        'department': 'marketing'
    }
)

# Redirect user to Microsoft OAuth
print(f'Redirect to: {connection.auth_link}')
# Output: Redirect to: https://oauth.provider.com/...
# Output: Redirect to: https://login.microsoftonline.com/oauth2/authorize?...
```

```bash cURL
curl -X POST "https://api.supermemory.ai/v3/connections/onedrive" \
  -H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "redirectUrl": "https://yourapp.com/auth/onedrive/callback",
    "containerTags": ["user-123", "onedrive-sync"],
    "documentLimit": 1500,
    "metadata": {
      "source": "onedrive",
      "accountType": "business",
      "department": "marketing"
    }
  }'

# Response: {
#   "authLink": "https://login.microsoftonline.com/oauth2/authorize?...",
#   "expiresIn": "1 hour",
#   "id": "conn_od123"
# }
```

</CodeGroup>

### 2. Handle Microsoft OAuth

After user grants permissions, Microsoft redirects to your callback URL. The connection is automatically established and initial sync begins.

### 3. Monitor Sync Status

<CodeGroup>
  ```typescript Typescript
    // Check connection details
    const connection = await client.connections.getByTags('onedrive', {
      containerTags: ['user-123', 'onedrive-sync']
    });


    // List synced Office documents
    const documents = await client.connections.listDocuments('onedrive', {
      containerTags: ['user-123', 'onedrive-sync']
    });
    ```
  ```python Python
    # Check connection details
    connection = client.connections.get_by_tags(
        'onedrive',
        container_tags=['user-123', 'onedrive-sync']
    )

    # List synced Office documents
    documents = client.connections.list_documents(
        'onedrive',
        container_tags=['user-123', 'onedrive-sync']
    )
    ```
  ```bash cURL
    # 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", "onedrive-sync"],
        "provider": "onedrive"
      }'

    # List synced Office 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", "onedrive-sync"],
        "source": "onedrive"
      }'
    ```
</CodeGroup>

## Supported Document Types

### Microsoft Word Documents
- **Rich text formatting** converted to markdown
- **Headers and styles** preserved as markdown hierarchy
- **Images and charts** extracted and referenced
- **Tables** converted to markdown tables

### Excel Spreadsheets
- **Worksheet data** converted to structured markdown
- **Multiple sheets** processed separately
- **Charts and graphs** extracted as images
- **Formulas** converted to calculated values
- **Cell formatting** simplified in markdown

### PowerPoint Presentations
- **Slide content** converted to structured markdown
- **Speaker notes** included when present
- **Images and media** extracted and referenced
- **Embedded objects** processed when possible

## Sync Mechanism

Webhooks lead to real-time syncing of changes in documents. You may also manually trigger a sync.

### Manual Sync Trigger

<CodeGroup>
  ```typescript Typescript
    // Trigger immediate sync for all OneDrive connections
    await client.connections.import('onedrive');

    // Trigger sync for specific user
    await client.connections.import('onedrive', {
      containerTags: ['user-123']
    });

    console.log('Manual sync initiated - documents will update within 5-10 minutes');
    ```
  ```python Python
    # Trigger immediate sync for all OneDrive connections
    client.connections.import_('onedrive')

    # Trigger sync for specific user
    client.connections.import_(
        'onedrive',
        container_tags=['user-123']
    )

    print('Manual sync initiated - documents will update within 5-10 minutes')
    ```
  ```bash cURL
    # Trigger manual sync
    curl -X POST "https://api.supermemory.ai/v3/connections/onedrive/import" \
      -H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"containerTags": ["user-123"]}'
    ```
</CodeGroup>

## Delete Connection

Remove a OneDrive connection when no longer needed:

<CodeGroup>

```typescript Typescript
// Delete by connection ID
const result = await client.connections.delete('connection_id_123');
console.log('Deleted connection:', result.id);

// Delete by provider and container tags
const providerResult = await client.connections.deleteByProvider('onedrive', {
  containerTags: ['user-123']
});
console.log('Deleted OneDrive connection for user');
```

```python Python
# Delete by connection ID
result = client.connections.delete('connection_id_123')
print(f'Deleted connection: {result.id}')

# Delete by provider and container tags
provider_result = client.connections.delete_by_provider(
    'onedrive',
    container_tags=['user-123']
)
print('Deleted OneDrive connection for user')
```

```bash cURL
# Delete by connection ID
curl -X DELETE "https://api.supermemory.ai/v3/connections/connection_id_123" \
  -H "Authorization: Bearer $SUPERMEMORY_API_KEY"

# Delete by provider and container tags
curl -X DELETE "https://api.supermemory.ai/v3/connections/onedrive" \
  -H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"containerTags": ["user-123"]}'
```

</CodeGroup>

<Note>
Deleting a connection will:
- Stop all future syncs from OneDrive
- Remove the OAuth authorization
- Keep existing synced documents in Supermemory (they won't be deleted)
</Note>

## Advanced Configuration

### Custom Microsoft App

For production deployments, configure your own Microsoft application:

<CodeGroup>
  ```typescript Typescript
    // First, update organization settings with your Microsoft app credentials
    await client.settings.update({
      onedriveCustomKeyEnabled: true,
      onedriveClientId: 'your-microsoft-app-id',
      onedriveClientSecret: 'your-microsoft-app-secret'
    });

    // Then create connections using your custom app
    const connection = await client.connections.create('onedrive', {
      redirectUrl: 'https://yourapp.com/callback',
      containerTags: ['org-456', 'user-789'],
      metadata: { customApp: true }
    });
    ```
  ```python Python
    # First, update organization settings with your Microsoft app credentials
    client.settings.update(
        onedrive_custom_key_enabled=True,
        onedrive_client_id='your-microsoft-app-id',
        onedrive_client_secret='your-microsoft-app-secret'
    )

    # Then create connections using your custom app
    connection = client.connections.create(
        'onedrive',
        redirect_url='https://yourapp.com/callback',
        container_tags=['org-456', 'user-789'],
        metadata={'customApp': True}
    )
    ```
  ```bash cURL
    # Update organization settings
    curl -X PATCH "https://api.supermemory.ai/v3/settings" \
      -H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "onedriveCustomKeyEnabled": true,
        "onedriveClientId": "your-microsoft-app-id",
        "onedriveClientSecret": "your-microsoft-app-secret"
      }'
    ```
</CodeGroup>

### Document Filtering

Control which OneDrive documents get synced:

<CodeGroup>
  ```typescript Typescript
    // Configure filtering for Office documents
    await client.settings.update({
      shouldLLMFilter: true,
      includeItems: {
        fileTypes: ['docx', 'xlsx', 'pptx'],
        folderNames: ['Projects', 'Documentation', 'Reports'],
        titlePatterns: ['*Proposal*', '*Specification*', '*Analysis*']
      },
      excludeItems: {
        folderNames: ['Archive', 'Templates', 'Personal'],
        titlePatterns: ['*Draft*', '*Old*', '*Backup*', '*~$*']
      },
      filterPrompt: "Sync professional business documents, project files, reports, and presentations. Skip personal files, drafts, temporary files, and archived content."
    });
    ```
  ```python Python
    # Configure filtering for Office documents
    client.settings.update(
        should_llm_filter=True,
        include_items={
            'fileTypes': ['docx', 'xlsx', 'pptx'],
            'folderNames': ['Projects', 'Documentation', 'Reports'],
            'titlePatterns': ['*Proposal*', '*Specification*', '*Analysis*']
        },
        exclude_items={
            'folderNames': ['Archive', 'Templates', 'Personal'],
            'titlePatterns': ['*Draft*', '*Old*', '*Backup*', '*~$*']
        },
        filter_prompt="Sync professional business documents, project files, reports, and presentations. Skip personal files, drafts, temporary files, and archived content."
    )
    ```
  ```bash cURL
    # Configure filtering for Office documents
    curl -X PATCH "https://api.supermemory.ai/v3/settings" \
      -H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "shouldLLMFilter": true,
        "includeItems": {
          "fileTypes": ["docx", "xlsx", "pptx"],
          "folderNames": ["Projects", "Documentation", "Reports"],
          "titlePatterns": ["*Proposal*", "*Specification*", "*Analysis*"]
        },
        "excludeItems": {
          "folderNames": ["Archive", "Templates", "Personal"],
          "titlePatterns": ["*Draft*", "*Old*", "*Backup*", "*~$*"]
        },
        "filterPrompt": "Sync professional business documents, project files, reports, and presentations. Skip personal files, drafts, temporary files, and archived content."
      }'

    # Response: {
    #   "shouldLLMFilter": true,
    #   "includeItems": {...},
    #   "excludeItems": {...},
    #   "filterPrompt": "..."
    # }
    ```
</CodeGroup>

### Optimization Tips

1. **Set realistic document limits** based on storage and usage
2. **Use targeted filtering** to sync only business-critical documents
3. **Monitor sync health** regularly due to scheduled nature
4. **Trigger manual syncs** when immediate updates are needed
5. **Consider account type** when setting expectations

<Callout type="info">
**OneDrive-Specific Benefits:**
- Supports both personal and business Microsoft accounts
- Processes all major Office document formats
- Preserves document structure and formatting
- Handles large enterprise document collections
</Callout>

<Warning>
**Important Limitations:**
- Large Office documents may take significant time to process
- Complex Excel formulas may not convert perfectly to markdown
- Microsoft API rate limits may slow sync for large accounts
</Warning>