Back to Supermemory

OneDrive Connector

apps/docs/connectors/onedrive.mdx

latest11.8 KB
Original Source

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
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
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 -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
  # 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
# 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
# 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
  # 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>