Jun 21 2022 06:33 AM
Hello,
We are using SharePoint API to develop an integration with SharePoint for our software. We have a problem with getting the version history of files: the token we receive via the API allows to read files, but doesn't allow to access vti history (like https://revizto.sharepoint.com/_vti_history/2048/Shared Documents/Document23.docx). If we login to SharePoint itself via browser for the same user, it allows to see version history there. But via the API we cannot do this.
Did anyone face similar issues?
Thanks!
Jun 21 2022 06:50 AM
Jun 22 2022 02:48 AM
Jun 22 2022 03:04 AM
Solution
I don't know if you are using a Provided or Hosted AddIn, but try this;
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(decodeURIComponent(location.search));
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
}
Not get the stuff
var itemID = getUrlParameter("ID");
var versionID = getUrlParameter("VersionNo");
if(itemID!= "" && versionID!= ""){
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/lists/getbytitle('"+libraryName+"')/Items("+itemID+")/versions("+versionID+")?$select=FileLeafRef,FileRef",
type: "GET",
headers: {
"Accept": "application/json;odata=verbose",
},
success: function (data) {
var versionFileUrl = data.d.FileRef.replace(libraryName,"_vti_history/"+versionID+"/"+libraryName);
},
error: function (data) {
}
});
}
Or CSOM see:
Jun 23 2022 05:26 AM
Jun 22 2022 03:04 AM
Solution
I don't know if you are using a Provided or Hosted AddIn, but try this;
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(decodeURIComponent(location.search));
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
}
Not get the stuff
var itemID = getUrlParameter("ID");
var versionID = getUrlParameter("VersionNo");
if(itemID!= "" && versionID!= ""){
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/lists/getbytitle('"+libraryName+"')/Items("+itemID+")/versions("+versionID+")?$select=FileLeafRef,FileRef",
type: "GET",
headers: {
"Accept": "application/json;odata=verbose",
},
success: function (data) {
var versionFileUrl = data.d.FileRef.replace(libraryName,"_vti_history/"+versionID+"/"+libraryName);
},
error: function (data) {
}
});
}
Or CSOM see: