Problem Statement
Recently, we encountered an issue where a team member mistakenly updated 599 records without any backup in our SharePoint list database. Restoring the previous versions of this data is crucial and needs to be done as soon as possible.
Solution
To address this, I developed a Power Automate flow to revert the data to its previous state. restore a version of an item in a SharePoint Online list using a Power Automate flow.
1 . Set Up the Manual Trigger
Create Manually triggers a flow.
2. Get Items
The “Get Items” action retrieves data from our SharePoint site, allowing us to access the necessary records for processing. For testing purposes, in the Filter Query field, I use the following OData query: “ID le 5” for testing purposes. This query will filter the items to only include those where the ID is less than or equal to 5.
We require the SharePoint object information below to proceed further.
- site-id
- list-id
- item-id
- Version-Label
Finding your SharePoint Site ID can be done in several ways. I prefer the easiest one.
Get the site from the Site URL
- Navigate to your SharePoint site.
- Add /_api/site/id at the end of the URL.
- Press Enter, and you'll see the Site ID in the response.
- Site ID value within the <d:Id> tags.
Get list-id
Got to your list setting. You will find it on the URL.
List=%7Bcd8ca4f1-0d08-430b-8150-c573d4da8024%8C
The rest of the item-id & version-id, which you can find with SharePoint UI, is not the hardest task. Now use this id in the initialize variable.
3. Initialize Variable
Use the site-id as Value & Data type String. Do the same for rest list-id, item-id, and Version-Label.
4. Configure HTTP Action
This setup will use the site-id, list-id, item-id, and version-id when you manually trigger the flow. Then, these values are used to restore the specified version of the SharePoint list item.
item-id will be dynamic from the Get Items Action.
version-id, in our case, required “1.0”
URI
_api/v2.0/sites/@{variables('SiteId')}/lists/@{variables('ListId')}/items/@{variables('ItemId')}/versions/@{variables('VersionLabel')}/restoreVersion
Headers
{
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose"
}
Conclusion
You will see the version history in the snapshot below. Using this Power Automate workflow, we restored the list item to version 1.0 and created a new version 3.0.
Thanks for reading.
Happy coding
Resources: Restore a previous version of a SharePoint list item - OneDrive dev center | Microsoft Learn