web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Use REST API to Retrie...
Power Automate
Answered

Use REST API to Retrieve All Versions of a SharePoint Online Document Only Return One Version (Latest one)

(0) ShareShare
ReportReport
Posted on by 112

Hi Community,

 

I've done a thorough dig via the forum here and via google, but after I exhausted all the methods that I could try, I am hoping someone can provide some insights here.

 

This should have been straightforward, or so I thought.  I want to use Power Automate to retrieve a SharePoint Online document's all versions.  First of all, I want to stress that using the following code return empty eg

"body": {
"d": {

"result": []

 

_api/web/getFileByServerRelativeUrl('RelativeLink')/versions

 

Therefore, I ended up using two REST API calls:

 

1st is to get properties via this:

 

_api/web/getFileByServerRelativeUrl('RelativeLink')/listItemAllFields

 

Capture.PNG

 

From the result of this call, I composed the List GUID and Item ID, then I used these to send the 2nd call which I finally got the results of version (not empty).

Capture1.PNG

 

Now the only problem is, the result only contains the most current version.  Meaning observing the whole output from this call, there is only one (current) version data are there, where IsCurrentVersion: true.  I just couldn't figure out why.  Any suggestions are much appreciated.

 

Many thanks!

 

 

Categories:
I have the same question (0)
  • lbendlin Profile Picture
    8,649 Super User 2026 Season 1 on at

    You seem to be mixing up terminology. There are different calls for documents and for lists.

     

    lbendlin_0-1713735299482.png

     

  • sc0rpiongirl Profile Picture
    112 on at

    Thanks for the reply.  Perhaps I should provide a bit more context to clarify, that it's not my intention to "mix up" document library and lists (which I can assure you that I am aware of), but rather my attempt to find a workaround to get the results.

     

    First of all, the flow is being triggered from Power App.  When user clicks a button, it will set the "RelatieveLink" in the Power App as input for the flow to run.  As mentioned in my post, using the "straightforward" call with the RelativeLink yielded empty results i.e. 

     

    _api/web/getFileByServerRelativeUrl('RelativeLink')/versions

     

    which prompted me to try using listItemAllFields to see if I can get any results, and I did.  In the Output of that call, within "__metadata", I noticed that there is a Versions uri as seen below:

    Capture.PNG

     

    So I wanted to test using this uri to see if it would produce results of versions (since using the relativeLink method earlier returned empty result).  That's why I extracted the List GUID and the itme ID from this uri that came out from the listItemAllFields call, and attempted to get Versions this way:

     

    _api/Web/Lists(guid'@{outputs('Compose_List_ID')}')/Items(@{outputs('Compose_Item_ID')})/Versions

     

    This returned output with results of current version (well, at least no longer empty) but my end goal is to get all versions.  Hence my hope of anyone has other suggestions that I could try...

     

     

  • lbendlin Profile Picture
    8,649 Super User 2026 Season 1 on at

    Please try the API call version I posted. It works for me.

  • sc0rpiongirl Profile Picture
    112 on at

    Thanks for this...I already tried that one...and it returned 404 even though the parameters appeared to be correct...I have the feeling that my company's SP online document library somehow is different from "traditional" set up 😞

  • sc0rpiongirl Profile Picture
    112 on at

    Just want to add to this and close the topic.

     

    I tried a few different ways to attempt getting the versions, and by going to Sharepoint site where the folder resides, right clicking a document > select Version History, then right click on the most recent version url > Copy link, using that link to parse a "relative Link" inside Power App, which is being passed to the automate flow as input parameter, it managed to retrieve all versions with this code.

     

    _api/web/getFileByServerRelativeUrl('RelativeLink')/versions

     

    What puzzled me is, although this works for some documents, it failed (and returned error code 404 i.e. the file does not exist in the flow) for other documents.  I am not sure if anyone has encountered similar issues, and could shed some light on that.  Thanks!

  • Verified answer
    sc0rpiongirl Profile Picture
    112 on at

    Just want to report back I got it worked out with 2 flows as my original post mentioned, the only "problem" my original flow didn't work (only produced latest version information) was because the document link I used.  After testing, using the link of the document form Version History instead of "Get a link" worked.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 592

#2
Valantis Profile Picture

Valantis 340

#3
11manish Profile Picture

11manish 284

Last 30 days Overall leaderboard