SharePoint file operations via Microsoft Graph API
List, download, and upload files from SharePoint sites programmatically using Microsoft Graph API. Designed for AI agents and automation workflows.
- π List files in SharePoint folders and document libraries
- β¬οΈ Download files from SharePoint to local filesystem
- β¬οΈ Upload files to SharePoint (files <4MB)
- π OAuth2 authentication via Azure App Registration
- π― Interactive setup wizard - guided configuration with validation
- π Multi-tenant support - works with any Microsoft 365 tenant
- β Permission validation - checks required Graph API permissions
No dependencies required! Scripts use Node.js built-in https module.
node scripts/setup.jsThe setup wizard will:
- Prompt for Azure App Registration credentials (Tenant ID, Client ID, Client Secret)
- Test authentication
- Validate SharePoint permissions
- Test site access
- Save configuration
# List files in a SharePoint site
node scripts/sharepoint-list-files.js TeamSite
# Download a file
node scripts/sharepoint-download.js TeamSite "document.docx" ./document.docx
# Upload a file
node scripts/sharepoint-upload.js TeamSite ./report.pdf "Shared Documents/report.pdf"Your Azure App Registration needs these Microsoft Graph Application permissions:
Sites.Read.Allβ RequiredFiles.Read.Allβ RequiredSites.ReadWrite.All(optional, for upload)Files.ReadWrite.All(optional, for upload)
- Go to Azure Portal β App Registrations
- Create new registration or use existing
- API Permissions β Add permission β Microsoft Graph β Application permissions
- Add the required permissions listed above
- Grant admin consent (important!)
- Copy Application (client) ID and Directory (tenant) ID
- Certificates & secrets β New client secret β Copy the secret value
Run node scripts/setup.js and enter these values when prompted.
Interactive setup wizard for first-time configuration.
node scripts/setup.jsList files and folders in a SharePoint site.
node scripts/sharepoint-list-files.js <site-name> [folder-path]
# Examples
node scripts/sharepoint-list-files.js TeamSite
node scripts/sharepoint-list-files.js TeamSite "Shared Documents/General"Output: JSON array with file details (name, size, URLs, last modified, type)
Download a file from SharePoint.
node scripts/sharepoint-download.js <site-name> <file-path> [output-path]
# Examples
node scripts/sharepoint-download.js TeamSite "document.docx"
node scripts/sharepoint-download.js TeamSite "General/report.docx" ./downloads/report.docxUpload a file to SharePoint (max 4MB).
node scripts/sharepoint-upload.js <site-name> <local-file> <remote-path>
# Examples
node scripts/sharepoint-upload.js TeamSite ./document.pdf "document.pdf"
node scripts/sharepoint-upload.js TeamSite ./file.txt "General/file.txt"Note: Large file uploads (>4MB) require resumable upload session (not yet implemented).
Credentials are stored in ~/.config/bobby/sharepoint.env:
TEAMS_CLIENT_ID=your-client-id
TEAMS_CLIENT_SECRET=your-client-secret
TEAMS_TENANT_ID=contoso.onmicrosoft.comThe setup wizard creates this file automatically, but you can also edit it manually.
SharePoint site names are the last part of the site URL.
Example: For https://contoso.sharepoint.com/sites/TeamSite, use TeamSite as the site name.
Site names are case-sensitive - use the exact name from the URL.
- π Explore first: Use
sharepoint-list-files.jsto see available files before downloading - π Quote paths: Always quote paths with spaces:
"Shared Documents/General" - π Library names: Default library is often
Shared Documents(English) or localized in your tenant language - π Root folder: Use empty string
""or omit the folder parameter for root β οΈ Case sensitive: File and folder names are case-sensitive
Error: "code": "accessDenied"
Solution: Your Azure App Registration is missing SharePoint permissions. Add Sites.Read.All and Files.Read.All, then grant admin consent.
Error: "error": "Site not found"
Possible causes:
- Site name is case-sensitive (check exact name in URL)
- Site does not exist
- Site is not accessible to the app
Error: Token request failed
Solution:
- Verify Client ID and Client Secret are correct
- Check Tenant ID format (e.g.,
contoso.onmicrosoft.com) - Ensure client secret hasn't expired in Azure Portal
- π€ AI Agent workflows - Download documents for processing, upload generated reports
- π Automation - Sync files between systems, backup documents
- π Integration - Connect SharePoint with other tools and platforms
- π Document management - Programmatic access to SharePoint libraries
SharePoint Skill
βββ scripts/
β βββ setup.js # Interactive setup wizard
β βββ sharepoint-auth.js # OAuth2 token generation
β βββ sharepoint-list-files.js
β βββ sharepoint-download.js
β βββ sharepoint-upload.js
β βββ get-tenant.js # Tenant helper (loads from config)
βββ SKILL.md # Full documentation
All scripts use Node.js with built-in https module - no external HTTP libraries needed.
Contributions welcome! Open issues or pull requests on GitHub.
MIT License - See LICENSE file for details.
Created by CloudWerk GmbH for AI agent workflows.