REST API Item Versions Endpoint
-
30-01-2021 - |
Domanda
In this question, it appears there is a "/versions" endpoint for the ListItems REST API.
/_api/lists/getbytitle('ListName')/Items(#)/versions
returns a 404 'Not Found' on our SharePoint 2016 On-Premise server.
Is there a Cumulative Update or Feature Pack that introduces this endpoint?
Soluzione
This API only supports in SharePoint Online, not for on-premises. So, it does not work in SharePoint 2016.
If you want to get version information, you can try to use the SharePoint List web service that exposes Lists.GetVersionCollection Method to return version information for an item in a SharePoint list.
Here is a code demo to retrieve a list item version, it works.
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>
<script type="text/javascript">
$(function(){
$().SPServices({
operation: "GetVersionCollection",
async: false,
strlistID: "Lists_1",
strlistItemID: 1,
strFieldName: "Title",
completefunc: function (xData, Status) {
console.log(xData);
$(xData.responseText).find("Version").each(function(i) {
console.log("Name: " + $(this).attr("Title") + " Modified: " + $(this).attr("Modified"));
});
}
});
});
</script>
Refer to my answer in this thread.
Here is a demo to get item field version history from Versions.aspx:
Altri suggerimenti
This will work:
https://{site_url}/_api/web/GetFileByServerRelativeUrl('/sites/siteName/Lists/listName/{itemID}_.000')/Versions