Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph SDK Dotnet 5 (Graph api v5) call to get lists in a sharepoint site not listing all lists #2417

Open
sant2006 opened this issue Apr 8, 2024 · 4 comments

Comments

@sant2006
Copy link

sant2006 commented Apr 8, 2024

I'm using graph api v5 (sdk for dotnet) to get sharepoint lists in a site. As explained in below Microsoft documentation I've used system facet in select query to get the lists. https://learn.microsoft.com/en-us/graph/api/list-list?view=graph-rest-1.0&tabs=csharp . But this is not returning all the lists in the sharepoint site, I get some lists though.

Here is my code

 
var result = await graphClient.Sites[siteId].Lists.GetAsync((requestConfiguration) =>
 {
       requestConfiguration.QueryParameters.Expand = new string[] { "drive" };
       requestConfiguration.QueryParameters.Select = new string[] { "system", "*" };
 });

Above code is returning only 50 lists in the site in the first page of results and a null nextLink . With previous version of graph sdk (v4) same code has returned 66 lists.

Tried another approach which also returning 50 lists.

 //requestInformation.UrlTemplate = requestInfo.UrlTemplate.Insert(requestInfo.UrlTemplate.Length   - 1, ",%24select,%24expand");
 requestInformation.QueryParameters.Add("%24select", "system,*");
 requestInformation.QueryParameters.Add("%24expand", "drive");
 
var result = await GraphServiceClient.RequestAdapter.SendAsync<ListCollectionResponse>(requestInformation, ListCollectionResponse.CreateFromDiscriminatorValue);

I've used the sdk generated url in graph explorer, that also returned only 50 lists. Could anyone help me with this c# code to get all the lists in a site?

Note: With the second approach if I enable the line which is commented, I get an exception "The server returned an unexpected status code and no error factory is registered for this code: 400". This is thrown from at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter as per the stack trace.
Thanks

Client version
5.37, 5.44.

@andrueastman
Copy link
Member

Thanks for raising this @sant2006

Any chance you can share a sample of the code using v4 that returns the correct number of items?

@sant2006
Copy link
Author

sant2006 commented Apr 9, 2024

@andrueastman thanks for responding to my query.
Below is v4 code which returned correct number of lists with/without token and top parameters.

var listsRequest = GraphServiceClient.Sites[siteId].Lists.Request();
listsRequest.QueryOptions.Add(new QueryOption("expand", "drive"));
listsRequest.QueryOptions.Add(new QueryOption("select", "system,*"));
if (!string.IsNullOrEmpty(token))
{
       listsRequest.QueryOptions.Add(new QueryOption(GraphConstants.SkipTokenKey, token));
}
if (pageSize.HasValue)
{
   listsRequest.Top(pageSize.Value);
}
var listsResponse = await listsRequest.GetAsync();

Thanks

@andrueastman
Copy link
Member

Do you get different results if you run these on graph explorer? (Only difference is the $ before select and expand parameters)

https://graph.microsoft.com/v1.0/sites/root/lists?select=system,*&expand=drive

and

https://graph.microsoft.com/v1.0/sites/root/lists?$select=system,*&$expand=drive

@sant2006
Copy link
Author

sant2006 commented Apr 9, 2024

@andrueastman I get different results , first query returns 39 lists and no nextLink, second one returns 23 and no nextLink. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants