My Digital Garden

Power Automate - Read files from SharePoint directory

Power Automate - Read files from SharePoint directory

Overview

  1. get the file properties
  2. iterate over the files
  3. read the content
  4. take action with the content

Get file properties

To find only files in a directory, use the SharePoint Get files (properties only) action with the FilterQuery set to FSObjType eq 0:

In code view:

{
    "inputs": {
        "host": {
            "connectionName": "shared_sharepointonline",
            "operationId": "GetFileItems",
            "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline"
        },
        "parameters": {
            "dataset": "OBFUSCATED",
            "table": "OBFUSCATED",
            "folderPath": "@outputs('Compose_full_folder_path')",
            "viewScopeOption": "Default",
            "$filter": "FSObjType eq 0",
            "view": "OBFUSCATED"
        },
        "authentication": {
            "type": "Raw",
            "value": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"
        }
    },
    "metadata": {
        "operationMetadataId": "41ec4337-2e5a-49b1-9f06-0eb152ddf4ad"
    }
}

Iterate over files and read content

The Apply to each action is applied to the following data: outputs('Get_files_(properties_only)')?['body/value']

The code view of the Get file content action looks like this:

{
    "inputs": {
        "host": {
            "connectionName": "shared_sharepointonline",
            "operationId": "GetFileContent",
            "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline"
        },
        "parameters": {
            "dataset": "OBFUSCATED",
            "id": "@items('Apply_to_each')?['{Identifier}']",
            "inferContentType": true
        },
        "authentication": {
            "type": "Raw",
            "value": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"
        }
    },
    "metadata": {
        "operationMetadataId": "6dcd37b2-92e6-4496-9621-c0f3a7c9f179"
    }
}

See also