bunker.m365
Available when Bunker uses Microsoft Entra ID sign-in and an admin has turned on Microsoft 365.
const { items } = await bunker.m365.lists.items('https://corp.sharepoint.com/sites/PMO', 'Projects', { top: 200 });const { values } = await bunker.m365.excel.range(fileUrl, 'Budget!A1:F40');const { files } = await bunker.m365.files.list('https://corp.sharepoint.com/sites/HR/Shared Documents/Policies');const manager = await bunker.m365.graph('/me/manager');Methods
Section titled “Methods”| Method | Returns |
|---|---|
lists.items(siteUrl, list, { top }) |
{ items, count }. Each item is the list’s fields plus id. top defaults to 200, at most 5,000. list is the list’s name or ID. lists.get is the same |
excel.range(file, range) |
{ address, sheet, values, text }. file is a sharing link or a OneDrive path. Leave range out for the used range of the first sheet |
files.list(folder) |
{ files }, each with id, name, size, webUrl, modified, modifiedBy, folder, mimeType or childCount. Leave folder out for the viewer’s OneDrive root |
graph(path) |
Microsoft Graph’s own JSON for any allowed path, for example /me/events?$top=5 |
Delegated, viewer-scoped
Section titled “Delegated, viewer-scoped”- Every call runs as the person viewing the app, with their own Microsoft 365 permissions. An app can never show someone a list or file they couldn’t open in SharePoint themselves.
- Read only. Only Graph paths and scopes on the admin’s allowlist work.
- Tokens stay on the server, encrypted. The page never sees them.
- Every Graph call is audited.
Consent
Section titled “Consent”The first call may need the viewer to approve a permission. Bunker handles it: it shows a dialog, opens Microsoft’s consent page, and retries the call when they come back. If they say no, the call throws consent_required. Show a friendly message with a button that tries again.
try { ({ items } = await bunker.m365.lists.items(site, 'Projects'));} catch (err) { if (err.code === 'consent_required') showRetryButton(err.message); else bunker.toast(err.message);}Errors
Section titled “Errors”err.code |
Means |
|---|---|
m365_disabled |
Microsoft 365 isn’t turned on |
m365_not_approved |
The admin approves apps one by one, and this one isn’t approved yet |
scope_not_allowed |
The path needs a scope the admin hasn’t allowed. The message names the scopes |
consent_required |
The viewer didn’t grant the permission |
forbidden |
The viewer has no access to that list or file, or the SharePoint site isn’t on the admin’s list |
not_found |
Wrong list name, file or path |
throttled |
Microsoft 365 is busy. The message says how long to wait |
too_large |
The result is over 8 MB. Ask for fewer items |
Route (under /api/v1/sites/{site}) |
Operation | |
|---|---|---|
| Any allowlisted Graph GET | GET /m365/graph?path= |
m365.graph |
| SharePoint list items | GET /m365/lists/items?siteUrl=&list=&top= |
m365.lists.items |
| Excel range | GET /m365/excel/range?file=&range= |
m365.excel.range |
| Files in a folder | GET /m365/files?folder= |
m365.files |
From a terminal, as yourself:
bunker api m365.lists.items --site project-dashboard \ --siteUrl https://corp.sharepoint.com/sites/PMO --list Projects --top 50