1

Very new to SharePoint so I am sure this is a newbie question... I did look at the forums. Here is the command I am using:

https://Server/Site/_api/lists/getbytitle('Equipment%20and%20Inventory')/Items(471)/versions

But I get this error:

<m:error><m:code>-1,
Microsoft.SharePoint.Client.ResourceNotFoundException</m:code><m:message 
xml:lang="en-US">Cannot find resource for the request versions.
</m:message></m:error>

I have also tried this:

https://server/site/_layouts/15/versions.aspx?list={7ab286cb-0fc9-4ea7-b17e-2c08a6b9681a}&id=471

Which worked, but this just produces the page as if working on the site interface.. Not something that is easily harvester-able.

How can I get a item history in a format that a script can easily parse?

1

What you're using works for me, but I'm in SharePoint online and you didn't mention a what version of SharePoint you're using. If I do:

$.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + 
        "/_api/web/Lists/getbytitle('JobTitles')/items(1)/versions?$select=Title,VersionLabel",
    async: false,
    headers: {
        'accept': 'application/json;odata=nometadata'
    },
    complete: function(request) {
        console.log("CurrentUser: " + JSON.stringify(request, null, 4));
    },
    error: function(request) {
        console.log(JSON.stringify(request, null, 4));
    }
});

The response JSON I get back looks like:

{
    "value": [
        {
            "Title":"Web Developer",
            "VersionLabel":"2.0"
        },
        {
            "Title":"Application Developer",
            "VersionLabel":"1.0"
        }
    ]
}

So no parsing necessary. Are you sure you have version history turned on for the list (List Settings->Version History, or Library Settings if it's a document library)?

-1

Try using SPServices:

$().SPServices({
  operation: "GetVersionCollection",
  async: false,
  strlistID: "Projects",
  strlistItemID: 1,
  strFieldName: "Description",
  completefunc: function (xData, Status) {
    $(xData.responseText).find("Version").each(function(i) {
      console.log("Name: " + $(this).attr("Description") + " Modified: " + $(this).attr("Modified"));
    });  
  }
});

Sources:

  1. SharePoint 2013 - Get SPListItem versions via REST.
  2. Any Rest API available for Version history of List item fileds?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.