File extractor - SharePoint Online documentation

  • 30 October 2023
  • 6 replies

Userlevel 2


I was wondering where I can find information about how to set up the permissions for a file extractor reading only files from a few sites in SharePoint, i.e., not giving the extractor access to all sites. I have solved it using the GraphAPI, but this is quite cumbersome, so I was wondering if we have documentation on how this can be set up. I’ll post my solution below for clarity on how I solved the issue:


You will need to create two applications. One that is used in the file extractor and one to give access to the file extractor.

  1. Register the File Extractor App:
    • Go to the Azure Active Directory portal.
    • Click on "Azure Active Directory" then click on "App registrations".
    • Click on "New registration" to register a new app.
  2. Grant API Permissions:
    • Once your app is registered, click on the app's name to go to its dashboard.
    • Click on "API permissions" in the left panel.
    • Click "Add a permission".
    • Choose "Microsoft Graph" and then "Application permissions".
    • Look for the "Sites.Selected" permission and add it.
  3. Admin Consent:
    • For application permissions, an administrator needs to provide consent for the app to have the specified permissions.
    • In the "API permissions" tab, after adding the required permissions, you'll see the "Grant admin consent for [Your Organization]" button. Click it. This will grant the necessary permissions at the tenant level.
  4. Grant Access to the Specific SharePoint Site:
    • Now, even with admin consent, for "Sites.Selected", you still need to specify which sites your app can access.
    • Create new App with Sites.FullControl.All (Application) and Sites.Read.All (Application) permission and a client secret
  5. Give access using the GraphAPI
    • You need to fill in the Id’s and secret of the app you created, as well as the app you need to give access to
    #AAD AppOnly for Graph API
    $aadClientId = "{adminClientId}"
    $aadClientSecret = "{adminClientSecret}"
    $file_extractor_app_id = "{file_extractor_app_id}"
    $file_extractor_app_name = "{file_extractor_app_name}"
    $siteName = "Testsite"

    $scopes =  ""
    $loginURL = "$tenantId/oauth2/v2.0/token"

    $Token = Invoke-RestMethod -Method Post -Uri $loginURL -Body @{grant_type="client_credentials";client_id=$aadClientId;client_secret=$aadClientSecret;scope=$scopes}
    $headers  = @{'Authorization'="$($Token.token_type) $($Token.access_token)"}

    # Define the URI and body
    $uri = "$siteName"
    $response = Invoke-WebRequest -Method Get -Headers $headers -Uri $uri
    $jsonObject = $response.Content | ConvertFrom-Json
    $siteId = $

    # Define the URI and body
    $uri = "$siteId/permissions"
    $body = @"
        "roles": [
        "grantedToIdentities": [
                "application": {
                    "id": "$file_extractor_app_id",
                    "displayName": "$file_extractor_app_name"

    # Perform the POST request using Invoke-WebRequest
    $response = Invoke-WebRequest -Uri $uri -Method POST -Body $body -Headers $headers -ContentType "application/json"

    # Output the HTTP status code

    # If you also want to see the status description:

    # And if you want to see the content (body) of the response:


You should get something like this:

You can now check if the File Extractor App has access by running this script in PowerShell

#AAD AppOnly for Graph API
$aadClientId = "{fileExtractorClientId}"
$aadClientSecret = "{fileExtractorClientSecret}"
$siteName = "Testsite"

$scopes =  ""
$loginURL = "$tenantId/oauth2/v2.0/token"

$body = @{grant_type="client_credentials";client_id=$aadClientId;client_secret=$aadClientSecret;scope=$scopes}

$Token = Invoke-RestMethod -Method Post -Uri $loginURL -Body $body
$headerParams  = @{'Authorization'="$($Token.token_type) $($Token.access_token)"}

#Graph API call to get site
Invoke-WebRequest -Method Get -Headers $headerParams -Uri "$siteName"

The application should now have the correct rights if it was able to return the information about the site. Change the siteName to another site to see that it doesn’t have access to all sites.

  1. Download the file extractor and configure
    Create a .env file that looks like this:

use it with the following config file, add other configs such as extraction pipelines as needed:

# Configuration template for the Cognite File Extractor version 0.1.0
# The config schema supports general interpolation with environment variables.
# To set a config parameter to an environment variable, use the ${ENV_VAR}
# syntax.
# Example: to set the client-password field to the content of the MY_PASSWORD
# environment variable, use
#   client-password: ${MY_PASSWORD}
# For optional parameters, the default values are provided as comments.
# Uncomment them to change their values. For most scenarios the default values
# should not be changed.

# (Optional) Configure logging to standard out (console) and/or file. Level can
  # Logging to console/terminal. Remove or comment out to disable terminal
  # logging
    level: INFO

  # Logging to file. Include to enable file logging
    #level: INFO
    #path: "/path/to/file.log"

    # (Optional) Log retention (in days).
    #retention: 7

# Information about CDF project
  # Read these from environment variables
  project: ${COGNITE_PROJECT}

    # OIDC client ID
    client-id: ${COGNITE_CLIENT_ID}

    # URL to fetch OIDC tokens from
    token-url: ${COGNITE_TOKEN_UTL}

    # Alternatively, you can specify an Azure tenant to generate token-url automatically
    #tenant: azure-tenant-uuid

    # OIDC client secret - either this or certificate is required

    # Uncomment to use a key/certificate pair instead of client secret to authenticate
      # Path to key and certificate
      #path: /path/to/key_and_cert.pem

      # Authority URL (Either this or tenant is required

    # List of OIDC scopes to request
      - ${COGNITE_BASE_URL}/.default

  # Data set to attach uploaded files to. Either use CDF IDs (integers) or
  # user-given external ids (strings)
    #id: 1234
    external-id: ${SP_DATASET_EXTERNAL_ID}

# (Optional) Extractor performance tuning.
  # (Optional) Schedule for triggering runs, ie extractor will run continuously
  # Can be either cron type or an interval. Supported units for intervals are
  # seconds (s), minutes (m), hours (h) and days (d).
  #  type: cron
  #  expression: "*/5 8-16 * * 1-5"

    type: interval
    expression: 10s

  # (Optional) Where to store extraction states (progress) between runs.
  # Required for incremental load to work.
    # Uncomment to use a local json file for state storage

      # (Optional) Save interval (in seconds) for intermediate file saves. A
      # final save will also be made on extractor shutdown.
      #save-interval: 30

    # Uncomment to use a RAW table for state storage
      # RAW database and table to use

      # (Optional) Upload interval (in seconds) for intermediate uploads. A
      # final upload will also be made on extractor shutdown.
      #upload-interval: 30

# Information about files to extract
  # (Optional) A list of extensions to fetch. If included, only files matching
  # these extensions will be uploaded.
  #  - .pdf
  #  - .tiff

  # (Optional) Maximum number of concecutive errors before crashing extractor
  #errors-threshold: 5

  # (Optional) Maximum file size of files before skipping upload. Default: no
  # maximum.
  #max-file-size: 64Mb

  # (Optional) Whether to let a single failure crash the extractor or not
  #fail-fast: false

  # (Optional) Include metadata in file upload
  #with-metadata: false

  # (Optional) CDF Labels to attach to uploaded files
  #  - label1
  #  - label2

  # (Optional) CDF Security Categories to assign to uploaded files
  #  - 123456
  #  - 234567

  # Information about file provider
    # Provider type. Supported types include local, sharepoint_online,
    # gcp_cloud_storage, azure_blob_storage, aws_s3, smb_protocol, ftp and sftp.

  # (Optional) Prefix added to the directory property on files in CDF.
  #directory-prefix: "/my/files"
    type: sharepoint_online

    # User login for Sharepoint server
    client-id: ${SP_CLIENT_ID}
    client-secret: ${SP_CLIENT_SECRET}

    # Azure tenant ID
    tenant-id: ${SP_AZURE_TENANT_ID}

    # Base URL for Sharepoint server
    base-url: ${SP_BASE_URL}

    # Sharepoint site
    site: ${SP_SITE}

    # Document library to fetch from
    document-library: ${SP_DOCUMENT_LIBRARY}

    # (Optional) Whether to traverse into subfolders or not
    #with-subfolders: false
  1. Run the extractor
    • Run the extractor with the config file you just created



Best answer by Dilini Fernando 24 January 2024, 11:44

View original

6 replies

Userlevel 3

Hi @Kristian Gjestad Vangsnes

Thanks a lot for your question, and the information you have shared. We are currently actually working on some documentation regarding the SharePoint extractor. Hopefully that’ll help in answering your question. I’ll let you know when it’s out!



Hi @Kristian Gjestad Vangsnes  

Please check below link and see if it is helpful. 


Hi @Carin Meems 

I am also looking for resources for sharepoint extractor. Thanks for your help :) 


Userlevel 3

Hi @Kristian Gjestad Vangsnes,

As @Rajendra Pasupuleti has noticed, the documentation has been added to Hub. Please use that for your reference. Hope it helps!


Hi @Rajendra Pasupuleti, this is all we have, currently. Is there any specific information you’re looking for? 

Userlevel 2

From my look at the “Configure SharePoint Extractor” page, it gives full access to all the sites. This is as mentioned too broad access in most cases, we simply want to give access to certain sites. If there is a way to do that with the same method, then that is greatly appreciated.

Userlevel 4
Badge +2

Hi @Kristian Gjestad Vangsnes,

Cognite has updated the documentation. Please take a look and let me know if you have more questions.






Userlevel 4
Badge +2

Hi @Kristian Gjestad Vangsnes,

I hope the above helped. As of now, I’m closing this topic. Please feel free to create a new post if you have any questions.

Best regards,