> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Microsoft Graph

> Mount Outlook mail, OneDrive and SharePoint Online drives, and Teams channels on your app.

## Outlook mail

Mount `@bijectionhq/app-imap` in Graph mode. Use one mailbox directory
object ID and one actual mail folder ID. Bind the receiver and the mount under
the same declared label.

## Mount and start

`mailbox({ data, graph })` returns the app to place at a path of your tree.
Bind the Graph receiver with `graphMailboxReceiver(auth, label)`.

```ts app.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app, label, secret } from "@bijectionhq/bijection";
import mailbox, { graphMailboxReceiver } from "@bijectionhq/app-imap";

const mail = label();
const token = secret();
const graph = graphMailboxReceiver({ kind: "bearer", secret: token }, mail);

export default app({ mail, token, graph, graphMail: mailbox({ data: mail, graph }) });
```

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection secret set token
bijection mutate graphMail.source.initialize '{"profile": {"mode": "graph", "mailbox": "MAILBOX_OBJECT_ID", "folder": "FOLDER_ID"}}'
```

`graphMail.operator` is granted from code: `ctx.grant(graphMail.operator, { to, under })` in one of your
mutations ([Grants](https://docs.bijection.com/access/grants.md)).

The mount's `operator` role clears `data` and is the only role its functions
allow: `graphMail.source.*`, `graphMail.metadata.list`, `graphMail.content.*`.
Give the principal `Mail.Read` access to the selected mailbox and folder. The
receiver also accepts a reviewed `oauth2` credential. This mode uses the global
`graph.microsoft.com` origin.
[Message delta and permissions](https://learn.microsoft.com/en-us/graph/api/message-delta?view=graph-rest-1.0)

## Position and limits

The app asks for immutable IDs on every page. The returned ID keys the
metadata row within this folder. `payload` is JSON text containing the
observed subject, conversation, folder, receipt time, read state and
attachment presence. A partial update changes only fields the answer
states. An explicit `@removed` withdraws the row from the folder, including
when a message moves out of scope. [Immutable Outlook IDs](https://learn.microsoft.com/en-us/graph/outlook-immutable-id)

The initial delta round publishes the folder baseline when its final page
lands. Each subsequent page commits its changes and full continuation
together. The app checks each next or delta link against the same origin,
mailbox and folder. It accepts at most 32 entries per page within the 64 KiB
encoded task result budget and 4,096 characters of retained cursor text.

`source.progress` reports the revision and gap instant. `source.poll`,
`source.pause` and `source.resume` take the current revision. HTTP 410
on a held cursor requires `source.reset` with `revision` and `gapAt`.
The previous folder view stays visible until the replacement baseline
finishes. Page `metadata.list({ cursor })`: it returns `{ facts, next }`, and `next`
is the following call's `cursor`.

A new baseline has one day to finish, including time spent paused. An
expired baseline keeps the previous view. Reset the source and resume it
if it is paused.

## Message Files

The app pins the immutable message ID and `changeKey`, reads MIME through
`$value`, and checks the same identity again before publication. The raw MIME
File and embedded attachment Files are available through `content.get`.
Call `content.requestAttachment` with the message key and a Graph attachment
`id` for a direct `$value` read of a file or item attachment. That read also
checks the parent message before and after staging.

The raw MIME and up to 32 attachment Files share an 8 MiB budget.
Within one permit, the receiver uses 512 KiB HTTP ranges when Graph
returns an exact partial response with a strong ETag. It sends that ETag
with `If-Match` on later ranges and checks Graph's `changeKey` before and
after the read. When the range probe yields a complete answer, the
receiver streams that same body. A partial answer without a usable
validator falls back to one complete download. Publication checks the
whole-body digest and retires the private File parts in the same commit.
A changed version, validator, length or digest refuses the capture. Metadata remains available while content is pending
or refused. `content.retry` requests a fresh raw capture for the same item.
[Graph MIME](https://learn.microsoft.com/en-us/graph/outlook-get-mime-message)
· [Graph attachment reads](https://learn.microsoft.com/en-us/graph/api/attachment-get?view=graph-rest-1.0)

## OneDrive and SharePoint Online

Mount `@bijectionhq/app-rest` using the [REST installation guide](https://docs.bijection.com/integrations/native-rest.md#mount-and-bind).
Use the Graph drive ID of one OneDrive account or SharePoint Online document
library. Teams channel Files are stored in SharePoint document libraries.
Choose the drive for the site that owns those Files.

```ts app.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app, label, secret } from "@bijectionhq/bijection";
import rest, { graphDriveContentReceiver, providerEndpoint } from "@bijectionhq/app-rest";

