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

# SharePoint

> Connect SharePoint sites and OneDrive for Business document libraries to a Mixpeek bucket.

<Note>
  Mixpeek reads document libraries through the Microsoft Graph API. Each file becomes a bucket object.
</Note>

## Overview

SharePoint nests four levels: tenant, site, drive (document library), item. A connection pins the first three, and the sync path selects the folder.

| Field         | Selects                             |
| ------------- | ----------------------------------- |
| `site_id`     | The SharePoint site                 |
| `drive_id`    | A document library inside that site |
| `folder_path` | A folder inside that library        |

## Prerequisites

* An Azure AD application registration.
* Microsoft Graph permissions `Sites.Read.All` and `Files.Read.All`.
* Admin consent, for the client-credentials flow.

## Authentication

Two flows, chosen by the `type` field on `credentials`.

**`client_credentials`** — app-only access with no user in the loop. Use this in production.

| Field           | Required |
| --------------- | -------- |
| `tenant_id`     | Yes      |
| `client_id`     | Yes      |
| `client_secret` | Yes      |

**`delegated`** — acts as a user, limited to that user's permissions. Needs refresh-token upkeep.

| Field           | Required                                |
| --------------- | --------------------------------------- |
| `tenant_id`     | Yes, or `common` for a multi-tenant app |
| `client_id`     | Yes                                     |
| `client_secret` | Yes                                     |
| `refresh_token` | Yes                                     |

<Warning>
  `client_secret` and `refresh_token` are encrypted at rest and never returned in a response.
</Warning>

## Configuration

### Connection-level fields

| Field         | Required | Description                                     |
| ------------- | -------- | ----------------------------------------------- |
| `credentials` | Yes      | One of the two flows above                      |
| `site_id`     | No       | Omit for personal OneDrive                      |
| `drive_id`    | No       | Omit to use the site's default document library |
| `folder_path` | No       | Omit to sync from the drive root                |

### Sync-level fields

| Field                      | Required | Description                                           |
| -------------------------- | -------- | ----------------------------------------------------- |
| `source_path`              | Yes      | For example `/sites/SiteName/Shared Documents/folder` |
| `polling_interval_seconds` | No       | Defaults to `300`                                     |

## Setup

<Steps>
  <Step title="Register the Azure AD application">
    1. Open **Azure Portal → App registrations → New registration**.
    2. Copy the **Application (client) ID** and **Directory (tenant) ID**.
    3. Under **Certificates & secrets**, create a client secret and copy its value.
    4. Under **API permissions**, add `Sites.Read.All` and `Files.Read.All`, then grant admin consent.
  </Step>

  <Step title="Find your site and drive IDs">
    ```bash cURL theme={null}
    curl -H "Authorization: Bearer YOUR_GRAPH_TOKEN" \
      "https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com:/sites/Marketing"

    curl -H "Authorization: Bearer YOUR_GRAPH_TOKEN" \
      "https://graph.microsoft.com/v1.0/sites/SITE_ID/drives"
    ```

    A site ID looks like `contoso.sharepoint.com,guid1,guid2`. A drive ID starts with `b!`.
  </Step>

  <Step title="Create the storage connection">
    <CodeGroup>
      ```python Python theme={null}
      from mixpeek import Mixpeek

      client = Mixpeek(api_key="your-mixpeek-api-key")

      connection = client.organizations.connections.create(
          name="Marketing SharePoint",
          provider_type="sharepoint",
          provider_config={
              "credentials": {
                  "type": "client_credentials",
                  "tenant_id": "your-tenant-id",
                  "client_id": "your-client-id",
                  "client_secret": "your-client-secret",
              },
              "site_id": "contoso.sharepoint.com,guid1,guid2",
              "drive_id": "b!your-drive-id",
              "folder_path": "/Shared Documents/Marketing",
          },
      )
      print(f"Created connection: {connection['connection_id']}")
      ```

      ```javascript JavaScript theme={null}
      import { Mixpeek } from 'mixpeek-sdk'

      const client = new Mixpeek({ apiKey: 'your-mixpeek-api-key' })

      const connection = await client.organizations.connections.create({
        name: 'Marketing SharePoint',
        provider_type: 'sharepoint',
        provider_config: {
          credentials: {
            type: 'client_credentials',
            tenant_id: 'your-tenant-id',
            client_id: 'your-client-id',
            client_secret: 'your-client-secret',
          },
          site_id: 'contoso.sharepoint.com,guid1,guid2',
          drive_id: 'b!your-drive-id',
          folder_path: '/Shared Documents/Marketing',
        },
      })
      console.log('Created connection:', connection.connection_id)
      ```

      ```bash cURL theme={null}
      curl -X POST https://api.mixpeek.com/v1/organizations/connections \
        -H "Authorization: Bearer YOUR_MIXPEEK_API_KEY" \
        -H "Content-Type: application/json" \
        -d '{
          "name": "Marketing SharePoint",
          "provider_type": "sharepoint",
          "provider_config": {
            "credentials": {
              "type": "client_credentials",
              "tenant_id": "your-tenant-id",
              "client_id": "your-client-id",
              "client_secret": "your-client-secret"
            },
            "site_id": "contoso.sharepoint.com,guid1,guid2",
            "drive_id": "b!your-drive-id",
            "folder_path": "/Shared Documents/Marketing"
          }
        }'
      ```
    </CodeGroup>
  </Step>

  <Step title="Browse folders before creating a sync">
    ```bash cURL theme={null}
    curl "https://api.mixpeek.com/v1/organizations/connections/conn_your_connection_id/folders" \
      -H "Authorization: Bearer YOUR_MIXPEEK_API_KEY"
    ```
  </Step>

  <Step title="Create the sync">
    ```bash cURL theme={null}
    curl -X POST https://api.mixpeek.com/v1/buckets/bkt_your_bucket_id/syncs \
      -H "Authorization: Bearer YOUR_MIXPEEK_API_KEY" \
      -H "X-Namespace: ns_your_namespace_id" \
      -H "Content-Type: application/json" \
      -d '{
        "connection_id": "conn_your_connection_id",
        "source_path": "/sites/Marketing/Shared Documents/Campaigns",
        "polling_interval_seconds": 1800
      }'
    ```
  </Step>
</Steps>

## Related

<CardGroup cols={2}>
  <Card title="Google Drive" icon="google-drive" href="/docs/integrations/object-storage/google-drive">
    The same file-library pattern on Google Workspace.
  </Card>

  <Card title="Box" icon="box" href="/docs/integrations/object-storage/box">
    Enterprise content management connector.
  </Card>
</CardGroup>
