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

# Connect to SharePoint Online

> Configure the Cognite File extractor to connect to SharePoint Online sources.

<Info>
  The configuration is subject to change depending on permissions, restricted access on the SharePoint level, etc.
</Info>

## Register an application

<Steps>
  <Step title="Register the application">
    [Follow the steps to register an application](/cdf/access/entra/guides/register_custom_webapp) that the Cognite File extractor will use to connect to SharePoint Online.
  </Step>

  <Step title="Set up groups (optional)">
    [Set up and create groups](/cdf/integration/guides/extraction/admin_oidc#step-2-create-a-group-in-microsoft-entra-id-and-add-the-registered-app-as-its-member).
  </Step>

  <Step title="Assign API permissions">
    Assign relevant API permissions to use Microsoft Graph API. The example has the minimal setup for the File extractor to read all SharePoint Online sites.

    ```
    Sites.Read.All (Type: Application)
    User.Read (Type: Delegated)
    ```

    <Frame>
      <img src="https://apps-cdn.cogniteapp.com/@cognite/docs-portal-images/1.0.0/images/cdf/integrations/extraction/file_extractor/file_extractor_sharepoint_1.png" alt="App Registration API permissions showing Sites.Read.All and User.Read permissions" />
    </Frame>
  </Step>
</Steps>

## SharePoint app permissions

After creating the App Registration, add its details to the SharePoint administration app registration.

<Steps>
  <Step title="Create SharePoint app permission">
    To create a new SharePoint app permission, go to this URL [https://YOUR-SHAREPOINT-NAME-admin.sharepoint.com/\_layouts/15/AppInv.aspx](https://YOUR-SHAREPOINT-NAME-admin.sharepoint.com/_layouts/15/AppInv.aspx), where `YOUR-SHAREPOINT-NAME` should be changed. Make sure to use your Microsoft 365 admin account.
  </Step>

  <Step title="Enter Application ID">
    Enter your Application (client) ID in the App Id field and select Lookup. You should see the App registration details filled out.

    <Frame>
      <img src="https://apps-cdn.cogniteapp.com/@cognite/docs-portal-images/1.0.0/images/cdf/integrations/extraction/file_extractor/file_extractor_sharepoint_2.png" alt="SharePoint App permission configuration screen with App Id lookup field" />
    </Frame>
  </Step>

  <Step title="Configure App Domain and Redirect URL">
    Enter App Domain and Redirect URL of your App registration. For a local execution of the File extractor, enter the values of a localhost domain:

    ```yaml theme={"languages":{"custom":["/_languages/kuiper.json","../_languages/kuiper.json"]}}
    App Domain: www.localhost.com
    Redirect URL: https://www.localhost.com/default.aspx
    ```
  </Step>

  <Step title="Add Permission Request XML">
    Add the App's Permission Request XML to configure the SharePoint permission level. This may vary from every configuration scenario. The example gives the minimal XML with the `Read` permissions to all SharePoint sites.

    ```xml theme={"languages":{"custom":["/_languages/kuiper.json","../_languages/kuiper.json"]}}
    <AppPermissionRequests AllowAppOnlyPolicy="true">  
       <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" 
        Right="Read" />
    </AppPermissionRequests>
    ```

    <Info>
      The configuration is subject to change depending on permissions, restrict access on the SharePoint level, etc.
    </Info>
  </Step>

  <Step title="Confirm trust">
    Select Create and then confirm that you trust SharePoint.
  </Step>
</Steps>

## Run extractor

Once you register the application and add the SharePoint app permissions, you can extract files from SharePoint Online.

<Steps>
  <Step title="Download the extractor">
    Go to **Data fusion** > **Integrate** > **Extractors** > **Cognite File extractor** > **Download extractor**.
  </Step>

  <Step title="Configure the extractor">
    In the downloaded folder, find and edit the `example-sharepoint.yaml` configuration template by setting the App registration information and the related SharePoint configuration parameters.
  </Step>

  <Step title="Run the extractor">
    Run the extractor. The example has a successful execution log.

    ```
    2023-11-21 09:06:16.564 UTC [INFO    ] ThreadPoolExecutor-0_0 - All files processed. 5 files uploaded
    2023-11-21 09:06:16.564 UTC [INFO    ] ThreadPoolExecutor-0_0 - Job "FileExtractor (trigger: interval[0:00:10], next run at: 2023-11-21 10:06:20 CET)" run successfully
    2023-11-21 09:06:20.207 UTC [INFO    ] ThreadPoolExecutor-0_0 - Running job "FileExtractor (trigger: interval[0:00:10], next run at: 2023-11-21 10:06:30 CET)" (scheduled at 2023-11-21 10:06:20.184848+01:00)

    ```
  </Step>

  <Step title="Verify extraction">
    Check the extracted files in **Data fusion** > **Data explorer**.
  </Step>
</Steps>

## Find the right paths in SharePoint Online

You can configure the File extractor to extract data from various paths in SharePoint Online. It's possible to provide paths to sites, document libraries, folders, and individual files.

### Paths to sites

You can get the paths to sites from the address bar in your browser. Go to your SharePoint Online site, copy the URL from the address bar, and paste it into your configuration.

For example, [https://cogsp.sharepoint.com/sites/MySite](https://cogsp.sharepoint.com/sites/MySite).

<Info>
  URLs with `/teams/` instead of `/sites/` are also valid.
</Info>

### Paths to document libraries

Sites in SharePoint Online can contain one or more document libraries where you store your files. New sites generally have only a document library called `Documents`, but you can create any number of document libraries.

To extract a single document library from a site, you need to find this document library URL.

<Steps>
  <Step title="Navigate to the document library">
    Go to the document library you want to extract.
  </Step>

  <Step title="Copy the URL">
    Copy the beginning of the URL until `/Forms/AllItems.aspx`, for example, [https://cogsp.sharepoint.com/sites/MySite/Shared%20Documents](https://cogsp.sharepoint.com/sites/MySite/Shared%20Documents).
  </Step>
</Steps>

### Paths to files and folders

To find paths to files and folders:

<Steps>
  <Step title="Select the file or folder">
    In SharePoint Online, go to **Documents** and select the file or the folder you want to extract.
  </Step>

  <Step title="Open details">
    Select **More actions** (...) > **Details**.
  </Step>

  <Step title="Copy the direct link">
    Scroll down to **Paths** and select **Copy direct link** to copy the URL to your clipboard, for example, [https://cogsp.sharepoint.com/sites/MySite/Shared%20Documents/my%20folder/test.doc](https://cogsp.sharepoint.com/sites/MySite/Shared%20Documents/my%20folder/test.doc).

    The copied URL matches the document library URL with the file or folder path added.
  </Step>
</Steps>
