Is there a way to restore a previous version of a document, using client-side code? I've been looking at the REST API, Lists Web Service, and SPServices JS library, but couldn't find any methods for restoring previous document versions.


You can use the below sample code that uses the restoreByLabel method to restore the previous version of the document.

<script language="javascript" type="text/javascript"
<script language="javascript" type="text/javascript">

$(document).ready(function() {
   SP.SOD.executeFunc('sp.js', 'SP.ClientContext',restoreFile);
var oFile;
function restoreFile() {
 //Get client context and web
clientContext = new SP.ClientContext();
var oWeb = clientContext.get_web();
//Get File object and restore a specific version

//Load Client Context and execute the batch
clientContext.executeQueryAsync(QuerySuccess, QueryFailure);
function QuerySuccess() {
//Get major version
var majorVersion =oFile.get_majorVersion();
   console.log("Version Restored . New Major Version - "+ majorVersion );

function QueryFailure(sender,args) {
   console.log('Request failed - '+args.get_message());

enter image description here


I have never tried this using CSOM, but it seems FileVersionCollection.RestoreByLabel is what you are looking for.


I have not tried this in a SharePoint environment, but in OneDrive there are endpoints to deal with versioning. As OneDrive and SharePoint tend to work with similar REST calls, you might give these a go.

To restore a previous version:

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

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

Get the versions of an item:

GET /sites/{site-id}/items/{item-id}/versions

GET /sites/{site-id}/lists/{list-id}/items/{item-id}/versions

For more details see:


using the REST api in SharePoint,
post to the following endpoint with an empty request body...


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.