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

# SharePoint and OneDrive (Microsoft Graph)

> Client-mode REST API connector for a curated Microsoft Graph SharePoint/OneDrive slice: upload file content, create list items, list drive children, and large-file upload sessions

Technical Preview

## Overview

A client-mode connector for a **curated storage** slice of [Microsoft Graph OneDrive / SharePoint](https://learn.microsoft.com/en-us/graph/api/resources/onedrive) under `https://graph.microsoft.com/v1.0`:

| Catalog connector event | Entity / path | Notes |
| - | - | - |
| PUT drives/\{id}/root:/\{path}:/content | `PUT /drives/{drive-id}/root:/{item-path}:/content` | Small file upload/replace (≤ \~250 MB) — Bearer Entra token |
| POST sites/\{id}/lists/\{id}/items | `POST /sites/{site-id}/lists/{list-id}/items` | Create list item (device register) — Bearer |
| GET drives/\{id}/root/children | `GET /drives/{drive-id}/root/children` | List children under drive root — Bearer |
| (supporting) createUploadSession | `POST /drives/{drive-id}/root:/{item-path}:/createUploadSession` | Large files — returns `uploadUrl` on another host |
| (supporting) GET by path | `GET /drives/{drive-id}/root:/{item-path}:` | driveItem metadata |
| (supporting) PUT upload chunk | `PUT {upload_path}` | **Host:** uploadUrl origin — no Authorization |

Default `BASE_ADDRESS` is `https://graph.microsoft.com/v1.0` (no trailing slash). Topics use `storage/sharepoint-and-onedrive/<object>/<verb>`.

See the base guide: [REST API Connectors](/latest/lot-language/routes/rest-api-routes).

> [!NOTE]
>
> **Path encoding:** `item_path` is the path under the drive root **without** a leading slash (e.g. `FolderA/telemetry.csv`). URL-encode path segments in the publisher if they contain spaces or reserved characters. LoT ENDPOINT uses `/drives/{value.json.drive_id}/root:/{value.json.item_path}:/content`.

> [!NOTE]
>
> **Large upload sessions:** `createUploadSession` returns an `uploadUrl` that is **not** on `graph.microsoft.com`. When calling `Putuploadchunk`, set connector `BASE_ADDRESS` to that URL's origin (scheme + host + port) and put path + query in `upload_path`. Do not send a Graph `Authorization` header — the session URL embeds auth. Same pattern as Teams Workflows webhooks and S3 presigned PUT.

> [!NOTE]
>
> Prefer Hub secrets for Entra access tokens (`GET SECRET "GRAPH_ACCESS_TOKEN"` or `"SHAREPOINT_GRAPH_TOKEN"`). Typical scopes: `Files.ReadWrite.All`, `Sites.ReadWrite.All`, and `offline_access` for refresh. This template has not been verified against a live Microsoft 365 tenant. Status remains blocked until an authenticated live smoke succeeds.

## Basic Syntax

```lot wrap theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
# Coreflux REST_API template — SharePoint and OneDrive (Microsoft Graph)
# Auth: Bearer {value.json.access_token}
# BASE_ADDRESS: https://graph.microsoft.com/v1.0
# Putuploadchunk: set BASE_ADDRESS to uploadUrl origin

DEFINE ROUTE SharepointAndOnedriveRestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://graph.microsoft.com/v1.0"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '60'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT Putdriveitemcontent
        WITH SOURCE_TOPIC "storage/sharepoint-and-onedrive/drive-item/put-content"
        WITH DESTINATION_TOPIC "storage/sharepoint-and-onedrive/drive-item/put-content/response"
        WITH METHOD "PUT"
        WITH ENDPOINT "/drives/{value.json.drive_id}/root:/{value.json.item_path}:/content"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "{value.json.content_type}"
            ADD "Authorization" "Bearer {value.json.access_token}"
        WITH BODY "{payload}"
    ADD EVENT Postlistitem
        WITH SOURCE_TOPIC "storage/sharepoint-and-onedrive/list-item/create"
        WITH DESTINATION_TOPIC "storage/sharepoint-and-onedrive/list-item/create/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/sites/{value.json.site_id}/lists/{value.json.list_id}/items"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
        WITH BODY "{payload}"
    ADD EVENT Listdrivechildren
        WITH SOURCE_TOPIC "storage/sharepoint-and-onedrive/drive-children/list"
        WITH DESTINATION_TOPIC "storage/sharepoint-and-onedrive/drive-children/list/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/drives/{value.json.drive_id}/root/children"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
    ADD EVENT Createuploadsession
        WITH SOURCE_TOPIC "storage/sharepoint-and-onedrive/drive-item/create-upload-session"
        WITH DESTINATION_TOPIC "storage/sharepoint-and-onedrive/drive-item/create-upload-session/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/drives/{value.json.drive_id}/root:/{value.json.item_path}:/createUploadSession"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
        WITH BODY "{payload}"
    ADD EVENT Getdriveitembypath
        WITH SOURCE_TOPIC "storage/sharepoint-and-onedrive/drive-item/get-by-path"
        WITH DESTINATION_TOPIC "storage/sharepoint-and-onedrive/drive-item/get-by-path/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/drives/{value.json.drive_id}/root:/{value.json.item_path}:"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
    ADD EVENT Putuploadchunk
        WITH SOURCE_TOPIC "storage/sharepoint-and-onedrive/upload-session/put-chunk"
        WITH DESTINATION_TOPIC "storage/sharepoint-and-onedrive/upload-session/put-chunk/response"
        WITH METHOD "PUT"
        WITH ENDPOINT "{value.json.upload_path}"
        WITH HEADERS
            ADD "Content-Type" "application/octet-stream"
            ADD "Content-Length" "{value.json.content_length}"
            ADD "Content-Range" "{value.json.content_range}"
        WITH BODY "{payload}"
```

## Auth

1. **Graph events:** pass Entra ID `access_token` on each MQTT payload → `Authorization: Bearer {value.json.access_token}`. Prefer Hub secrets / `GET SECRET "GRAPH_ACCESS_TOKEN"` or `"SHAREPOINT_GRAPH_TOKEN"`. Never commit real tokens.
2. **Scopes:** `Files.ReadWrite.All` (drive content), `Sites.ReadWrite.All` (list items), `offline_access` (refresh). Application (client credentials) or delegated depending on your Entra app registration.
3. **Upload chunk:** no Authorization header. Split `uploadUrl` into origin → `BASE_ADDRESS` and path+query → `upload_path`. Send `Content-Range` / `Content-Length` as placeholders.

## MQTT topics

| Event | Source topic | Response topic |
| - | - | - |
| Putdriveitemcontent | `storage/sharepoint-and-onedrive/drive-item/put-content` | `…/response` |
| Postlistitem | `storage/sharepoint-and-onedrive/list-item/create` | `…/response` |
| Listdrivechildren | `storage/sharepoint-and-onedrive/drive-children/list` | `…/response` |
| Createuploadsession | `storage/sharepoint-and-onedrive/drive-item/create-upload-session` | `…/response` |
| Getdriveitembypath | `storage/sharepoint-and-onedrive/drive-item/get-by-path` | `…/response` |
| Putuploadchunk | `storage/sharepoint-and-onedrive/upload-session/put-chunk` | `…/response` |

## Example payloads

**List drive children** (`BASE_ADDRESS` = `https://graph.microsoft.com/v1.0`):

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "access_token": "YOUR_ENTRA_ACCESS_TOKEN",
  "drive_id": "b!xxxxxxxx"
}
```

**Upload small file content:**

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "access_token": "YOUR_ENTRA_ACCESS_TOKEN",
  "drive_id": "b!xxxxxxxx",
  "item_path": "IIoT/snapshots/line-1.csv",
  "content_type": "text/csv"
}
```

