1
votes

I have a problem synchronizing events from an outlook.live.com calendar using the php library for Microsoft Graph .

When I do delta query to get new events added to the Outlook calendar, instead of returning the new events, I receive the deleted events.

My query:

/beta/users/{userId}/calendars/{CalendarId}=/calendarView/delta?$deltatoken={deltatoken}

Response I got:

array(3) { ["@odata.context"]=> string(60) "https://graph.microsoft.com/beta/$metadata#Collection(event)" ["@odata.deltaLink"]=> string(523) "https://graph.microsoft.com/beta/users/{userid}/calendars/{Calendarid}/calendarView/delta?$deltatoken=VLoBDbMAW0qt42orhN1P_K-qpJgWEpyLQD3OQNZD4Oq1X-2qdILwT6qcenOJ4pg1SIrCY2XWWOEWX909SipAXkdT1f5_HvmIeOV401E2_SRuq37btKNElPw5OcmQh0yE1XvjPNL78Lpmnlg17dJAxyYY-sHWwF9-E0R1DkDtQM27Oc3cpEf7wrstQciCfYJRzRmVgaefdO4fNrsIXEQYIJ5Ui88_-IZA5WtiNffpWME.s-FenjlawGT-DdS6Bzo3MAhc9v1Na9bN8l3Y7YSC9xk" ["value"]=> array(1) { [0]=> array(3) { ["@odata.type"]=> string(22) "#microsoft.graph.event" ["id"]=> string(140) "AQMkADAwATNiZmYAZC1jNGI4LTlkNjctMDACLTAwCgBGAAADufkn5zrCbEu9_NPar0cGNQcAHVeViMrRMU6xEww1vqDblAAAANeIC7oAAAAdV5WIytExTrETDDW_oNuUAAECoeU1AAAA" ["@removed"]=> array(1) { ["reason"]=> string(7) "deleted" } } } }

My code looks like this:

$pdo=new PDO("mysql:host=10.0.2.200;port=3306;dbname=$db", {your username},{your password},array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));
        $query="SELECT * FROM sync_data WHERE id=$id";
        $stmt=$pdo->prepare($query);
        $stmt->execute();
        while($val= $stmt->fetch(PDO::FETCH_ASSOC)){
            if ($val["syncTo"]=='Outlook'){
                $accessToken=new Token\AccessToken(json_decode($val["accessToken"],true));
                $deltaLink=$val["syncToken"];
                $calendarId=$val["calendarId"];
            }
        }
        $graph=new Microsoft\Graph\Graph();
        $graph->setAccessToken($accessToken);
        $response = $graph->createRequest("GET", $deltaLink)
        ->addHeaders(array ("Prefer"=>"outlook.body-content-type='text'"))
        ->execute();
        $response=$response->getBody();
        var_dump($response);

I found out that the id provided in response about removed event is actually the id of created event and O'm capable of pulling the event details with a get request like this:

$url = "/me/calendars/$calendarid/events/AQMkADAwATNiZmYAZC1jNGI4LTlkNjctMDACLTAwCgBGAAADufkn5zrCbEu9_NPar0cGNQcAHVeViMrRMU6xEww1vqDblAAAANeIC7oAAAAdV5WIytExTrETDDW_oNuUAAECoeU1AAAA";
    $response = $graph->createRequest("GET", $url)
    ->addHeaders(array ("Prefer"=>"outlook.body-content-type='text'"))
    ->execute();
    $response=$response->getBody();
1

1 Answers

0
votes

This is by design, delta queries responses contain all the changes. Deleted events should contain a @removed annotation so you can tell which events were deleted and which ones are new/updated.