Sample code for 30+ languages & platforms
Unicode C++

MS Graph Calendar List Events

See more Microsoft Calendar Examples

Retrieve a list of events in a calendar. The list contains single instance meetings and series masters.

For more details, see https://docs.microsoft.com/en-us/graph/api/calendar-list-events?view=graph-rest-1.0

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkHttpW.h>
#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    bool success = false;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttpW http;

    // Use your previously obtained access token as shown here:
    //    Get Microsoft Graph OAuth2 Access Token with Calendars.ReadWrite scope.

    CkJsonObjectW jsonToken;
    success = jsonToken.LoadFile(L"qa_data/tokens/msGraphCalendar.json");
    if (success == false) {
        wprintf(L"%s\n",jsonToken.lastErrorText());
        return;
    }

    http.put_AuthToken(jsonToken.stringOf(L"access_token"));

    // Specify the calendar id
    http.SetUrlVar(L"id",L"AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAClEpRTgAAAA==");
    // Send a GET request to https://graph.microsoft.com/v1.0/me/calendars/{$id}/events
    const wchar_t *strResponse = http.quickGetStr(L"https://graph.microsoft.com/v1.0/me/calendars/{$id}/events");
    if (http.get_LastMethodSuccess() == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    CkJsonObjectW json;
    json.Load(strResponse);
    json.put_EmitCompact(false);

    if (http.get_LastStatus() != 200) {
        wprintf(L"%s\n",json.emit());
        wprintf(L"Failed, response status code = %d\n",http.get_LastStatus());
        return;
    }

    wprintf(L"%s\n",json.emit());

    // Sample output:
    // (See parsing code below..)

    // {
    //   "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('admin%40chilkat.io')/calendars('AQMkADAwATM0MDAAMS1i ... AClEpRTgAAAA%3D%3D')/events",
    //   "value": [
    //     {
    //       "@odata.etag": "W/\"5+vF7TKKdE6bGCRqXyl2PQAClIgmmw==\"",
    //       "id": "AQMkADAwATM0MDAAM ... AApRZ7JkAAAA=",
    //       "createdDateTime": "2019-04-26T14:31:39.8791929Z",
    //       "lastModifiedDateTime": "2019-04-26T14:31:41.2753537Z",
    //       "changeKey": "5+vF7TKKdE6bGCRqXyl2PQAClIgmmw==",
    //       "categories": [
    //       ],
    //       "originalStartTimeZone": "Pacific Standard Time",
    //       "originalEndTimeZone": "Pacific Standard Time",
    //       "iCalUId": "040000008200E ... A230FEBFE5F7486A",
    //       "reminderMinutesBeforeStart": 15,
    //       "isReminderOn": true,
    //       "hasAttachments": false,
    //       "subject": "Let's go for lunch",
    //       "bodyPreview": "Does mid month work for you?",
    //       "importance": "normal",
    //       "sensitivity": "normal",
    //       "isAllDay": false,
    //       "isCancelled": false,
    //       "isOrganizer": true,
    //       "responseRequested": true,
    //       "seriesMasterId": null,
    //       "showAs": "busy",
    //       "type": "singleInstance",
    //       "webLink": "https://outlook.live.com/owa/?itemid=AQMkADAwATM0MDAAMS1iNTcwLWI2NT ... gkal8pdj0AApRZ7JkAAAA%3D&exvsurl=1&path=/calendar/item",
    //       "onlineMeetingUrl": null,
    //       "recurrence": null,
    //       "responseStatus": {
    //         "response": "organizer",
    //         "time": "0001-01-01T00:00:00Z"
    //       },
    //       "body": {
    //         "contentType": "html",
    //         "content": "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=us-ascii\">\r\n</head>\r\n<body>\r\nDoes mid month work for you?\r\n</body>\r\n</html>\r\n"
    //       },
    //       "start": {
    //         "dateTime": "2019-11-15T20:00:00.0000000",
    //         "timeZone": "UTC"
    //       },
    //       "end": {
    //         "dateTime": "2019-11-15T22:00:00.0000000",
    //         "timeZone": "UTC"
    //       },
    //       "location": {
    //         "displayName": "Harry's Bar",
    //         "locationType": "default",
    //         "uniqueId": "Harry's Bar",
    //         "uniqueIdType": "private"
    //       },
    //       "locations": [
    //         {
    //           "displayName": "Harry's Bar",
    //           "locationType": "default",
    //           "uniqueId": "Harry's Bar",
    //           "uniqueIdType": "private"
    //         }
    //       ],
    //       "attendees": [
    //         {
    //           "type": "required",
    //           "status": {
    //             "response": "none",
    //             "time": "0001-01-01T00:00:00Z"
    //           },
    //           "emailAddress": {
    //             "name": "Adele Vance",
    //             "address": "adelev@contoso.onmicrosoft.com"
    //           }
    //         }
    //       ],
    //       "organizer": {
    //         "emailAddress": {
    //           "name": "Matt",
    //           "address": "outlook_3A33FCEB9B74CC15@outlook.com"
    //         }
    //       }
    //     }
    //   ]
    // }

    // Use this online tool to generate parsing code from sample JSON: 
    // Generate Parsing Code from JSON

    const wchar_t *odataContext = 0;
    int i;
    int count_i;
    const wchar_t *odataEtag = 0;
    const wchar_t *id = 0;
    const wchar_t *createdDateTime = 0;
    const wchar_t *lastModifiedDateTime = 0;
    const wchar_t *changeKey = 0;
    const wchar_t *originalStartTimeZone = 0;
    const wchar_t *originalEndTimeZone = 0;
    const wchar_t *iCalUId = 0;
    int reminderMinutesBeforeStart;
    bool isReminderOn;
    bool hasAttachments;
    const wchar_t *subject = 0;
    const wchar_t *bodyPreview = 0;
    const wchar_t *importance = 0;
    const wchar_t *sensitivity = 0;
    bool isAllDay;
    bool isCancelled;
    bool isOrganizer;
    bool responseRequested;
    const wchar_t *seriesMasterId = 0;
    const wchar_t *showAs = 0;
    const wchar_t *v_type = 0;
    const wchar_t *webLink = 0;
    const wchar_t *onlineMeetingUrl = 0;
    const wchar_t *recurrence = 0;
    const wchar_t *responseStatusResponse = 0;
    const wchar_t *responseStatusTime = 0;
    const wchar_t *bodyContentType = 0;
    const wchar_t *bodyContent = 0;
    const wchar_t *startDateTime = 0;
    const wchar_t *startTimeZone = 0;
    const wchar_t *endDateTime = 0;
    const wchar_t *endTimeZone = 0;
    const wchar_t *locationDisplayName = 0;
    const wchar_t *locationLocationType = 0;
    const wchar_t *locationUniqueId = 0;
    const wchar_t *locationUniqueIdType = 0;
    const wchar_t *organizerEmailAddressName = 0;
    const wchar_t *organizerEmailAddressAddress = 0;
    int j;
    int count_j;
    const wchar_t *displayName = 0;
    const wchar_t *locationType = 0;
    const wchar_t *uniqueId = 0;
    const wchar_t *uniqueIdType = 0;
    const wchar_t *statusResponse = 0;
    const wchar_t *statusTime = 0;
    const wchar_t *emailAddressName = 0;
    const wchar_t *emailAddressAddress = 0;

    odataContext = json.stringOf(L"\"@odata.context\"");
    i = 0;
    count_i = json.SizeOfArray(L"value");
    while (i < count_i) {
        json.put_I(i);
        odataEtag = json.stringOf(L"value[i].\"@odata.etag\"");
        id = json.stringOf(L"value[i].id");
        createdDateTime = json.stringOf(L"value[i].createdDateTime");
        lastModifiedDateTime = json.stringOf(L"value[i].lastModifiedDateTime");
        changeKey = json.stringOf(L"value[i].changeKey");
        originalStartTimeZone = json.stringOf(L"value[i].originalStartTimeZone");
        originalEndTimeZone = json.stringOf(L"value[i].originalEndTimeZone");
        iCalUId = json.stringOf(L"value[i].iCalUId");
        reminderMinutesBeforeStart = json.IntOf(L"value[i].reminderMinutesBeforeStart");
        isReminderOn = json.BoolOf(L"value[i].isReminderOn");
        hasAttachments = json.BoolOf(L"value[i].hasAttachments");
        subject = json.stringOf(L"value[i].subject");
        bodyPreview = json.stringOf(L"value[i].bodyPreview");
        importance = json.stringOf(L"value[i].importance");
        sensitivity = json.stringOf(L"value[i].sensitivity");
        isAllDay = json.BoolOf(L"value[i].isAllDay");
        isCancelled = json.BoolOf(L"value[i].isCancelled");
        isOrganizer = json.BoolOf(L"value[i].isOrganizer");
        responseRequested = json.BoolOf(L"value[i].responseRequested");
        seriesMasterId = json.stringOf(L"value[i].seriesMasterId");
        showAs = json.stringOf(L"value[i].showAs");
        v_type = json.stringOf(L"value[i].type");
        webLink = json.stringOf(L"value[i].webLink");
        onlineMeetingUrl = json.stringOf(L"value[i].onlineMeetingUrl");
        recurrence = json.stringOf(L"value[i].recurrence");
        responseStatusResponse = json.stringOf(L"value[i].responseStatus.response");
        responseStatusTime = json.stringOf(L"value[i].responseStatus.time");
        bodyContentType = json.stringOf(L"value[i].body.contentType");
        bodyContent = json.stringOf(L"value[i].body.content");
        startDateTime = json.stringOf(L"value[i].start.dateTime");
        startTimeZone = json.stringOf(L"value[i].start.timeZone");
        endDateTime = json.stringOf(L"value[i].end.dateTime");
        endTimeZone = json.stringOf(L"value[i].end.timeZone");
        locationDisplayName = json.stringOf(L"value[i].location.displayName");
        locationLocationType = json.stringOf(L"value[i].location.locationType");
        locationUniqueId = json.stringOf(L"value[i].location.uniqueId");
        locationUniqueIdType = json.stringOf(L"value[i].location.uniqueIdType");
        organizerEmailAddressName = json.stringOf(L"value[i].organizer.emailAddress.name");
        organizerEmailAddressAddress = json.stringOf(L"value[i].organizer.emailAddress.address");
        j = 0;
        count_j = json.SizeOfArray(L"value[i].categories");
        while (j < count_j) {
            json.put_J(j);
            // ...
            j = j + 1;
        }

        j = 0;
        count_j = json.SizeOfArray(L"value[i].locations");
        while (j < count_j) {
            json.put_J(j);
            displayName = json.stringOf(L"value[i].locations[j].displayName");
            locationType = json.stringOf(L"value[i].locations[j].locationType");
            uniqueId = json.stringOf(L"value[i].locations[j].uniqueId");
            uniqueIdType = json.stringOf(L"value[i].locations[j].uniqueIdType");
            j = j + 1;
        }

        j = 0;
        count_j = json.SizeOfArray(L"value[i].attendees");
        while (j < count_j) {
            json.put_J(j);
            v_type = json.stringOf(L"value[i].attendees[j].type");
            statusResponse = json.stringOf(L"value[i].attendees[j].status.response");
            statusTime = json.stringOf(L"value[i].attendees[j].status.time");
            emailAddressName = json.stringOf(L"value[i].attendees[j].emailAddress.name");
            emailAddressAddress = json.stringOf(L"value[i].attendees[j].emailAddress.address");
            j = j + 1;
        }

        i = i + 1;
    }

    wprintf(L"Success.\n");
    }