Token doesn't allow to access version history of files

New Contributor



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 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?


4 Replies
What is the context? SPFx? SP Addin?
best response confirmed by azrevizto (New 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(;
    return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));


Not get the stuff


var itemID = getUrlParameter("ID");
    var versionID = getUrlParameter("VersionNo");
    if(itemID!= "" && versionID!= ""){
            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:


New SharePoint CSOM version released for SharePoint Online - September 2017 - Microsoft 365 Develope...


Thanks a lot, your hint lead us to the right answer, which was to use the link of the following type:‘/Shared Documents/Document23.docx’)/Versions/GetById(1024)/$value