Microsoft graph api to get lists in a sharepoint site not listing all lists

65 Views Asked by At

I'm using graph api v5 (dotnet sdk for dotnet) to get sharepoint lists in a site. As explained below Microsoft documentation I'm using 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.

Below is code I've written

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

This is code is returning only 50 lists in the site in the first page of results and nextLink null. With previous version of graph (v4) same code has returned 66 lists. Tried another approach which also returning 50 lists.

  var requestInformation = GraphServiceClient.Sites[siteId].Lists.ToGetRequestInformation();
  //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 debugged and got the sdk generated url and tried the url in graph explorer, that also returned 50 lists. Could anyone help me with this c# code to get all the lists?

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

1

There are 1 best solutions below

3
user2250152 On

If the URL returns only 50 lists also in the Graph Explorer, it's probably server side issue. Have you tried to use $top query parameter to return let's say 500 lists?

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