Parsing OData Select and Expand failed: Could not find a property named 'fields' on type 'microsoft.graph.site'

john john Pter 1,015 Reputation points
2025-04-20T20:36:04.38+00:00

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:-

M6nlxPQp

Also if i pass the site ID instead of the site url, i will get "invalid Request"

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,771 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.