I was trying to use Advanced Query on list items but its throws error ?

Parth Jani 90 Reputation points
2023-07-04T09:23:40.96+00:00

Hello,

I was trying to Use Query filter with Graph SDK v5 (latest ).
was referring this article :
https://learn.microsoft.com/en-us/graph/filter-query-parameter?context=graph%2Fapi%2F1.0&view=graph-rest-1.0&tabs=csharp

Call in the .net c# code looks like

var lists = GraphServiceClient.Sites["siteid"].Lists.GetAsync((x) =>
            {
               
                    x.QueryParameters.Filter = "listProp/template eq 'genericList'";


            }).Result;

i have verified that there are properties ListProp and inside that there is a string property template which has values genericList/ documentLibrary but when i try to query it throws error.

also i have tried linq in filter like

x.QueryParameters.Filter = "items/any(s:s/ContentType.Name eq 'Folder')";

but this too throws error.

can anybody please help !

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,776 questions
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 44,671 Reputation points
    2023-07-05T07:04:53.5166667+00:00

    Hi @Parth Jani

    It is not yet supported to use the $filter query parameter to filter the list attribute, you can only traverse the site list set, and then execute the if conditional statement to filter the result set:

    var graphClient = new GraphServiceClient(requestAdapter);
    
    var result = await graphClient.Sites["{site id}"].Lists.GetAsync();
    
    for (int i = 0; i < result.Value.Count; i++) {
    
        if (result.Value[i].ListProp.Template == "genericList") {
    
            Console.WriteLine(result.Value[i].Id);
    
        }
    
    }
    

    User's image

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. TH-4749-MSFT 3,305 Reputation points
    2023-07-04T15:44:47.8333333+00:00

    Hello,

    Thanks for reaching out. There is no property called listProp. Please refer to article https://learn.microsoft.com/en-us/graph/api/resources/list?view=graph-rest-1.0 for available list of properties for the get lists endpoint. There is a property called 'list' of type 'listinfo' that contains a sub-property Template. You can find more information on the 'list' property here. Additionally, filtering is not supported for the list property. I would suggest client-side filtering after retrieving the lists.

    The any filter can only be used in a collection. The 'list' property is not a collection.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    Thanks.


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.