Parsing OData Select and Expand failed: Could not find a property named 'fields' on type 'microsoft.graph.site'
I have this code inside my azure function which uses .NET core 8 and which we enabled its managed identity to access Graph api as per the scripts on this link @ https://learn.microsoft.com/en-us/sharepoint/dev/apis/webhooks/sharepoint-webhooks-using-azd-template#grant-the-function-app-access-to-sharepoint-online:-. to get all the items inside a SharePoint list which was modified since 7 days..
Where when i am inside the Development environment, I need to login using a browser, while on production we need to use the azure function's managed identity:-
if (Environment.GetEnvironmentVariable("AZURE_FUNCTIONS_ENVIRONMENT") == "Development")
{
var credential = new InteractiveBrowserCredential(); // or AzureCliCredential
graphClient = new GraphServiceClient(credential);
}
else
{
var credential = new DefaultAzureCredential(); // Managed Identity
graphClient = new GraphServiceClient(credential);
}
and here the code, to get the items which is failing:-
var sitePath = "https://****.sharepoint.com/sites/analytic";
var listId = "6****6";
var allItems = new List<ListItem>();
var oneWeekAgo = DateTime.UtcNow.AddDays(-7).ToString("o");
// Initial page request with Expand = fields
var page = await graphClient
.Sites[sitePath]
.Lists[listId]
.Items
.GetAsync(config =>
{
config.QueryParameters.Filter = $"lastModifiedDateTime ge {oneWeekAgo}";
config.QueryParameters.Top = 100;
config.QueryParameters.Expand = new string[]
{ "fields($select=*)" };
});
allItems.AddRange(page?.Value ?? []);
// Paging loop — DO NOT reapply query parameters here
while (!string.IsNullOrEmpty(page?.OdataNextLink))
{
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
URI = new Uri(page.OdataNextLink)
};
page = await graphClient.RequestAdapter
.SendAsync(requestInfo, ListItemCollectionResponse.CreateFromDiscriminatorValue);
allItems.AddRange(page?.Value ?? []);
}
var calllogs = ParseCallTransferHistoryLogFromRestResponse(allItems);
But i am getting this error:-
Parsing OData Select and Expand failed: Could not find a property named 'fields' on type 'microsoft.graph.site'.
any advice?
I am using those packages:-
Also if i pass the site ID instead of the site url, i will get "invalid Request"