Share via

Graph API we lost some reservation with this code .

admin_365_st 0 Reputation points
2026-03-26T10:07:16.0333333+00:00

Hi, we are working with an other enterprise, and they use he api graph to retreive our calendar of the cars.

But when they run it at 2 different time, some time 1 day or more or less, they lost some appointment.

A event created in some days, is found, but when they run the code later this event is no more in the answer.

Do yu have an idea ?

Here the code :

Voici les requêtes que notre middleware envoie à MS Graph.

  1. Acquisition du token (avant chaque série d'appels)

curl -X POST "https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token" \

-H "Content-Type: application/x-www-form-urlencoded" \

-d "grant_type=client_credentials" \

-d "client_id={client_id}" \

-d "client_secret={client_secret}" \

-d "scope=https://graph.microsoft.com/.default"


  1. POST /process-vehicles — Membres du groupe Azure AD (véhicules)

Appelé en premier par le cron pour peupler la table des véhicules.

curl -X GET "https://graph.microsoft.com/v1.0/groups/{azure_vehicles_group_id}/transitiveMembers" \

-H "Authorization: Bearer {access_token}" \

-H "Content-Type: application/json"


  1. POST /process-reservations — Calendriers des véhicules (1 requête par véhicule, en parallèle)

Pour chaque boîte de ressource listée dans halpades_vehicles.resource_email :

curl -X GET "https://graph.microsoft.com/v1.0/users/{resource_email}/calendarView\

?startDateTime={startDateTime}\

&endDateTime={endDateTime}\

&%24top=50\

&%24orderby=start%2FdateTime" \

-H "Authorization: Bearer {access_token}" \

-H "Prefer: outlook.timezone=\"Europe/Paris\""

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Q&A Assist
    2026-03-26T10:07:39.7766667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The described behavior is consistent with using /calendarView without handling paging and without using delta tokens to track changes over time.

    Key points in the current request:

    GET https://graph.microsoft.com/v1.0/users/{resource_email}/calendarView
      ?startDateTime={startDateTime}
      &endDateTime={endDateTime}
      &$top=50
      &$orderby=start/dateTime
    

    Potential causes of “lost” reservations:

    1. Not paging through all results
      • $top=50 limits the response to at most 50 events per call.
      • If there are more than 50 events in the requested time range, Graph returns an @odata.nextLink URL.
      • If the code does not follow @odata.nextLink until there is no more link, some events will never be read, and which ones are returned can change between runs as the calendar content changes.
    2. Not using delta query for incremental sync
      • /calendarView supports delta queries via /calendarView/delta.
      • Without delta, each run is a fresh snapshot; if the time window, paging, or ordering changes slightly, events that were previously seen may not be re-fetched or may fall outside the window.
      • With delta, the app can:
        • Do an initial full sync of the time range.
        • Store the @odata.deltaLink.
        • On subsequent runs, call the deltaLink to get only changes (new, updated, deleted events) and keep its own database consistent.
    3. Time window and time zone handling
      • The request uses Prefer: outlook.timezone="Europe/Paris", which is correct for local times, but the startDateTime and endDateTime parameters must be consistent across runs.
      • If the cron job changes the window (for example, “next 30 days from now”), events can move out of the window between runs and appear “lost” if the application expects a cumulative list instead of a sliding window.

    Recommended changes:

    1. Implement full paging for /calendarView
      • After the first GET, check for @odata.nextLink in the response.
      • Keep calling the nextLink URL until it is no longer present.
      • Aggregate all events from all pages before updating the reservations table.
    2. Use delta query to keep reservations in sync
      • For each resource mailbox, do an initial sync:
             GET https://graph.microsoft.com/v1.0/users/{resource_email}/calendarView/delta
               ?startDateTime={startDateTime}
               &endDateTime={endDateTime}
        
      • Page through all results (follow @odata.nextLink).
      • At the end, store the @odata.deltaLink.
      • On subsequent runs, call the stored deltaLink instead of a fresh /calendarView URL.
      • Apply the returned changes (added/updated/deleted events) to the local reservations table.
    3. Clarify business logic for the time window
      • If the goal is “all reservations ever made in a given global period,” keep the same fixed startDateTime/endDateTime and use delta to track changes.
      • If the goal is “future reservations only,” ensure the code explicitly removes events that fall before now rather than relying on a sliding /calendarView window without state.

    These changes align with the documented patterns for working with events and synchronizing a calendar view using Microsoft Graph.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.