I'm currently developing API rest that retrieves a list of documents created with a template in a Sharepoint site. I'm using the MS Graph SDK. I'm able to retrieve the list of items, but I'm not able to limit the list to the last 3 o 5 items added. I have been through the documentation, but still getting no changes. This is the code in GraphHelper class:
// <MakeGraphCallSnippet>
public async Task<List<Dictionary<string, object>>> GetSiteItems()
{
// Ensure Graph has been initialized
InitializeGraphForAppOnlyAuth();
// Ensure client isn't null
_ = _appClient ??
throw new System.NullReferenceException("Graph has not been initialized for app-only auth");
var listId = "xxxxxxxx";
var itemsResponse = await _appClient.Sites["xxxxxx"]
.Lists[listId]
.Items
.GetAsync((requestConfiguration) =>
{
// set order by desc
requestConfiguration.QueryParameters.Orderby = new string[] { "createdDateTime desc" };
// set number of items to retrieve
requestConfiguration.QueryParameters.Top = 3;
// set selected fields to retrieve
requestConfiguration.QueryParameters.Expand = new string[] { "fields($select=Title,Description,Class,Class_x003a__x0020_ID_x0020_Class,StartDate,EndDate)" };
});
//var items = itemsResponse.Value;
var items = itemsResponse.Value.ToList();
var result = new List<Dictionary<string, object>>();
foreach (var item in items)
{
var itemData = new Dictionary<string, object>();
if (item.Fields?.AdditionalData != null)
{
var fields = item.Fields.AdditionalData;
if (fields.TryGetValue("Title", out var title))
itemData["Title"] = title;
if (fields.TryGetValue("Description", out var description))
itemData["Description"] = description;
if (fields.TryGetValue("Class", out var classValue))
itemData["Class"] = classValue;
if (fields.TryGetValue("Class_x003a__x0020_ID_x0020_Class", out var classId))
itemData["Class_x003a__x0020_ID_x0020_Class"] = classId;
//if (fields.TryGetValue("DateandTime", out var dateAndTime))
// itemData["Date and Time"] = dateAndTime;
if (fields.TryGetValue("StartDate", out var startDate))
itemData["Start Date"] = startDate;
if (fields.TryGetValue("EndDate", out var endDate))
itemData["End Date"] = endDate;
// Retrieve and add the unique ID
if (item.Id != null)
itemData["ID"] = item.Id;
result.Add(itemData);
}
}
return result;
}
// </MakeGraphCallSnippet
Any help apreciated.
Thanks