Forum Discussion
How to get current version of a document on Sharepoint?
- DeletedApr 11, 2019
Hey Si_Da ,
Just figured how you can get the Item versions from the URL.
You'll need 2 REST calls.
The first is _api/web/getFileByServerRelativeUrl('{filePath}')/listItemAllFields. This call should give you some important info about the file, including the field "OData__UIVersionString" that I first mentioned, which give you the current file version. If you want to get all versions from there, you can use the field "odata.editLink", which contains the an URL string to the Item containing the file. So you can just append this URL to your site relative URL and add "/versions" to the end. Something like "tenant.sharepoint.com/sites/{sitename}/_api/Web/Lists(listID)/Items({itemID})/versions"
let me know if it helps.
Hey Si_Da ,
Just figured how you can get the Item versions from the URL.
You'll need 2 REST calls.
The first is _api/web/getFileByServerRelativeUrl('{filePath}')/listItemAllFields. This call should give you some important info about the file, including the field "OData__UIVersionString" that I first mentioned, which give you the current file version. If you want to get all versions from there, you can use the field "odata.editLink", which contains the an URL string to the Item containing the file. So you can just append this URL to your site relative URL and add "/versions" to the end. Something like "tenant.sharepoint.com/sites/{sitename}/_api/Web/Lists(listID)/Items({itemID})/versions"
let me know if it helps.
- Si_DaApr 18, 2019Brass Contributor
Deleted- hopefully I'll get to the bottom of it soon or find a workaround. And I still greatly appreciate your help, thank you!
- DeletedApr 18, 2019
Hey Si_Da ,
I have never seen this tool before, so I can't really help you there. But yeah, a C# program to make the request might be the way to go if nothing else works. Wish you luck!
- Si_DaApr 18, 2019Brass Contributor
Deleted yes I tried searching too and found nothing and I've already created a separate post on here but no response, will try StackOverFlow too though, thanks.
I'm running the script through Outsystems v10 integrating with SharePoint online. If I can't get it working I'm considering seeing if I can wrap it in C# and integrate that component into Outsystems just to see if it makes any difference, not that it should of course but not sure what else to try. This is one of the calls I'm using that generates the 403 Forbidden....
https://MyCompany.SharePoint.com/sites/{SiteName}/_api/web/GetFileByServerRelativeUrl('/sites/{SiteName}/Shared%20Documents/{FilenameAndPath}')/versions
- DeletedApr 18, 2019
Hey Si_Da ,
That's really odd. I tried searching for this specific problem and nothing came up. I suggest that you create a new question on this board, maybe StackOverflow too, to get more information.
Also, how is your app running in SPO? Is it a just an embedded script? Can you share your request so I can try it out in my environment?
Regards,
- Si_DaApr 18, 2019Brass Contributor
The app can successfully delete files and overwrite them, check in and out etc. I have also tried checking a file out before reading the version information just in case (as check out is forced before any actions can be carried out on this site) but that didn't work either.
- Si_DaApr 18, 2019Brass Contributor
Ok so I have a REST API that just checks for the existence of a document and it is identical to the one I'm using to get versions except it has '/versions' on the end of it. The one that checks for the existence of a document works fine so I cut and pasted that into a new REST call (including the parameters and how it's called from within the app) and then I added '/versions' on the end and that still generates the 403 Forbidden error. So it seems that there is some restriction with anything relating to versions. Although I don't know why, nor why the app can test the REST calls during design time and work just fine. Very confusing!
- Si_DaApr 18, 2019Brass Contributor
....and also Restore Version is not working either (well at runtime anyway, works fine testing at design time). All other REST APIs using the same parameters from the same app are working fine at runtime.
I have no idea what could be causing the 403 Forbidden for all these version related REST APIs. Although they were all created on the same day but I can't see anything different to any others. I'm going to experiment with some more calls and report back....
- Si_DaApr 17, 2019Brass Contributor
Deleted
I've not added anything to the header and yet it is only these 2 calls that are not working (getting previous versions and getting current version), except of course when testing at design time and then they do work. It's so frustrating as I have no idea what could be causing this as all the permissions will be the same for all the calls.
- DeletedApr 17, 2019
Hey Si_Da ! No worries, hope you're better now.
Back to the problem, so you're able to make the REST calls through testing but not through AJAX? I'd reccommend checking your header just in caso, if that's the scenario.
Regards,
- Si_DaApr 17, 2019Brass Contributor
Deleted
Sorry for the delayed reply (was unwell and then really busy)....
That's great, thank you! I already have a way to get the previous versions but "_api/web/getFileByServerRelativeUrl('{filePath}')/listItemAllFields" works to obtain the current one. :) Very odd to me that Get Versions and Get Major Version don't return the current version but no matter, at least it works now.....
....well kind of! I can do test calls and getting the version works fine. However when I run it through my application, it returns a 403 Forbidden error. What is odd is that all other REST calls from my application to SharePoint are working just fine, it's only the Get Version calls that aren't. I don't suppose you have any idea what could be causing this?