Restore data from SharePoint version history with PowerAutomate

Restore data from SharePoint version history with PowerAutomate

In this article, we will learn how to use Power Automate and Version History API to restore a document in SharePoint or other cloud storage services. Power Automate is a service that allows you to create automated workflows between different applications and services. Version History API is a RESTful web service that allows you to get and restore the versions of a document in SharePoint or other cloud storage services.

Step 1

Create a flow that triggers when a document is modified or deleted in SharePoint or other cloud storage services. To do this, follow these steps:

  • ?From Power Automate, click on Automated Cloud Flow.
  • Click on Create.
  • Give your flow a name and choose When an item is created or modified as the trigger. Select your site and list name where the document is stored.
  • Click on Create.


Step 2

Add an action to get the version history of the document using the Version History API. To do this, follow these steps:

  • Click on Add an action from the previous step.
  • Search for and select HTTP as the connector type.
  • Enter a name for your action, such as GetVersionHistory.
  • In the Method field, select GET.
  • In the Uri field, enter

/_api/web/versions/{versionId} where {versionId}         

  • is the version ID of the document. You can find this value in the response of the previous step under VersionId property.
  • In the Headers section, add two key-value pairs: X-HTTP-Method with value MERGE, and X-RequestDigest with value

$(concat('d41d8cd98f00b204e9800998ecf8427e', base64Encode_sha1(triggerBody()?['{versionId}'])))        


Step 3

Add an action to restore a specific version of the document using the Version History API. To do this, follow these steps:

  • Click on Add an action from the previous step.
  • Search for and select HTTP as the connector type.
  • Enter a name for your action, such as RestoreVersion.
  • In the Method field, select POST.
  • In the Uri field, enter

/_api/web/versions/{versionId}/restore        

  • where {versionId} is the same value as in step 2 under {versionId} property. You can also add some query parameters if needed, such as {siteUrl}, {listName}, {itemId}, etc.
  • In the Headers, add two key-value pairs: X-HTTP-Method with value MERGE, and X-RequestDigest with value

$(concat('d41d8cd98f00b204e9800998ecf8427e', base64Encode_sha1(triggerBody()?['{versionId}'])))        


Step 4

Add an action to update the document with the restored version using SharePoint or OneDrive actions. To do this, follow these steps:

  • Click on Add an action from any of the previous steps (except for HTTP actions).
  • Search for and select either SharePoint or OneDrive connector depending on where your document is stored (SharePoint for lists or libraries, OneDrive for files).
  • Enter a name for your action, such as UpdateDocument or UpdateFile respectively.
  • In the Site Address or Folder Path field, enter the same value as in step 2 under Site Address property (for SharePoint) or Folder Path property (for OneDrive).
  • In the List Name or File Name field, enter the same value as in step 2 under List Name property (for SharePoint) or File Name property (for OneDrive).
  • In the Item ID or File ID field, enter the same value as in step 2 under Item ID property (for SharePoint) or File ID property (for OneDrive).

Step 5

Test your flow and verify that it restores the document to its previous version successfully.


Further Links

You can find some examples of how to use Power Automate and Version History API for restoring documents in SharePoint or other cloud storage services in these link:

Restore a previous version of a ListItem

https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/listitemversion_restore?view=odsp-graph-online

POST /sites/{site-id}/items/{item-id}/versions/{version-id}/restoreVersion
POST /sites/{site-id}/lists/{list-id}/items/{item-id}/versions/{version-id}/restoreVersion        

?

要查看或添加评论,请登录

Marcel Broschk的更多文章

社区洞察

其他会员也浏览了