Sample code for 30+ languages & platforms
Xbase++

Outlook Calendar List Events

See more Outlook Calendar Examples

Retrieve a list of events in a calendar.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oJsonToken
LOCAL cCalendarId
LOCAL oResp
LOCAL oJson
LOCAL cOriginalStartTimeZone
LOCAL cOriginalEndTimeZone
LOCAL cResponseStatusResponse
LOCAL cResponseStatusTime
LOCAL cICalUId
LOCAL nReminderMinutesBeforeStart
LOCAL nIsReminderOn
LOCAL i
LOCAL nCount_i

nSuccess := 0

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

oHttp := CreateObject("Chilkat.Http")

//  Use your previously obtained access token here: Get Outlook Calendar OAuth2 Access Token (Azure AD v2.0 Endpoint).

oJsonToken := CreateObject("Chilkat.JsonObject")
nSuccess := oJsonToken:LoadFile("qa_data/tokens/outlookCalendar.json")
IF (nSuccess == 0)
    ? oJsonToken:LastErrorText
    oHttp:destroy()
    oJsonToken:destroy()
    RETURN
ENDIF

oHttp:AuthToken := oJsonToken:StringOf("access_token")

//  Specify the ID of the calendar to list.
cCalendarId := "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAAAiCsAAAA"

oHttp:SetUrlVar("id", cCalendarId)

//  To list the events in the default calendar, use the following URL: https://graph.microsoft.com/v1.0/me/calendars/events

oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpNoBody("GET", "https://graph.microsoft.com/v1.0/me/calendars/{$id}/events", oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oJsonToken:destroy()
    oResp:destroy()
    RETURN
ENDIF

? "Response status code = " + Str(oResp:StatusCode)

//  The HTTP request succeeded if the response status code = 200.
IF (oResp:StatusCode != 200)
    ? oResp:BodyStr
    ? "Failed"
    oHttp:destroy()
    oJsonToken:destroy()
    oResp:destroy()
    RETURN
ENDIF

oJson := CreateObject("Chilkat.JsonObject")
oJson:Load(oResp:BodyStr)
oJson:EmitCompact := 0
? oJson:Emit()

//  Here is a sample response:

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

//  {
//    "value": [
//      {
//        "originalStartTimeZone": "originalStartTimeZone-value",
//        "originalEndTimeZone": "originalEndTimeZone-value",
//        "responseStatus": {
//          "response": "",
//          "time": "datetime-value"
//        },
//        "iCalUId": "iCalUId-value",
//        "reminderMinutesBeforeStart": 99,
//        "isReminderOn": true
//      }
//    ]
//  }

i := 0
nCount_i := oJson:SizeOfArray("value")
DO WHILE i < nCount_i
    oJson:I := i
    cOriginalStartTimeZone := oJson:StringOf("value[i].originalStartTimeZone")
    cOriginalEndTimeZone := oJson:StringOf("value[i].originalEndTimeZone")
    cResponseStatusResponse := oJson:StringOf("value[i].responseStatus.response")
    cResponseStatusTime := oJson:StringOf("value[i].responseStatus.time")
    cICalUId := oJson:StringOf("value[i].iCalUId")
    nReminderMinutesBeforeStart := oJson:IntOf("value[i].reminderMinutesBeforeStart")
    nIsReminderOn := oJson:BoolOf("value[i].isReminderOn")
    i := i + 1
ENDDO

oHttp:destroy()
oJsonToken:destroy()
oResp:destroy()
oJson:destroy()