Zig
Zig
MS Graph Calendars List
See more Microsoft Calendar Examples
Get all the user's calendars (/calendars navigation property), get the calendars from the default calendar group or from a specific calendar group.For more details, see https://docs.microsoft.com/en-us/graph/api/user-list-calendars?view=graph-rest-1.0
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
// Use your previously obtained access token as shown here:
// Get Microsoft Graph OAuth2 Access Token with Calendars.ReadWrite scope.
const json_token = try chilkat.JsonObject.init();
defer json_token.deinit();
json_token.loadFile("qa_data/tokens/msGraphCalendar.json") catch {
std.debug.print("{s}\n", .{try json_token.getLastErrorText(alloc)});
return;
};
http.setAuthToken(try json_token.stringOf(alloc, "access_token"));
// Send a GET request to https://graph.microsoft.com/v1.0/me/calendars
const str_response = http.quickGetStr(alloc, "https://graph.microsoft.com/v1.0/me/calendars") catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.load(str_response) catch {};
json.setEmitCompact(false);
if (http.getLastStatus() != 200) {
std.debug.print("{s}\n", .{try json.emit(alloc)});
std.debug.print("Failed, response status code = {d}\n", .{http.getLastStatus()});
return;
}
std.debug.print("{s}\n", .{try json.emit(alloc)});
// Sample output:
// {
// "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('admin%40chilkat.io')/calendars",
// "value": [
// {
// "id": "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAAAiCsAAAA",
// "name": "Calendar",
// "color": "auto",
// "changeKey": "5+vF7TKKdE6bGCRqXyl2PQAAAAAiEQ==",
// "canShare": true,
// "canViewPrivateItems": true,
// "canEdit": true,
// "owner": {
// "name": "...",
// "address": "outlook_3A33FCEB9B74CC15@outlook.com"
// }
// },
// {
// "id": "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAClEpRTgAAAA==",
// "name": "Work",
// "color": "auto",
// "changeKey": "5+vF7TKKdE6bGCRqXyl2PQAClHjDcA==",
// "canShare": true,
// "canViewPrivateItems": true,
// "canEdit": true,
// "owner": {
// "name": "...",
// "address": "outlook_3A33FCEB9B74CC15@outlook.com"
// }
// }
// ]
// }
//
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
var i: i32 = 0;
var id: [:0]const u8 = "";
var name: [:0]const u8 = "";
var color: [:0]const u8 = "";
var change_key: [:0]const u8 = "";
var can_share: bool = false;
var can_view_private_items: bool = false;
var can_edit: bool = false;
var owner_name: [:0]const u8 = "";
var owner_address: [:0]const u8 = "";
_ = try json.stringOf(alloc, "\"@odata.context\"");
i = 0;
const count_i = json.sizeOfArray("value");
while (i < count_i) {
json.setI(i);
id = try json.stringOf(alloc, "value[i].id");
name = try json.stringOf(alloc, "value[i].name");
color = try json.stringOf(alloc, "value[i].color");
change_key = try json.stringOf(alloc, "value[i].changeKey");
can_share = json.boolOf("value[i].canShare");
can_view_private_items = json.boolOf("value[i].canViewPrivateItems");
can_edit = json.boolOf("value[i].canEdit");
owner_name = try json.stringOf(alloc, "value[i].owner.name");
owner_address = try json.stringOf(alloc, "value[i].owner.address");
i = i + 1;
}
std.debug.print("Success.\n", .{});
}