const files = label();
const token = secret();
const provider = providerEndpoint(
  "microsoft-graph.drive.items.delta",
  "https://graph.microsoft.com",
  "/v1.0/drives/b%21YOUR_DRIVE_ID/root/delta",
  { kind: "bearer", secret: token },
  files,
);

export default app({ files, token, provider, drive: rest({ data: files, receivers: { provider } }) });
```

Use the same drive ID in the receiver and the source profile. Percent-encode
`!` as `%21` in the receiver path and keep it literal in the selection. Pass
the receiver as `receivers.provider` and bind it and the mount under the same
`data` label. Use a sealed bearer or OAuth2 credential with Files read
permission for the chosen drive. Initialize with:

```json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{ "profile": { "mode": "provider", "provider": "microsoft-graph.drive.items.delta", "selection": "b!YOUR_DRIVE_ID", "limit": 25 } }
```

The first walk enumerates the drive and publishes each page as it lands.
The app keys rows by exact drive item ID, keeps the last event within
each page, and withdraws IDs with a `deleted` facet. The next or delta
position stays scoped to the drive and commits with the page. The completed
delta position persists between polls. HTTP 410 stops the source for
`source.reset` at the reviewed revision and gap instant. A replacement walk
keeps prior rows that it does not explicitly withdraw. Each page fits at
most 32 items and 36 KiB of JSON. [Drive delta and permissions](https://learn.microsoft.com/en-us/graph/api/driveitem-delta?view=graph-rest-1.0)

### Capture drive Files

When the published row is a file with an ETag, bind the File reader for the
same drive and pass it as `receivers.graphContent`.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
const graphContent = graphDriveContentReceiver("b!YOUR_DRIVE_ID", "tenant.sharepoint.com", { kind: "bearer", secret: token }, files);
export default app({ files, token, provider, graphContent, drive: rest({ data: files, receivers: { provider, graphContent } }) });
```

Choose the exact HTTPS download hostname reviewed for this installation.
The supported hosts are `onedrive.com` and hostnames under `onedrive.com`,
`files.1drv.com` or `sharepoint.com`. Set the Files credential of the
File receiver. The driver refuses any other redirect authority and
keeps the signed download URL in the driver. The download request has
its own headers and presents no Graph authorization.

