Sample code for 30+ languages & platforms
Zig

Microsoft Teams - List Team Members

See more Microsoft Teams Examples

Get the members of a team.

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 assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    const http = try chilkat.Http.init();
    defer http.deinit();

    // Implements the following CURL command:

    // curl -X GET https://graph.microsoft.com/v1.0/teams/{teamsId}/members \
    //   -H 'authorization: Bearer ACCESS_TOKEN'

    // Use the following online tool to generate HTTP code from a CURL command
    // Convert a cURL Command to HTTP Source Code

    // Adds the "Authorization: Bearer ACCESS_TOKEN" header.
    http.setAuthToken("ACCESS_TOKEN");

    http.setUrlVar("teamsId", "285c8d65-d8b5-447a-91c7-85593d50c826") catch {};

    const sb_response_body = try chilkat.StringBuilder.init();
    defer sb_response_body.deinit();
    http.quickGetSb("https://graph.microsoft.com/v1.0/teams/{$teamsId}/members", sb_response_body) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    const j_resp = try chilkat.JsonObject.init();
    defer j_resp.deinit();
    j_resp.loadSb(sb_response_body) catch {};
    j_resp.setEmitCompact(false);

    std.debug.print("Response Body:\n", .{});
    std.debug.print("{s}\n", .{try j_resp.emit(alloc)});

    const resp_status_code = http.getLastStatus();
    std.debug.print("Response Status Code = {d}\n", .{resp_status_code});
    if (resp_status_code >= 400) {
        std.debug.print("Response Header:\n", .{});
        std.debug.print("{s}\n", .{try http.getLastHeader(alloc)});
        std.debug.print("Failed.\n", .{});
        return;
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#teams('285c8d65-d8b5-447a-91c7-85593d50c826')/members",
    //   "@odata.count": 1,
    //   "value": [
    //     {
    //       "@odata.type": "#microsoft.graph.aadUserConversationMember",
    //       "id": "Mjg1YzhkNjUtZDhiNS00NDdhLTkxYzctODU1OTNkNTBjODI2IyM0ZWU3MzJjMz0zMjJlLTRhNmItYjcyOS0yZmQxZWI1YzYwMDQ=",
    //       "roles": [
    //         "owner"
    //       ],
    //       "displayName": "Joe Smith",
    //       "userId": "4ee732c3-322e-4a6b-b729-2fd1eb5c6004",
    //       "email": "admin@chilkat365.com"
    //     }
    //   ]
    // }

    // Sample code for parsing the JSON response...
    // Use the following online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    var odata_type: [:0]const u8 = "";
    var id: [:0]const u8 = "";
    var display_name: [:0]const u8 = "";
    var user_id: [:0]const u8 = "";
    var email: [:0]const u8 = "";
    var j: i32 = 0;
    var count_j: i32 = 0;
    var str_val: [:0]const u8 = "";

    _ = try j_resp.stringOf(alloc, "\"@odata.context\"");
    _ = j_resp.intOf("\"@odata.count\"");
    var i: i32 = 0;
    const count_i = j_resp.sizeOfArray("value");
    while (i < count_i) {
        j_resp.setI(i);
        odata_type = try j_resp.stringOf(alloc, "value[i].\"@odata.type\"");
        id = try j_resp.stringOf(alloc, "value[i].id");
        display_name = try j_resp.stringOf(alloc, "value[i].displayName");
        user_id = try j_resp.stringOf(alloc, "value[i].userId");
        email = try j_resp.stringOf(alloc, "value[i].email");
        j = 0;
        count_j = j_resp.sizeOfArray("value[i].roles");
        while (j < count_j) {
            j_resp.setJ(j);
            str_val = try j_resp.stringOf(alloc, "value[i].roles[j]");
            j = j + 1;
        }

        i = i + 1;
    }
}