Zig Requires Chilkat v11.0.0+
Zig
Get Tasks for User
See more Microsoft Tasks and Plans Examples
Demonstrates how to retrieve a list of plannertask objects assigned to a User.See https://docs.microsoft.com/en-us/graph/api/planneruser-list-tasks?view=graph-rest-1.0 for more information.
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();
// The Microsoft Planner REST API requires an OAuth2 token with the Group.ReadWrite.All scope.
// Use your previously obtained access token as shown here:
// Get Microsoft Graph OAuth2 Access Token with Group.ReadWrite.All scope.
const json_token = try chilkat.JsonObject.init();
defer json_token.deinit();
json_token.loadFile("qa_data/tokens/msGraphGroup.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/planner/tasks
const str_response = http.quickGetStr(alloc, "https://graph.microsoft.com/v1.0/me/planner/tasks") 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:
// (See parsing code below..)
// {
// "value": [
// {
// "createdBy": {
// "user": {
// "id": "6463a5ce-2119-4198-9f2a-628761df4a62"
// }
// },
// "planId": "xqQg5FS2LkCp935s-FIFm2QAFkHM",
// "bucketId": "gcrYAaAkgU2EQUvpkNNXLGQAGTtu",
// "title": "title-value",
// "orderHint": "9223370609546166567W",
// "assigneePriority": "90057581\"",
// "createdDateTime": "2015-03-25T18:36:49.2407981Z",
// "assignments": {
// "fbab97d0-4932-4511-b675-204639209557": {
// "@odata.type": "#microsoft.graph.plannerAssignment",
// "assignedBy": {
// "user": {
// "id": "1e9955d2-6acd-45bf-86d3-b546fdc795eb"
// }
// },
// "assignedDateTime": "2015-03-25T18:38:21.956Z",
// "orderHint": "RWk1"
// }
// },
// "id":"01gzSlKkIUSUl6DF_EilrmQAKDhh"
// }
// ]
// }
var i: i32 = 0;
var created_by_user_id: [:0]const u8 = "";
var plan_id: [:0]const u8 = "";
var bucket_id: [:0]const u8 = "";
var title: [:0]const u8 = "";
var order_hint: [:0]const u8 = "";
var assignee_priority: [:0]const u8 = "";
var created_date_time: [:0]const u8 = "";
var assignments_odata_type: [:0]const u8 = "";
var assignments_assigned_by_user_id: [:0]const u8 = "";
var assignments_assigned_date_time: [:0]const u8 = "";
var assignments_order_hint: [:0]const u8 = "";
var id: [:0]const u8 = "";
const json_a = try chilkat.JsonObject.init();
defer json_a.deinit();
const json_user_a = try chilkat.JsonObject.init();
defer json_user_a.deinit();
i = 0;
const count_i = json.sizeOfArray("value");
while (i < count_i) {
json.setI(i);
created_by_user_id = try json.stringOf(alloc, "value[i].createdBy.user.id");
plan_id = try json.stringOf(alloc, "value[i].planId");
bucket_id = try json.stringOf(alloc, "value[i].bucketId");
title = try json.stringOf(alloc, "value[i].title");
order_hint = try json.stringOf(alloc, "value[i].orderHint");
assignee_priority = try json.stringOf(alloc, "value[i].assigneePriority");
created_date_time = try json.stringOf(alloc, "value[i].createdDateTime");
json.objectOf2("value[i].assignments", json_a) catch {};
const user_id = try json_a.nameAt(alloc, 0);
json_a.objectOf2(user_id, json_user_a) catch {};
assignments_odata_type = try json_user_a.stringOf(alloc, "\"@odata.type\"");
assignments_assigned_by_user_id = try json_user_a.stringOf(alloc, "assignedBy.user.id");
assignments_assigned_date_time = try json_user_a.stringOf(alloc, "assignedDateTime");
assignments_order_hint = try json_user_a.stringOf(alloc, "orderHint");
id = try json.stringOf(alloc, "value[i].id");
i = i + 1;
}
std.debug.print("Success.\n", .{});
}