Sample code for 30+ languages & platforms
Zig

Microsoft Teams - Create Team (complex request)

See more Microsoft Teams Examples

Create a team with multiple channels, installed apps, and pinned tabs using delegated permissions

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

    // Build the following HTTP request:

    // POST https://graph.microsoft.com/v1.0/teams
    // Content-Type: application/json
    //
    // {
    //     "template@odata.bind": "https://graph.microsoft.com/v1.0/teamsTemplates('standard')",
    //     "visibility": "Private",
    //     "displayName": "Sample Engineering Team",
    //     "description": "This is a sample engineering team, used to showcase the range of properties supported by this API",
    //     "channels": [
    //         {
    //             "displayName": "Announcements",
    //             "isFavoriteByDefault": true,
    //             "description": "This is a sample announcements channel that is favorited by default. Use this channel to make important team, product, and service announcements."
    //         },
    //         {
    //             "displayName": "Training",
    //             "isFavoriteByDefault": true,
    //             "description": "This is a sample training channel, that is favorited by default, and contains an example of pinned website and YouTube tabs.",
    //             "tabs": [
    //                 {
    //                     "teamsApp@odata.bind": "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('com.microsoft.teamspace.tab.web')",
    //                     "name": "A Pinned Website",
    //                     "configuration": {
    //                         "contentUrl": "https://docs.microsoft.com/microsoftteams/microsoft-teams"
    //                     }
    //                 },
    //                 {
    //                     "teamsApp@odata.bind": "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('com.microsoft.teamspace.tab.youtube')",
    //                     "name": "A Pinned YouTube Video",
    //                     "configuration": {
    //                         "contentUrl": "https://tabs.teams.microsoft.com/Youtube/Home/YoutubeTab?videoId=X8krAMdGvCQ",
    //                         "websiteUrl": "https://www.youtube.com/watch?v=X8krAMdGvCQ"
    //                     }
    //                 }
    //             ]
    //         },
    //         {
    //             "displayName": "Planning",
    //             "description": "This is a sample of a channel that is not favorited by default, these channels will appear in the more channels overflow menu.",
    //             "isFavoriteByDefault": false
    //         },
    //         {
    //             "displayName": "Issues and Feedback",
    //             "description": "This is a sample of a channel that is not favorited by default, these channels will appear in the more channels overflow menu."
    //         }
    //     ],
    //     "memberSettings": {
    //         "allowCreateUpdateChannels": true,
    //         "allowDeleteChannels": true,
    //         "allowAddRemoveApps": true,
    //         "allowCreateUpdateRemoveTabs": true,
    //         "allowCreateUpdateRemoveConnectors": true
    //     },
    //     "guestSettings": {
    //         "allowCreateUpdateChannels": false,
    //         "allowDeleteChannels": false
    //     },
    //     "funSettings": {
    //         "allowGiphy": true,
    //         "giphyContentRating": "Moderate",
    //         "allowStickersAndMemes": true,
    //         "allowCustomMemes": true
    //     },
    //     "messagingSettings": {
    //         "allowUserEditMessages": true,
    //         "allowUserDeleteMessages": true,
    //         "allowOwnerDeleteMessages": true,
    //         "allowTeamMentions": true,
    //         "allowChannelMentions": true
    //     },
    //     "discoverySettings": {
    //         "showInTeamsSearchAndSuggestions": true
    //     },
    //     "installedApps": [
    //         {
    //             "teamsApp@odata.bind": "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('com.microsoft.teamspace.tab.vsts')"
    //         },
    //         {
    //             "teamsApp@odata.bind": "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('1542629c-01b3-4a6d-8f76-1938b779e48d')"
    //         }
    //     ]
    // }

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

    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("visibility", "Private") catch {};
    json.updateString("displayName", "Sample Engineering Team") catch {};
    json.updateString("description", "This is a sample engineering team, used to showcase the range of properties supported by this API") catch {};
    json.updateString("channels[0].displayName", "Announcements") catch {};
    json.updateBool("channels[0].isFavoriteByDefault", true) catch {};
    json.updateString("channels[0].description", "This is a sample announcements channel that is favorited by default. Use this channel to make important team, product, and service announcements.") catch {};
    json.updateString("channels[1].displayName", "Training") catch {};
    json.updateBool("channels[1].isFavoriteByDefault", true) catch {};
    json.updateString("channels[1].description", "This is a sample training channel, that is favorited by default, and contains an example of pinned website and YouTube tabs.") catch {};
    json.updateString("channels[1].tabs[0].\"teamsApp@odata.bind\"", "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('com.microsoft.teamspace.tab.web')") catch {};
    json.updateString("channels[1].tabs[0].name", "A Pinned Website") catch {};
    json.updateString("channels[1].tabs[0].configuration.contentUrl", "https://docs.microsoft.com/microsoftteams/microsoft-teams") catch {};
    json.updateString("channels[1].tabs[1].\"teamsApp@odata.bind\"", "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('com.microsoft.teamspace.tab.youtube')") catch {};
    json.updateString("channels[1].tabs[1].name", "A Pinned YouTube Video") catch {};
    json.updateString("channels[1].tabs[1].configuration.contentUrl", "https://tabs.teams.microsoft.com/Youtube/Home/YoutubeTab?videoId=X8krAMdGvCQ") catch {};
    json.updateString("channels[1].tabs[1].configuration.websiteUrl", "https://www.youtube.com/watch?v=X8krAMdGvCQ") catch {};
    json.updateString("channels[2].displayName", "Planning") catch {};
    json.updateString("channels[2].description", "This is a sample of a channel that is not favorited by default, these channels will appear in the more channels overflow menu.") catch {};
    json.updateBool("channels[2].isFavoriteByDefault", false) catch {};
    json.updateString("channels[3].displayName", "Issues and Feedback") catch {};
    json.updateString("channels[3].description", "This is a sample of a channel that is not favorited by default, these channels will appear in the more channels overflow menu.") catch {};
    json.updateBool("memberSettings.allowCreateUpdateChannels", true) catch {};
    json.updateBool("memberSettings.allowDeleteChannels", true) catch {};
    json.updateBool("memberSettings.allowAddRemoveApps", true) catch {};
    json.updateBool("memberSettings.allowCreateUpdateRemoveTabs", true) catch {};
    json.updateBool("memberSettings.allowCreateUpdateRemoveConnectors", true) catch {};
    json.updateBool("guestSettings.allowCreateUpdateChannels", false) catch {};
    json.updateBool("guestSettings.allowDeleteChannels", false) catch {};
    json.updateBool("funSettings.allowGiphy", true) catch {};
    json.updateString("funSettings.giphyContentRating", "Moderate") catch {};
    json.updateBool("funSettings.allowStickersAndMemes", true) catch {};
    json.updateBool("funSettings.allowCustomMemes", true) catch {};
    json.updateBool("messagingSettings.allowUserEditMessages", true) catch {};
    json.updateBool("messagingSettings.allowUserDeleteMessages", true) catch {};
    json.updateBool("messagingSettings.allowOwnerDeleteMessages", true) catch {};
    json.updateBool("messagingSettings.allowTeamMentions", true) catch {};
    json.updateBool("messagingSettings.allowChannelMentions", true) catch {};
    json.updateBool("discoverySettings.showInTeamsSearchAndSuggestions", true) catch {};
    json.updateString("installedApps[0].\"teamsApp@odata.bind\"", "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('com.microsoft.teamspace.tab.vsts')") catch {};
    json.updateString("installedApps[1].\"teamsApp@odata.bind\"", "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('1542629c-01b3-4a6d-8f76-1938b779e48d')") catch {};

    http.setRequestHeader("Content-type", "application/json");

    // 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", .{});
    }
}