Sample code for 30+ languages & platforms
Swift

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

Swift

func chilkatTest() {
    var success: Bool = false

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

    let http = CkoHttp()!

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

    let jsonToken = CkoJsonObject()!
    success = jsonToken.loadFile(path: "qa_data/tokens/msGraphCalendar.json")
    if success == false {
        print("\(jsonToken.lastErrorText!)")
        return
    }

    http.authToken = jsonToken.string(of: "access_token")

    // Specify the calendar id
    http.setUrlVar(name: "id", value: "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAClEpRTgAAAA==")
    // Send a GET request to https://graph.microsoft.com/v1.0/me/calendars/{$id}/events
    var strResponse: String? = http.quickGetStr(url: "https://graph.microsoft.com/v1.0/me/calendars/{$id}/events")
    if http.lastMethodSuccess == false {
        print("\(http.lastErrorText!)")
        return
    }

    let json = CkoJsonObject()!
    json.load(json: strResponse)
    json.emitCompact = false

    if http.lastStatus.intValue != 200 {
        print("\(json.emit()!)")
        print("Failed, response status code = \(http.lastStatus.intValue)")
        return
    }

    print("\(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

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

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

        j = 0
        count_j = json.size(ofArray: "value[i].locations").intValue
        while j < count_j {
            json.j = j
            displayName = json.string(of: "value[i].locations[j].displayName")
            locationType = json.string(of: "value[i].locations[j].locationType")
            uniqueId = json.string(of: "value[i].locations[j].uniqueId")
            uniqueIdType = json.string(of: "value[i].locations[j].uniqueIdType")
            j = j + 1
        }

        j = 0
        count_j = json.size(ofArray: "value[i].attendees").intValue
        while j < count_j {
            json.j = j
            v_type = json.string(of: "value[i].attendees[j].type")
            statusResponse = json.string(of: "value[i].attendees[j].status.response")
            statusTime = json.string(of: "value[i].attendees[j].status.time")
            emailAddressName = json.string(of: "value[i].attendees[j].emailAddress.name")
            emailAddressAddress = json.string(of: "value[i].attendees[j].emailAddress.address")
            j = j + 1
        }

        i = i + 1
    }

    print("Success.")

}