Forum Discussion
azrevizto
Jun 21, 2022Copper Contributor
Token doesn't allow to access version history of files
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!
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:
4 Replies
Sort By
- Joao LivioIron ContributorWhat is the context? SPFx? SP Addin?
- azreviztoCopper Contributor
- Joao LivioIron Contributor
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: