microsoftgraph / msgraph-sdk-php

Microsoft Graph Library for PHP.
Other
568 stars 144 forks source link

Bug: No $deltatoken or $skiptoken in DeltaRequestBuilderGetQueryParameters #1503

Open jdelaune opened 5 months ago

jdelaune commented 5 months ago

Hi we are upgrading to v2 and I can't see how to use the $deltatoken and $skiptoken when making a request to https://graph.microsoft.com/v1.0/me/calendarView/delta.

I'm trying to use \Microsoft\Graph\Generated\Users\Item\CalendarView\Delta\DeltaRequestBuilderGetRequestConfiguration but they aren't given as options.

Should I be constructing the request in a different way?

dnllromao commented 5 months ago

Same issue. Class Microsoft\Graph\Generated\Groups\Delta\DeltaRequestBuilderGetQueryParameters doesn't have the properties skiptoken or deltatoken. How can I request the second page of results when the requested results are paginated?

jdelaune commented 5 months ago

I have combed all the source files and can't find references to the delta or skip tokens. So the question is, is this an oversight in the v2 SDK? Intentional? Coming Soon?

Would be good to know as it is blocking our upgrade to the v2 SDK.

jdelaune commented 5 months ago

Okay so I found this: https://learn.microsoft.com/en-us/graph/delta-query-events?tabs=php

This is the example code they provide:

<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Users\Item\CalendarView\Delta\DeltaRequestBuilderGetRequestConfiguration;

$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);

$requestConfiguration = new DeltaRequestBuilderGetRequestConfiguration();
$headers = [
        'Prefer' => 'odata.maxpagesize=2',
    ];
$requestConfiguration->headers = $headers;

$queryParameters = DeltaRequestBuilderGetRequestConfiguration::createQueryParameters();
$queryParameters->deltatoken = "R0usmcMDNGg0J1E";
$requestConfiguration->queryParameters = $queryParameters;

$result = $graphServiceClient->me()->calendarView()->delta()->get($requestConfiguration)->wait();

However in reality it doesn't exist:

Screenshot 2024-04-11 at 17 11 54

So I would say this is a bug in the SDK

dnllromao commented 5 months ago

Concerning the skiptoken, I found out on the package code examples a class PageIterator that can be used to go through the multiple pages of a collection. Hoping this can help.

jdelaune commented 5 months ago

Thanks. The skip count has a different usage to the skip token and the delta token. They are needed for getting just the delta changes from when you last asked for changes. We use the paginator and skip count for paging but it doesn't help here.

jdelaune commented 5 months ago

Bug still present in 2.5.0 https://github.com/microsoftgraph/msgraph-sdk-php/blob/dev/src/Generated/Users/Item/CalendarView/Delta/DeltaRequestBuilderGetQueryParameters.php

igor-krein commented 4 months ago

Actually, deltatoken here is a URL that contains everyting we need to run a delta request, so I am not sure there is a sense to support it in cfg/parameters.

Something like this should work (I took a working code of mine and rewrote it accordingly to the example above, so there is a possibility I missed something):

<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Users\Item\CalendarView\Delta\DeltaRequestBuilder;

// ...

// pass previously stored '@odata.deltaLink' value in $deltaLink

$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);

$requestAdapter = $graphServiceClient->getRequestAdapter();

if ($deltaLink) {
    // we have a deltaLink from a previous request, create a request builder from this URL
    $request = new DeltaRequestBuilder($deltaLink, $requestAdapter);
} else {
    // first request to get all the data (and a deltaLink for future use)
    $request = $graphServiceClient->me()->calendarView()->delta();
}

$result = $request->get()->wait();

// ...

// new deltaLink for the next request
$deltaLink = $result->getOdataDeltaLink();

Note: For those who use PageIterator, there is another problem: for some reason, it doesn't support deltaLink yet (as of v2.7.0). I had to use my own iterator that gets '@odata.deltaLink' value from the last request. I just hope this will be fixed in the future.