I have a document library in a SharePoint Online site, which holds many PDF files, each with several versions in the history. Is there a way I can easily download all versions of every file?

  • you will have to go for a custom solution like using SSOM
    – Gaurravs
    Commented Jan 20, 2016 at 4:51

1 Answer 1


The solution I eventually found combined the SharePoint REST API, web services (as suggested by this answer) and a cunning Python script. It worked a treat.

I requested a list of files in the library using the REST API endpoint https://example.sharepoint.com/_api/web/getFolderByServerRelativeUrl('/Test Library')/Files, then looped through each result, calling the URL from the property Versions > __deferred > uri. I was then able to loop through the returned file version list, calling the URL from the Url property, which in turn downloaded one version of one file for each iteration of the nested loop. At this point the file can be saved with the version number appended to the file name.

My actual script was a fair bit more complicated than this, since I also wanted to retrieve and save the value from another field, Revision. This required making two SOAP requests per file to https://example.sharepoint.com/_vti_bin/Lists.asmx*; the first for the Version field and the second for the Revision field (since the web services medthod GetVersionCollection can only return one field at a time). I then filtered out the latest version of each file (I already had a copy of these) and all but the latest version for each value of Revision, and saved the files with the Revision value appended instead of the version.

* If you visit this URL in a browser you'll be presented with documentation for each method, with useful examples demonstrating the rather complicated XML required.

  • Can you explain how you did it so that people with the same issue that stumble across this question can know what to do?
    – wjervis
    Commented May 11, 2016 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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