5

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?

3

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

2
2

Solution for SharePoint 2013 REST API:

https://{site_url}/_api/web/GetFileByServerRelativeUrl('/sites/siteName/Lists/listName/{itemID}_.000')/Versions
5
  • For some reason I'm getting empty XML tags. For example <author><name></name></author>
    – Paul Vu
    May 27 '20 at 18:57
  • What is your item's URL? How many versions this item has? May 29 '20 at 5:16
  • 1
    The URL is site + "_api/web/GetFileByServerRelativeUrl('/ajm/ajm-25/Mobile-Dev/Lists/Announcements_list/379_.000')/Versions" and there is only two versions.
    – Paul Vu
    May 29 '20 at 12:09
  • What do you get without the /Versions at the end? May 29 '20 at 12:39
  • It gives me the data for everything else except for the ones I actually need which are the title, author, the actual comment.
    – Paul Vu
    May 29 '20 at 15:23
-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.