This article aims to explain some issues and how to resolve them on common tasks when working with SharePoint files in Power Automate such as creating a new file, querying document libraries, and deleting files.
these tasks seem to be easy to implement using the existing actions under the SharePoint category in Power Automate but as soon as we start using them, we face some annoying errors.
Sometime a file needs to be deleted from a SharePoint library but as soon as the flow is executed an error message is shown that the file “is locked for shared use”. I have seen several solutions to resolve this error such as adding a delay for almost one hour before deleting the file or creating a loop to retry the deletion until the lock is removed, but none of the above solutions is practical in my view.
The best solution that has been tested by me and easily resolves the issue is using the SharePoint API with a special header that instructs the SharePoint to ignore the lock. The following screenshot shows the required action and the required API and configuration parameters:


As can be seen in the above screenshot the following header instructs the SharePoint to ignore the file lock:
Prefer: bypass-shared-lock
Please note that the above API, permanently deletes the file and does not send it to the recycle bin of the SharePoint site.