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...
- Jun 22, 2022
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:
Joao Livio
Jun 21, 2022Iron Contributor
What is the context? SPFx? SP Addin?
- azreviztoJun 22, 2022Copper Contributor
- Joao LivioJun 22, 2022Iron 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:
- azreviztoJun 23, 2022Copper ContributorThanks a lot, your hint lead us to the right answer, which was to use the link of the following type:
https://revizto.sharepoint.com/_api/web/GetFileByServerRelativeUrl(‘/Shared Documents/Document23.docx’)/Versions/GetById(1024)/$value