The operator calls `drive.files.request` and `drive.files.get`. Request the item `key` to capture the current File. A matching
in-flight or ready request returns the retained state. A refused capture
can be requested again. Read the state, size, Graph version ID and File
reference with `files.get`. The driver checks the observed item ETag and
most recent `driveItemVersion` before and after download. It accepts a
complete response of the checked length or ranges with exact offsets and
a strong validator across multiple ranges. The File limit is 8 MiB and
the mount permits four concurrent captures. A subsequent changed ETag or
item deletion withdraws the captured File.
[Drive item versions](https://learn.microsoft.com/en-us/graph/api/driveitem-list-versions?view=graph-rest-1.0)
· [Drive content](https://learn.microsoft.com/en-us/graph/api/driveitem-get-content?view=graph-rest-1.0)

## Teams channels

Mount `@bijectionhq/app-rest` with `providerEndpoint` and the mode
`microsoft-graph.team.channels.observations`. Bind
`https://graph.microsoft.com` and `/v1.0/teams/<team-id>/channels`. Supply
the same team GUID as `selection`, with `limit: 100`. Use sealed Graph
authorization with read access to the team's channels, and bind the mount
and the receiver under the same `data` label.

Each sweep reads the channels visible to that credential and keys the
metadata by channel ID. The app reuses a continuation only within that
team and restarts when it reaches the last page. Missing channels remain
published. A response must fit 100 rows and 36 KiB. Read channel Files
through their SharePoint drive.
[List channels and permissions](https://learn.microsoft.com/en-us/graph/api/channel-list?view=graph-rest-1.0)

## Write list items

Follow the [native write mount guide](https://docs.bijection.com/integrations/native-rest.md#native-provider-writes). Use mode `microsoft-graph.list-items.create-update-delete` with `providerWriter` and endpoint `https://graph.microsoft.com`, passed in `receivers.writers` under that mode. Use `scope: ["TENANT.sharepoint.com", "SITE_COLLECTION_UUID", "SITE_UUID", "LIST_UUID"]` and seal an OAuth credential authorized to write the installed SharePoint list. Create takes `{ fields: { … } }` and requires HTTP 201 with the new item ID. Update takes a field-value object and accepts the HTTP 200 field-set response for the requested item. Delete accepts HTTP 204 for removal of the exact list item. Use decimal item IDs as text.

The writer records evidence under the mount's label. Commands take up to 24 KiB of JSON and carry no read cursor.

[Provider write API](https://learn.microsoft.com/en-us/graph/api/listitem-create?view=graph-rest-1.0)

## Directory, Planner, To Do, OneNote and Teams messages

Bind one `@bijectionhq/app-rest` mount per collection with
`providerEndpoint` at `https://graph.microsoft.com`. Seal a bearer or
OAuth2 credential with the permissions for the selected API. Bind a
protected `data` label to the receiver and the mount.

Use the mode from the table as `profile.provider`. Put the indicated IDs
in `selection` as literal text, separated by slashes when there is more
than one ID. In the installed path, percent-encode each ID segment
independently. For example, write `%3A` and `%40` in a Teams channel ID
and `%21` in a OneNote ID. The route must match the source selection.

| Mode | Path after `/v1.0` | Selection |
| - | - | - |
| `microsoft-graph.users.observations` | `/users` | Omit |
| `microsoft-graph.groups.observations` | `/groups` | Omit |
| `microsoft-graph.planner.plans.observations` | `/groups/GROUP/planner/plans` | `GROUP` |
| `microsoft-graph.planner.tasks.observations` | `/planner/plans/PLAN/tasks` | `PLAN` |
| `microsoft-graph.todo.lists.observations` | `/users/USER/todo/lists` | `USER` |
| `microsoft-graph.todo.tasks.observations` | `/users/USER/todo/lists/LIST/tasks` | `USER/LIST` |
| `microsoft-graph.onenote.notebooks.observations` | `/users/USER/onenote/notebooks` | `USER` |
| `microsoft-graph.onenote.sections.observations` | `/users/USER/onenote/notebooks/NOTEBOOK/sections` | `USER/NOTEBOOK` |
| `microsoft-graph.onenote.pages.observations` | `/users/USER/onenote/sections/SECTION/pages` | `USER/SECTION` |
| `microsoft-graph.channel.messages.observations` | `/teams/TEAM/channels/CHANNEL/messages` | `TEAM/CHANNEL` |
| `microsoft-graph.channel.replies.observations` | `/teams/TEAM/channels/CHANNEL/messages/MESSAGE/replies` | `TEAM/CHANNEL/MESSAGE` |

Directory, Planner, To Do and OneNote modes accept up to 100 rows per
response. Graph controls the Planner page size. Teams accepts up to 50.
All modes cap inline answers at 36 KiB and publish by provider object ID.
OneNote reads metadata for notebooks, direct sections and pages. HTML
page content requires a separate read outside these modes.

Graph paging positions stay on the exact installed collection. OneNote
uses ordered traversal offsets and advances after a full window even when
Graph omits a next link. These sweeps restart at the end. A Teams message
or reply with `deletedDateTime` withdraws that ID. Missing objects remain
published, including when a credential loses access.

[Planner](https://learn.microsoft.com/en-us/graph/planner-concept-overview) ·
[To Do](https://learn.microsoft.com/en-us/graph/todo-concept-overview) ·
[OneNote](https://learn.microsoft.com/en-us/graph/onenote-get-content) ·
[Teams messages](https://learn.microsoft.com/en-us/graph/api/channel-list-messages?view=graph-rest-1.0)

## OneNote page HTML

Bind a separate protected REST mount with mode
`microsoft-graph.onenote.page.content` and path
`/v1.0/users/USER/onenote/pages/PAGE/content` at `https://graph.microsoft.com`.
Set `selection` to the literal `USER/PAGE` pair and `limit: 1`. Apply
the same path encoding and OneNote read authorization as for page
metadata. The app publishes one UTF-8 HTML record by page ID, up to
36 KiB. Linked assets stay remote. The read carries no cursor, and a
failed read keeps the prior observation.

[OneNote page content](https://learn.microsoft.com/en-us/graph/api/page-get?view=graph-rest-1.0)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.