onedrive-business-sp

n8n node for Microsoft OneDrive for Business (SharePoint)

Package Information

Downloads: 38 weekly / 959 monthly
Latest Version: 3.0.0
Author: Your Name

Documentation

Microsoft OneDrive (Business) Node for n8n

This is a complete implementation of a Microsoft OneDrive for Business node for n8n, built on SharePoint Document Library with Microsoft Graph API.

🚀 Features

Resources & Operations

File Operations

  • Delete - Remove files from OneDrive
  • Download - Download file content as binary data
  • Get - Retrieve file metadata
  • Rename - Change file names
  • Search - Find files by query
  • Share - Create sharing links with configurable permissions
  • Upload - Upload files from binary data

Folder Operations

  • Create - Create new folders
  • Delete - Remove folders
  • Get Items - List contents of a folder
  • Rename - Change folder names
  • Search - Find folders by query
  • Share - Create sharing links with configurable permissions

Triggers (Webhook-based)

  • On File Created - Triggers when a new file is created
  • On File Updated - Triggers when a file is modified
  • On Folder Created - Triggers when a new folder is created
  • On Folder Updated - Triggers when a folder is modified

📋 Prerequisites

Microsoft Azure App Registration

  1. Go to Azure Portal

  2. Navigate to Azure Active Directory > App registrations > New registration

  3. Configure:

    • Name: n8n OneDrive Business Integration
    • Supported account types: Accounts in any organizational directory
    • Redirect URI: https://your-n8n-instance.com/rest/oauth2-credential/callback
  4. After creation, note down:

    • Application (client) ID
    • Directory (tenant) ID
  5. Go to Certificates & secrets > New client secret

    • Note down the Client secret value (shown only once!)
  6. Go to API permissions > Add a permission > Microsoft Graph > Delegated permissions

    • Add these permissions:
      • Files.ReadWrite.All
      • Sites.Read.All
      • Sites.ReadWrite.All
      • offline_access
    • Click Grant admin consent

🔧 Installation

For n8n Community Nodes

  1. Copy Files to n8n Custom Nodes Directory:
# Navigate to your n8n installation
cd ~/.n8n/custom

# Create directory structure
mkdir -p nodes/MicrosoftOneDriveBusiness
mkdir -p credentials

# Copy credential file
cp credentials/MicrosoftOneDriveBusinessOAuth2Api.credentials.ts ~/.n8n/custom/credentials/

# Copy node files
cp nodes/MicrosoftOneDriveBusiness/* ~/.n8n/custom/nodes/MicrosoftOneDriveBusiness/
  1. Install as Community Node (Alternative):

If published as an npm package:

# In n8n UI: Settings > Community Nodes > Install
# Package name: n8n-nodes-microsoft-onedrive-business

For Development

# Clone repository
git clone <repository-url>
cd n8n-onedrive-business

# Install dependencies
npm install

# Link to n8n
npm link

# In your n8n directory
npm link n8n-nodes-microsoft-onedrive-business

⚙️ Configuration

1. Add Credentials in n8n

  1. Go to Credentials > New > Microsoft OneDrive (Business) OAuth2 API
  2. Enter:
    • Client ID: Your Azure App's Application (client) ID
    • Client Secret: Your Azure App's client secret
  3. Click Connect my account and authorize

2. Get Site ID and Drive ID

To use the node, you need your SharePoint site ID:

Get Site ID:

GET https://graph.microsoft.com/v1.0/sites/{hostname}:/{site-path}

Example:

GET https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com:/sites/TeamSite

Get Drive ID (optional - will auto-fetch if not provided):

GET https://graph.microsoft.com/v1.0/sites/{site-id}/drive

📖 Usage Examples

Example 1: Upload a File

{
  "nodes": [
    {
      "parameters": {
        "resource": "file",
        "operation": "upload",
        "siteId": "contoso.sharepoint.com,abc123,def456",
        "parentFolderId": "root",
        "fileName": "report.pdf",
        "binaryPropertyName": "data"
      },
      "name": "Upload to OneDrive",
      "type": "n8n-nodes-microsoftOneDriveBusiness.microsoftOneDriveBusiness",
      "credentials": {
        "microsoftOneDriveBusinessOAuth2Api": "OneDrive Business Credentials"
      }
    }
  ]
}

Example 2: Search and Download Files

{
  "nodes": [
    {
      "parameters": {
        "resource": "file",
        "operation": "search",
        "siteId": "contoso.sharepoint.com,abc123,def456",
        "query": "quarterly report"
      },
      "name": "Search Files"
    },
    {
      "parameters": {
        "resource": "file",
        "operation": "download",
        "fileId": "={{ $json.id }}",
        "binaryProperty": "data"
      },
      "name": "Download File"
    }
  ]
}

Example 3: Trigger on New Files

{
  "nodes": [
    {
      "parameters": {
        "siteId": "contoso.sharepoint.com,abc123,def456",
        "event": "fileCreated",
        "watchFolderId": "root"
      },
      "name": "OneDrive Trigger",
      "type": "n8n-nodes-microsoftOneDriveBusiness.microsoftOneDriveBusinessTrigger"
    }
  ]
}

🔑 Key Differences from OneDrive Personal

Feature OneDrive Personal OneDrive Business
Backend Consumer OneDrive SharePoint
Drive Type personal business
API Base /me/drive /sites/{id}/drive
Authentication Personal Microsoft Account Azure AD (Work/School)
Organization Features ✅ (Sharing policies, DLP, etc.)

🛠️ API Endpoints Used

  • GET /sites/{site-id}/drive - Get drive information
  • PUT /drives/{drive-id}/items/{parent-id}:/{filename}:/content - Upload file
  • GET /drives/{drive-id}/items/{item-id}/content - Download file
  • GET /drives/{drive-id}/items/{item-id} - Get metadata
  • DELETE /drives/{drive-id}/items/{item-id} - Delete item
  • PATCH /drives/{drive-id}/items/{item-id} - Update item
  • GET /drives/{drive-id}/root/search(q='{query}') - Search
  • POST /drives/{drive-id}/items/{item-id}/createLink - Create sharing link
  • POST /subscriptions - Create webhook subscription (triggers)
  • GET /drives/{drive-id}/root/delta - Get delta changes (triggers)

🐛 Troubleshooting

"Drive not found" error

  • Verify your Site ID is correct
  • Ensure user has access to the SharePoint site
  • Check that the drive exists for the site

"Insufficient privileges" error

  • Verify all required Graph API permissions are granted
  • Ensure admin consent is given for tenant-wide permissions
  • Check that the user has appropriate SharePoint permissions

Webhook/Trigger not working

  • Ensure your n8n instance is publicly accessible
  • Verify the webhook URL is correct
  • Check that subscriptions are being created (they expire after 72 hours)
  • Microsoft Graph webhook delivery can have delays

File upload fails

  • Check file size (large files >4MB need resumable upload session)
  • Verify binary data property name is correct
  • Ensure mime type is set correctly

📚 Resources

📄 License

MIT License - Feel free to use and modify as needed.

🤝 Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

✨ Credits

Built for n8n following official node development guidelines.
Implements OneDrive for Business (SharePoint) only - does not support OneDrive Personal.

Discussion