Sample code for 30+ languages & platforms
Lua

Outlook Calendar List Calendars

See more Outlook Calendar Examples

Get all the user's calendars.

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")

local resp = chilkat.HttpResponse.new()
success = http:http_no_body("GET", "https://graph.microsoft.com/v1.0/me/calendars", 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

-- {
--     "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#me/calendars",
--     "value": [
--         {
--             "@odata.id": "https://graph.microsoft.com/v1.0/users('ddfcd489-628b-40d7-b48b-57002df800e5@1717622f-1d94-4d0c-9d74-709fad664b77')/calendars('AAMkAGI2TGuLAAA=')",
--             "id": "AAMkAGI2TGuLAAA=",
--             "name": "Calendar",
--             "color": "auto",
--             "changeKey": "nfZyf7VcrEKLNoU37KWlkQAAA0x0+w==",
--             "canShare":true,
--             "canViewPrivateItems":true,
--             "hexColor": "",
--             "canEdit":true,
--             "allowedOnlineMeetingProviders": [
--                 "teamsForBusiness"
--             ],
--             "defaultOnlineMeetingProvider": "teamsForBusiness",
--             "isTallyingResponses": true,
--             "isRemovable": false,
--             "owner":{
--                 "name":"Samantha Booth",
--                 "address":"samanthab@adatum.onmicrosoft.com"
--             }
--         }
--     ]
-- }

local id = ""
local name = ""
local color = ""
local hexColor = ""
local isDefaultCalendar = false
local changeKey = ""
local canShare = false
local canViewPrivateItems = false
local canEdit = false
local defaultOnlineMeetingProvider = ""
local isTallyingResponses = false
local isRemovable = false
local ownerName = ""
local ownerAddress = ""
local j = 0
local count_j = 0
local strVal = ""

local odata_context = json:string_of("\"@odata.context\"")
local i = 0
local count_i = json:size_of_array("value")
while i < count_i do
    json.i = i
    id = json:string_of("value[i].id")
    name = json:string_of("value[i].name")
    color = json:string_of("value[i].color")
    hexColor = json:string_of("value[i].hexColor")
    isDefaultCalendar = json:bool_of("value[i].isDefaultCalendar")
    changeKey = json:string_of("value[i].changeKey")
    canShare = json:bool_of("value[i].canShare")
    canViewPrivateItems = json:bool_of("value[i].canViewPrivateItems")
    canEdit = json:bool_of("value[i].canEdit")
    defaultOnlineMeetingProvider = json:string_of("value[i].defaultOnlineMeetingProvider")
    isTallyingResponses = json:bool_of("value[i].isTallyingResponses")
    isRemovable = json:bool_of("value[i].isRemovable")
    ownerName = json:string_of("value[i].owner.name")
    ownerAddress = json:string_of("value[i].owner.address")
    j = 0
    count_j = json:size_of_array("value[i].allowedOnlineMeetingProviders")
    while j < count_j do
        json.j = j
        strVal = json:string_of("value[i].allowedOnlineMeetingProviders[j]")
        j = j + 1
    end

    i = i + 1
end