I am trying to get the newest item added to a list.
Get item by ID works for single item:
$.ajax({
url: xurl + "/_api/web/lists('" + xlist + "')/items/getById(123)",
type: "GET", headers: { "Accept": "application/json;odata=verbose", },
success: function (data) {
var xid = data.d.ID;
alert(xid);},
error: function (error) { alert(JSON.stringify(error)); }
});
Get top item, doesn't work, it returns undefined
:
$.ajax({
url: xurl + "/_api/web/lists('" + xlist + "')/items?$top=1&$orderby=ID desc",
type: "GET", headers: { "Accept": "application/json;odata=verbose", },
success: function (data) {
var xid = data.d.ID;
alert(xid);},
error: function (error) { alert(JSON.stringify(error)); }
});
Suggestions?