Sample code for 30+ languages & platforms
Zig

List Plans for a Group

See more Microsoft Tasks and Plans Examples

Demonstrates how to retrieve a list of plannerPlan objects owned by a group object.

See https://docs.microsoft.com/en-us/graph/api/plannergroup-list-plans?view=graph-rest-1.0 for more information.

Chilkat Zig Downloads

Zig
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/groups/{group-id}/planner/plans
    const str_response = http.quickGetStr(alloc, "https://graph.microsoft.com/v1.0/groups/{group-id}/planner/plans") 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": {
    //         "application": {
    //           "id": "95e27074-6c4a-447a-aa24-9d718a0b86fa"
    //         },
    //         "user": {
    //           "id": "ebf3b108-5234-4e22-b93d-656d7dae5874"
    //         }
    //       },
    //       "createdDateTime": "2015-03-30T18:36:49.2407981Z",
    //       "owner": "ebf3b108-5234-4e22-b93d-656d7dae5874",
    //       "title": "title-value",
    //       "id": "xqQg5FS2LkCp935s-FIFm2QAFkHM"
    //     }
    //   ]
    // }

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

    var i: i32 = 0;
    var created_by_application_id: [:0]const u8 = "";
    var created_by_user_id: [:0]const u8 = "";
    var created_date_time: [:0]const u8 = "";
    var owner: [:0]const u8 = "";
    var title: [:0]const u8 = "";
    var id: [:0]const u8 = "";

    i = 0;
    const count_i = json.sizeOfArray("value");
    while (i < count_i) {
        json.setI(i);
        created_by_application_id = try json.stringOf(alloc, "value[i].createdBy.application.id");
        created_by_user_id = try json.stringOf(alloc, "value[i].createdBy.user.id");
        created_date_time = try json.stringOf(alloc, "value[i].createdDateTime");
        owner = try json.stringOf(alloc, "value[i].owner");
        title = try json.stringOf(alloc, "value[i].title");
        id = try json.stringOf(alloc, "value[i].id");
        i = i + 1;
    }

    std.debug.print("Success.\n", .{});
}