Publish the file bytes (or text) as the MQTT payload body that `{payload}` forwards. Ensure `content_type` matches the body. Path/header placeholders come from `value.json.*`.

**Create list item (device register):**

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "access_token": "YOUR_ENTRA_ACCESS_TOKEN",
  "site_id": "contoso.sharepoint.com,guid,guid",
  "list_id": "LIST_GUID",
  "fields": {
    "Title": "device-42",
    "Status": "online"
  }
}
```

**Create upload session (large file):**

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "access_token": "YOUR_ENTRA_ACCESS_TOKEN",
  "drive_id": "b!xxxxxxxx",
  "item_path": "IIoT/archives/big.bin",
  "item": {
    "@microsoft.graph.conflictBehavior": "replace"
  }
}
```

Then `Putuploadchunk` with `BASE_ADDRESS` = uploadUrl origin:

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "upload_path": "/upn/…?guid=…",
  "content_length": "1048576",
  "content_range": "bytes 0-1048575/5242880"
}
```

## Sources

* [https://learn.microsoft.com/en-us/graph/api/driveitem-put-content](https://learn.microsoft.com/en-us/graph/api/driveitem-put-content)
* [https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession](https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession)
* [https://learn.microsoft.com/en-us/graph/api/driveitem-list-children](https://learn.microsoft.com/en-us/graph/api/driveitem-list-children)
* [https://learn.microsoft.com/en-us/graph/api/listitem-create](https://learn.microsoft.com/en-us/graph/api/listitem-create)
* [https://learn.microsoft.com/en-us/graph/api/driveitem-get](https://learn.microsoft.com/en-us/graph/api/driveitem-get)
* [https://learn.microsoft.com/en-us/graph/api/resources/onedrive](https://learn.microsoft.com/en-us/graph/api/resources/onedrive)
* [https://learn.microsoft.com/en-us/graph/api/resources/sharepoint](https://learn.microsoft.com/en-us/graph/api/resources/sharepoint)
* [https://learn.microsoft.com/en-us/connectors/sharepointonline/](https://learn.microsoft.com/en-us/connectors/sharepointonline/)

## Related

* [REST API Connectors](/latest/lot-language/routes/rest-api-routes)
* [Amazon S3](/latest/lot-language/routes/rest-api-apps/amazon-s3)
* [Azure Blob Storage and Data Lake Gen2](/latest/lot-language/routes/rest-api-apps/azure-blob-storage-and-data-lake-gen2)
* [MinIO](/latest/lot-language/routes/rest-api-apps/minio)


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