In this post, let us see how can we get the old files from a SharePoint Folder using Power Automate. In this example, I am considering a simple approach and this can be extended based on the requirement.
To ensure the Power Automate is simple, efficient and the performance is optimized - we are not using ForEach control to loop through and identify old file or item.
We use "Send an HTTP request to SharePoint" in the Power Automate and query the data using OData filters and order by. The idea here for the faster retrieval - selecting only a required set of fields from the file.
Steps to achieve this:
- Login to https:make.powerautomate.com.
- New Cloud Flow -> Scheduled Or Instant (based on the requirement).
(Configure the Start Date and Time. For repeat, every, configure the seconds/ minutes/ hours/ day/ week/ month) - Click on Create Button.
- Click + icon to add new action. Search for SharePoint and select "Send an HTTP request to SharePoint"
- Select the respective SharePoint site from the "Site Address".
- Method: "GET"
- Uri:
If the required files reside inside Shared Document Folder:
/_api/web/GetFolderByServerRelativeUrl('Shared Documents')/Files?$select=Name,TimeCreated,TimeLastModified&$OrderBy=TimeCreated
If the required files reside inside a folder under Shared Document Folder:
/_api/web/GetFolderByServerRelativeUrl('Shared Documents/FolderName')/Files?$select=Name,TimeCreated,TimeLastModified&$OrderBy=TimeCreated
- Headers: { "Accept":"application/json;odata=verbose"}
Now test the flow - the result gives us the list of file in sorting order by CreatedOn.
Comments
Post a Comment