October 13, 2024

File metadata is boring but can be incredibly useful. The SharePoint “Get File Metadata” action enables you to get information like the file’s path, size, and type. For example, you could have a list of files in a folder and, if they fit a category, move or archive them. There are many usages for it, but I want to focus on how the action works and how you can take advantage of it.

Where to find it?

To find it, you can search for the SharePoint “Get file metadata” action or go to the “Standard” tab:

Then go to “Get file metadata.”

It looks like this:

Pro Tip:
Power Automate tends to save the most common actions in the main screen, so check there before going trough the full hierarchy. Also you can use the search to quickly find it.

There’s a similar action, with the same name, for OneDrive for Business, but that’s not the one we’re looking here.

Usage

To use it, first select the SharePoint Site from the list. After that, you have one of two ways to get the file:

  1. Select it from the list of files, or.
  2. Provide the File “File Identifier.” 
Important:
Although the file identifier looks like the file’s path with the special characters encoded, you should not try to create your file paths manually. It would be best if you always got them from other actions.

We get a lot of data back under the following format:

{
    "statusCode": 200,
    "headers": {
        <redacted>
    },
    "body": {
        "ItemId": 86,
        "Id": "%252fShared%2bDocuments%252fAttachment%252fExcel%2bTemplate.xlsx",
        "Name": "Excel Template.xlsx",
        "DisplayName": "Excel Template.xlsx",
        "Path": "/Shared Documents/Attachment/Excel Template.xlsx",
        "LastModified": "2021-09-20T16:09:43Z",
        "Size": 17922,
        "MediaType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        "IsFolder": false,
        "ETag": "\"{BA4DFE3A-10CF-4914-A1AE-3E49D772A641},1\"",
        "FileLocator": "dataset=aHR0cHM6Ly9tYa51ZWx0Z29t1XNja20uc2hhcmVwb2ludC5jb20vc2l0ZXMvVGVzdA==,id=WTI1MmZTaGFyZWQlM3JEb2N1bWVudHMlMjUyZkF0dGFjaG1lbnQlMjUyZkV4a2VsJTJiVhVtcGxhdGU33GxzeA=="
    }
}

I’m showing you this so that you understand that you’ll always get a JSON file regardless of what Power Automate shows you.

As you can see above, you get pretty helpful information like:

  1. The file’s name and path
  2. When was it modified
  3. It’s size
  4. It’s the type and if it’s a folder or not.

Depending on your needs, having this information can be incredibly useful. For example, if you want to list all files in a folder and get their details, the SharePoint “Get File Metadata” action is the one to use.

Limitations

You can only access files inside Document Libraries. So you can’t fetch attachments of items in a list, for example.

Recommendations

Here are some things to keep in mind.

Don’t generate the ID.

I always recommend against generating the ID. Although it’s possible to get the ID by encoding the special characters, it’s pretty error-prone even if you know the path and the “formula” on how to do it. For example, if Microsoft changes something in Power Automate, you’ll get into trouble, but if you use the IDs from other actions, your Flows become future proof to any changes that may occur.

Name it correctly

The name is super important in this case since we’re getting the file by either picking the path or providing its ID. Always name it so that other people can understand what you are using without opening the action and checking the details.

Always add a comment.

Adding a comment will also help to avoid mistakes. Indicate where the path comes from, for example, what type (selected or using a file identifier) and how you’re using this information. Again, it’s essential to enable faster debugging when something goes wrong.

Always deal with errors.

Have your Flow fail graciously and notify someone that something failed. It’s horrible to have failing Flows in Power Automate since they may go unlooked for a while or generate even worse errors. I have a template, and a template that you can use that will help you make your Flow resistant to issues. You can check all details here.

Am I missing something? Leave a comment or interact on Twitter. Let’s work together to make this reference as complete as we can

Back to the Power Automate Action Reference.

Photo by Pontus Wellgraf on Unsplash

Manuel Gomes

I have 18 years of experience in automation, project management, and development. In addition to that, I have been writing for this website for over 3 years now, providing readers with valuable insights and information. I hope my expertise allows me to create compelling, informative content that resonates with the audience.

View all posts by Manuel Gomes →

2 thoughts on “Power Automate: SharePoint – Get File Metadata Action

  1. Hi, Thanks a lot for the article.
    I can not find where to find this feature, you did not mention won which site is this present.
    I am trying to get the metadata of files using a python script, can you suggest something for that?

    1. Hi Utka,
      The idea is to fetch files you already have either on SharePoint or Teams. Then you can check the metadata. Python is also an alternative, but I consider this one a bit easier, depending of course on what you want to do with the information
      Cheers.

Leave a Reply

Your email address will not be published. Required fields are marked *

Mastodon