Sample code for 30+ languages & platforms
Lua

Outlook Calendar List Events

See more Outlook Calendar Examples

Retrieve a list of events in a calendar.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

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

local http = chilkat.Http.new()

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

local jsonToken = chilkat.JsonObject.new()
local success = jsonToken:load_file("qa_data/tokens/outlookCalendar.json")
if not success then
    print(jsonToken.last_error_text)
    return
end

http.auth_token = jsonToken:string_of("access_token")

-- Specify the ID of the calendar to list.
local calendarId = "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAAAiCsAAAA"

http:set_url_var("id", calendarId)

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

local resp = chilkat.HttpResponse.new()
success = http:http_no_body("GET", "https://graph.microsoft.com/v1.0/me/calendars/{$id}/events", resp)
if not success then
    print(http.last_error_text)
    return
end

print("Response status code = " .. resp.status_code)

-- The HTTP request succeeded if the response status code = 200.
if resp.status_code ~= 200 then
    print(resp.body_str)
    print("Failed")
    return
end

local json = chilkat.JsonObject.new()
json:load(resp.body_str)
json.emit_compact = false
print(json: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
--     }
--   ]
-- }

local originalStartTimeZone = ""
local originalEndTimeZone = ""
local responseStatusResponse = ""
local responseStatusTime = ""
local iCalUId = ""
local reminderMinutesBeforeStart = 0
local isReminderOn = false

local i = 0
local count_i = json:size_of_array("value")
while i < count_i do
    json.i = i
    originalStartTimeZone = json:string_of("value[i].originalStartTimeZone")
    originalEndTimeZone = json:string_of("value[i].originalEndTimeZone")
    responseStatusResponse = json:string_of("value[i].responseStatus.response")
    responseStatusTime = json:string_of("value[i].responseStatus.time")
    iCalUId = json:string_of("value[i].iCalUId")
    reminderMinutesBeforeStart = json:int_of("value[i].reminderMinutesBeforeStart")
    isReminderOn = json:bool_of("value[i].isReminderOn")
    i = i + 1
end