msgraph-sdk-php icon indicating copy to clipboard operation
msgraph-sdk-php copied to clipboard

Bug: No $deltatoken or $skiptoken in DeltaRequestBuilderGetQueryParameters

Open jdelaune opened this issue 1 year ago • 8 comments

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?

jdelaune avatar Apr 09 '24 16:04 jdelaune

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?

dnllromao avatar Apr 10 '24 14:04 dnllromao

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 avatar Apr 11 '24 10:04 jdelaune

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

jdelaune avatar Apr 11 '24 16:04 jdelaune

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.

dnllromao avatar Apr 12 '24 13:04 dnllromao

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 avatar Apr 13 '24 08:04 jdelaune

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

jdelaune avatar Apr 17 '24 09:04 jdelaune

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.

igor-krein avatar May 06 '24 14:05 igor-krein

Ive been able to use the page iterator and retrieve the delta link when getting events via calendar view. When first using it you need to get the delta link from a different spot than when you use it.

try { $requestAdapter = $graphClient->getRequestAdapter();

        if ($deltaLink) {
            $requestInfo = new RequestInformation();
            $requestInfo->httpMethod = HttpMethod::GET;
            $requestInfo->setUri($deltaLink);
        } else {
            $requestConfig = $this->newDeltaRequestConfig($start, $end);

            $requestInfo = $graphClient
                ->users()
                ->byUserId($upn)
                ->calendarView()
                ->delta()
                ->toGetRequestInformation($requestConfig);
        }

        $response = $requestAdapter->sendAsync(
            $requestInfo,
            [EventCollectionResponse::class, 'createFromDiscriminatorValue'],
        )->wait();

        $iterator = new PageIterator($response, $requestAdapter);
        $iterator->iterate(function (MicrosoftEvent $event) use (&$events) {
            $events[] = Event::fromMicrosoft($event);

            return true;
        });

        $calendarView = [
            'events' => $events,
        ];

        // when using the existing delta this will actually be the delta link
        $additionalData = $response->getAdditionalData();

        // in the initial delta query the link we want is in the oDataNextLink
        $deltaLink = $response->getOdataNextLink() ?? null;

        // when importing using the delta the link we want is where it should be
        if ($additionalData['@odata.deltaLink']) {
            $deltaLink = $additionalData['@odata.deltaLink'];
        }

        $calendarView['deltaLink'] = $deltaLink;

        return $calendarView;
    } catch (BadResponseException $e) {
        throw $this->parseBadResponse($e);
    }

marialight707 avatar Apr 14 '25 19:04 marialight707