-
Notifications
You must be signed in to change notification settings - Fork 252
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
Paging in Microsoft.Graph.DirectoryObjects.GetByIds #2483
Comments
Thanks for raising this @ssteiner I believe it may be possible to use the pageIterator to collect all the items as below. var collectedItems = new List<DirectoryObject>();
var pageIterator = PageIterator<DirectoryObject, Microsoft.Graph.DirectoryObjects.GetByIds.GetByIdsPostResponse>.CreatePageIterator(graphClient, items, (item) => { collectedItems.Add(item); return true; });
await pageIterator.IterateAsync(); alternatively, you can use the var nextRequest = graphServiceClient.DirectoryObjects.GetByIds.WithUrl(items.OdataNextLink).ToPostRequestInformation(new Microsoft.Graph.DirectoryObjects.GetByIds.GetByIdsPostRequestBody
{
});
nextRequest.HttpMethod = Microsoft.Kiota.Abstractions.Method.GET;
var nextItems = await graphServiceClient.RequestAdapter.SendAsync(req, Microsoft.Graph.DirectoryObjects.GetByIds.GetByIdsPostResponse.CreateFromDiscriminatorValue); |
This exception will occur when you request more than 1000 IDs.
It appears to me that there is no built-in pagination. var payload = new Microsoft.Graph.DirectoryObjects.GetByIds.GetByIdsPostRequestBody
{
Ids = ids.Take(1001).ToList(),
Types = objectTypes
};
var req = graphServiceClient.DirectoryObjects.GetByIds.ToPostRequestInformation(payload);
if (attributeList != null)
req.URI = new Uri($"{req.URI}?$select={string.Join(",", attributeList.Select(o => o.FirstCharToLower()))}");
var items = await graphServiceClient.RequestAdapter.SendAsync(req, Microsoft.Graph.DirectoryObjects.GetByIds.GetByIdsPostResponse.CreateFromDiscriminatorValue); |
I suspect the API may have a limit as to many Ids can be passed as a parameter. Any chance you can share the error if you pass the errorMapiing parameter as below? var errorMapping = new Dictionary<string, ParsableFactory<IParsable>>
{
{ "XXX", ODataError.CreateFromDiscriminatorValue}
};
var items = await graphServiceClient.RequestAdapter.SendAsync(req, Microsoft.Graph.DirectoryObjects.GetByIds.GetByIdsPostResponse.CreateFromDiscriminatorValue, errorMapping); |
Here is the result -> Number of included identifiers cannot exceed '1000' Exception in GetDirectoryObjects: Number of included identifiers cannot exceed '1000'. at at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.ThrowIfFailedResponse(HttpResponseMessage response, Dictionary So it has no paging, I'm wrong? |
I believe what this means is that you can't pass more than 1000 items at a time as a parameter. However, if the response has a nextLink you can page through it as suggested above.
|
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. |
We're adapting our V5 code to remove the use of obsolete classes/methods. One of the things flagged was our way of getting a list of directory objects. I'm wondering - if this is my first request
and
items.OdataNextLink
is not null, what would be the correct API call to get the next page?I've not found any method on
GetByIdsPostRequestBody
that would take a url.The text was updated successfully, but these errors were encountered: