Sample code for 30+ languages & platforms
Zig

Microsoft Teams - Create Team (minimal request)

See more Microsoft Teams Examples

The following is an example of a minimal request to create a Team. By omitting other properties, the client is implicitly taking defaults from the pre-defined template represented by template.

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();

    // To create a Microsoft Team, we want to send an HTTP request like the following:

    // POST https://graph.microsoft.com/v1.0/teams
    // Content-Type: application/json
    //
    // {
    //   "template@odata.bind": "https://graph.microsoft.com/v1.0/teamsTemplates('standard')",
    //   "displayName": "My Sample Team",
    //   "description": "My Sample Team’s Description"
    // }

    const json = try chilkat.JsonObject.init();
    defer json.deinit();
    json.updateString("\"template@odata.bind\"", "https://graph.microsoft.com/v1.0/teamsTemplates('standard')") catch {};
    json.updateString("displayName", "My Sample Team") catch {};
    json.updateString("description", "My Sample Team’s Description") catch {};

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

    const resp = try chilkat.HttpResponse.init();
    defer resp.deinit();
    http.httpJson("POST", "https://graph.microsoft.com/v1.0/teams", json, "application/json", resp) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    // A successful response is indicated by a 202 response status code and an empty response body.
    std.debug.print("Response Status Code: {d}\n", .{resp.getStatusCode()});
    std.debug.print("Response Body:\n", .{});
    std.debug.print("{s}\n", .{try resp.getBodyStr(alloc)});

    if (resp.getStatusCode() >= 400) {
        std.debug.print("Response Header:\n", .{});
        std.debug.print("{s}\n", .{try resp.getHeader(alloc)});
        std.debug.print("Failed.\n", .{});
    }
}