Skip to main content

Notifications

Community site session details

Community site session details

Session Id : 6/UJhXdxMxPeQNK4YpD1+j
Power Automate - Using Flows
Unanswered

Retrieve versions of SharePoint files and save the version in another library

Like (0) ShareShare
ReportReport
Posted on 26 Feb 2025 19:18:05 by 47
I need to get all the versions of the files in a SharePoint Library for the past 3 years.
 
This flow was working before but since yesterday stopped with a 400 Error.
 
My flow steps are as follows:
 
1) Get all files from the SharePoint Library
2) loop through all the files
3) "Send an HTTP request to SharePoint" to get all the versions with the id of the file with the URI: 
_api/web/lists/getByTitle('Library')/items(864)/Versions
4) Parse JSON and loop through all the versions sending a request to SharePoint again to get the version information with the URI:
_api/web/lists/getByTitle('Library')/items(864)/Versions(101)
5) Make another call "Send and HTTP request to SharePoint' to get the contents of the file with the following URI:
/_api/web/GetFileByServerRelativeUrl('/sites/PnP/<Library>/<file name>.docx')/Versions(101)/$value - the /$value is/was giving me the contents of the file up until yesterday and now it is throwing a 400 error.  Nothing has changed in the flow or in the data.
6) Create a file in OneDrive
7) Copy the file to SharePoint
8) Update the metadata in the SharePoint document with the information from the previous steps.
 
Step 5 is throwing the following error:
{
  "message""Cannot write the value 'null' in raw format.\r\nclientRequestId: b9e851be-0862-4861-ab75-afd062411a89\r\nserviceRequestId: ce5b85a1-9047-0000-8053-9e555aba28ea",
  "status"400,
  "source""https://windsorcommunitieseo.sharepoint.com/sites/PnP/_api/web/GetFileByServerRelativeUrl('/sites/PnP/<library>/<file name>.docx')/Versions(101)/$value",
  "errors": [
    "-1",
    "Microsoft.Data.OData.ODataException"
  ]
}
 
  • David_MA Profile Picture
    9,770 Super User 2025 Season 1 on 14 Mar 2025 at 17:30:35
    Retrieve versions of SharePoint files and save the version in another library
    Based on the new data you show, I think the issue is that the file has not been checked in. The information you provided suggests that the file has never been checked in. Specifically, the VersionLabel of "0.101" indicates that the file is in a draft state and has not been checked in for the first time. In SharePoint, files with a version label starting with "0" are typically those that have been uploaded but not yet checked in (which technically means no version exists yet). Check in the file and see if that resolves your problem.
     
    With ShareGate there is an option to handle this, which will check in files to prevent this issue. As noted by ShareGate:
     
    We recommend checking-in checked-out documents before running a migration since checked out documents will not be migrated (only their last checked-in version will be migrated).
  • MS-03101913-0 Profile Picture
    47 on 14 Mar 2025 at 16:15:07
    Retrieve versions of SharePoint files and save the version in another library
    Hi David MA,
     
    I follow your train of thinking so I looked at a call directly to the file and the version and it is showing it is not null.
     
    "ID": 864,
    "VersionId": 101,
    "VersionLabel": "0.101",
    "File_x005f_x0020_x005f_Size": "3864634",
     
     
    I'm also interest in your thoughts about using ShareGate.  I have a ShareGate license for this client but don't see a way to export previous versions of the documents to another  library.  Can you elaborate on that though?
     
    Mike-
  • David_MA Profile Picture
    9,770 Super User 2025 Season 1 on 26 Feb 2025 at 20:36:05
    Retrieve versions of SharePoint files and save the version in another library
    The $value is the file content? If that is the case, it sounds like you have a file that contains no data (zero-byte file). I have seen this occasionally happen in SharePoint. There is a Microsoft Q&A on this at Does SharePoint Online support storing empty (0-Byte) files? - Microsoft Q&A
     
    I am not sure how you would handle this except to either find the 0-byte files and delete them, or add a parallel branch under the action that fails and set one side of the parallel branch to run on success and the other to run on failure. Maybe someone else will have a better idea. What you are doing I would use ShareGate to accomplish.
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Thomas Rice – Community Spotlight

We are honored to recognize Thomas Rice as our March 2025 Community…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,508 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,431 Most Valuable Professional

Leaderboard

Featured topics

Restore a deleted flow