Sample code for 30+ languages & platforms
Unicode C

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 Unicode C Downloads

Unicode C
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpW http;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;

    success = FALSE;

    //  This example assumes the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    //  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

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

    CkHttpW_SetRequestHeader(http,L"Content-type",L"application/json");

    //  Adds the "Authorization: Bearer ACCESS_TOKEN" header.
    CkHttpW_putAuthToken(http,L"ACCESS_TOKEN");

    resp = CkHttpResponseW_Create();
    success = CkHttpW_HttpJson(http,L"POST",L"https://graph.microsoft.com/v1.0/teams",json,L"application/json",resp);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkHttpResponseW_Dispose(resp);
        return;
    }

    //  A successful response is indicated by a 202 response status code and an empty response body.
    wprintf(L"Response Status Code: %d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));

    if (CkHttpResponseW_getStatusCode(resp) >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpResponseW_header(resp));
        wprintf(L"Failed.\n");
    }



    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);
    CkHttpResponseW_Dispose(resp);

    }