Sample code for 30+ languages & platforms
PureBasic

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 PureBasic Downloads

PureBasic
IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"

Procedure ChilkatExample()

    success.i = 0

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

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

    jsonToken.i = CkJsonObject::ckCreate()
    If jsonToken.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkJsonObject::ckLoadFile(jsonToken,"qa_data/tokens/msGraphCalendar.json")
    If success = 0
        Debug CkJsonObject::ckLastErrorText(jsonToken)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(jsonToken)
        ProcedureReturn
    EndIf

    CkHttp::setCkAuthToken(http, CkJsonObject::ckStringOf(jsonToken,"access_token"))

    ; Specify the calendar id
    CkHttp::ckSetUrlVar(http,"id","AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAClEpRTgAAAA==")
    ; Send a GET request to https://graph.microsoft.com/v1.0/me/calendars/{$id}/events
    strResponse.s = CkHttp::ckQuickGetStr(http,"https://graph.microsoft.com/v1.0/me/calendars/{$id}/events")
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(jsonToken)
        ProcedureReturn
    EndIf

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoad(json,strResponse)
    CkJsonObject::setCkEmitCompact(json, 0)

    If CkHttp::ckLastStatus(http) <> 200
        Debug CkJsonObject::ckEmit(json)
        Debug "Failed, response status code = " + Str(CkHttp::ckLastStatus(http))
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(jsonToken)
        CkJsonObject::ckDispose(json)
        ProcedureReturn
    EndIf

    Debug CkJsonObject::ckEmit(json)

    ; 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

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

    odataContext = CkJsonObject::ckStringOf(json,Chr(34) + "@odata.context" + Chr(34))
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(json,"value")
    While i < count_i
        CkJsonObject::setCkI(json, i)
        odataEtag = CkJsonObject::ckStringOf(json,"value[i]." + Chr(34) + "@odata.etag" + Chr(34))
        id = CkJsonObject::ckStringOf(json,"value[i].id")
        createdDateTime = CkJsonObject::ckStringOf(json,"value[i].createdDateTime")
        lastModifiedDateTime = CkJsonObject::ckStringOf(json,"value[i].lastModifiedDateTime")
        changeKey = CkJsonObject::ckStringOf(json,"value[i].changeKey")
        originalStartTimeZone = CkJsonObject::ckStringOf(json,"value[i].originalStartTimeZone")
        originalEndTimeZone = CkJsonObject::ckStringOf(json,"value[i].originalEndTimeZone")
        iCalUId = CkJsonObject::ckStringOf(json,"value[i].iCalUId")
        reminderMinutesBeforeStart = CkJsonObject::ckIntOf(json,"value[i].reminderMinutesBeforeStart")
        isReminderOn = CkJsonObject::ckBoolOf(json,"value[i].isReminderOn")
        hasAttachments = CkJsonObject::ckBoolOf(json,"value[i].hasAttachments")
        subject = CkJsonObject::ckStringOf(json,"value[i].subject")
        bodyPreview = CkJsonObject::ckStringOf(json,"value[i].bodyPreview")
        importance = CkJsonObject::ckStringOf(json,"value[i].importance")
        sensitivity = CkJsonObject::ckStringOf(json,"value[i].sensitivity")
        isAllDay = CkJsonObject::ckBoolOf(json,"value[i].isAllDay")
        isCancelled = CkJsonObject::ckBoolOf(json,"value[i].isCancelled")
        isOrganizer = CkJsonObject::ckBoolOf(json,"value[i].isOrganizer")
        responseRequested = CkJsonObject::ckBoolOf(json,"value[i].responseRequested")
        seriesMasterId = CkJsonObject::ckStringOf(json,"value[i].seriesMasterId")
        showAs = CkJsonObject::ckStringOf(json,"value[i].showAs")
        v_type = CkJsonObject::ckStringOf(json,"value[i].type")
        webLink = CkJsonObject::ckStringOf(json,"value[i].webLink")
        onlineMeetingUrl = CkJsonObject::ckStringOf(json,"value[i].onlineMeetingUrl")
        recurrence = CkJsonObject::ckStringOf(json,"value[i].recurrence")
        responseStatusResponse = CkJsonObject::ckStringOf(json,"value[i].responseStatus.response")
        responseStatusTime = CkJsonObject::ckStringOf(json,"value[i].responseStatus.time")
        bodyContentType = CkJsonObject::ckStringOf(json,"value[i].body.contentType")
        bodyContent = CkJsonObject::ckStringOf(json,"value[i].body.content")
        startDateTime = CkJsonObject::ckStringOf(json,"value[i].start.dateTime")
        startTimeZone = CkJsonObject::ckStringOf(json,"value[i].start.timeZone")
        endDateTime = CkJsonObject::ckStringOf(json,"value[i].end.dateTime")
        endTimeZone = CkJsonObject::ckStringOf(json,"value[i].end.timeZone")
        locationDisplayName = CkJsonObject::ckStringOf(json,"value[i].location.displayName")
        locationLocationType = CkJsonObject::ckStringOf(json,"value[i].location.locationType")
        locationUniqueId = CkJsonObject::ckStringOf(json,"value[i].location.uniqueId")
        locationUniqueIdType = CkJsonObject::ckStringOf(json,"value[i].location.uniqueIdType")
        organizerEmailAddressName = CkJsonObject::ckStringOf(json,"value[i].organizer.emailAddress.name")
        organizerEmailAddressAddress = CkJsonObject::ckStringOf(json,"value[i].organizer.emailAddress.address")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(json,"value[i].categories")
        While j < count_j
            CkJsonObject::setCkJ(json, j)
            ; ...
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(json,"value[i].locations")
        While j < count_j
            CkJsonObject::setCkJ(json, j)
            displayName = CkJsonObject::ckStringOf(json,"value[i].locations[j].displayName")
            locationType = CkJsonObject::ckStringOf(json,"value[i].locations[j].locationType")
            uniqueId = CkJsonObject::ckStringOf(json,"value[i].locations[j].uniqueId")
            uniqueIdType = CkJsonObject::ckStringOf(json,"value[i].locations[j].uniqueIdType")
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(json,"value[i].attendees")
        While j < count_j
            CkJsonObject::setCkJ(json, j)
            v_type = CkJsonObject::ckStringOf(json,"value[i].attendees[j].type")
            statusResponse = CkJsonObject::ckStringOf(json,"value[i].attendees[j].status.response")
            statusTime = CkJsonObject::ckStringOf(json,"value[i].attendees[j].status.time")
            emailAddressName = CkJsonObject::ckStringOf(json,"value[i].attendees[j].emailAddress.name")
            emailAddressAddress = CkJsonObject::ckStringOf(json,"value[i].attendees[j].emailAddress.address")
            j = j + 1
        Wend
        i = i + 1
    Wend

    Debug "Success."


    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(jsonToken)
    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure