Sample code for 30+ languages & platforms
DataFlex

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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoHttp
    Variant vJson
    Handle hoJson
    Variant vResp
    Handle hoResp
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

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

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson '"template@odata.bind"' "https://graph.microsoft.com/v1.0/teamsTemplates('standard')" To iSuccess
    Get ComUpdateString Of hoJson "visibility" "Private" To iSuccess
    Get ComUpdateString Of hoJson "displayName" "Sample Engineering Team" To iSuccess
    Get ComUpdateString Of hoJson "description" "This is a sample engineering team, used to showcase the range of properties supported by this API" To iSuccess
    Get ComUpdateString Of hoJson "channels[0].displayName" "Announcements" To iSuccess
    Get ComUpdateBool Of hoJson "channels[0].isFavoriteByDefault" True To iSuccess
    Get ComUpdateString Of hoJson "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." To iSuccess
    Get ComUpdateString Of hoJson "channels[1].displayName" "Training" To iSuccess
    Get ComUpdateBool Of hoJson "channels[1].isFavoriteByDefault" True To iSuccess
    Get ComUpdateString Of hoJson "channels[1].description" "This is a sample training channel, that is favorited by default, and contains an example of pinned website and YouTube tabs." To iSuccess
    Get ComUpdateString Of hoJson 'channels[1].tabs[0]."teamsApp@odata.bind"' "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('com.microsoft.teamspace.tab.web')" To iSuccess
    Get ComUpdateString Of hoJson "channels[1].tabs[0].name" "A Pinned Website" To iSuccess
    Get ComUpdateString Of hoJson "channels[1].tabs[0].configuration.contentUrl" "https://docs.microsoft.com/microsoftteams/microsoft-teams" To iSuccess
    Get ComUpdateString Of hoJson 'channels[1].tabs[1]."teamsApp@odata.bind"' "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('com.microsoft.teamspace.tab.youtube')" To iSuccess
    Get ComUpdateString Of hoJson "channels[1].tabs[1].name" "A Pinned YouTube Video" To iSuccess
    Get ComUpdateString Of hoJson "channels[1].tabs[1].configuration.contentUrl" "https://tabs.teams.microsoft.com/Youtube/Home/YoutubeTab?videoId=X8krAMdGvCQ" To iSuccess
    Get ComUpdateString Of hoJson "channels[1].tabs[1].configuration.websiteUrl" "https://www.youtube.com/watch?v=X8krAMdGvCQ" To iSuccess
    Get ComUpdateString Of hoJson "channels[2].displayName" "Planning" To iSuccess
    Get ComUpdateString Of hoJson "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." To iSuccess
    Get ComUpdateBool Of hoJson "channels[2].isFavoriteByDefault" False To iSuccess
    Get ComUpdateString Of hoJson "channels[3].displayName" "Issues and Feedback" To iSuccess
    Get ComUpdateString Of hoJson "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." To iSuccess
    Get ComUpdateBool Of hoJson "memberSettings.allowCreateUpdateChannels" True To iSuccess
    Get ComUpdateBool Of hoJson "memberSettings.allowDeleteChannels" True To iSuccess
    Get ComUpdateBool Of hoJson "memberSettings.allowAddRemoveApps" True To iSuccess
    Get ComUpdateBool Of hoJson "memberSettings.allowCreateUpdateRemoveTabs" True To iSuccess
    Get ComUpdateBool Of hoJson "memberSettings.allowCreateUpdateRemoveConnectors" True To iSuccess
    Get ComUpdateBool Of hoJson "guestSettings.allowCreateUpdateChannels" False To iSuccess
    Get ComUpdateBool Of hoJson "guestSettings.allowDeleteChannels" False To iSuccess
    Get ComUpdateBool Of hoJson "funSettings.allowGiphy" True To iSuccess
    Get ComUpdateString Of hoJson "funSettings.giphyContentRating" "Moderate" To iSuccess
    Get ComUpdateBool Of hoJson "funSettings.allowStickersAndMemes" True To iSuccess
    Get ComUpdateBool Of hoJson "funSettings.allowCustomMemes" True To iSuccess
    Get ComUpdateBool Of hoJson "messagingSettings.allowUserEditMessages" True To iSuccess
    Get ComUpdateBool Of hoJson "messagingSettings.allowUserDeleteMessages" True To iSuccess
    Get ComUpdateBool Of hoJson "messagingSettings.allowOwnerDeleteMessages" True To iSuccess
    Get ComUpdateBool Of hoJson "messagingSettings.allowTeamMentions" True To iSuccess
    Get ComUpdateBool Of hoJson "messagingSettings.allowChannelMentions" True To iSuccess
    Get ComUpdateBool Of hoJson "discoverySettings.showInTeamsSearchAndSuggestions" True To iSuccess
    Get ComUpdateString Of hoJson 'installedApps[0]."teamsApp@odata.bind"' "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('com.microsoft.teamspace.tab.vsts')" To iSuccess
    Get ComUpdateString Of hoJson 'installedApps[1]."teamsApp@odata.bind"' "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('1542629c-01b3-4a6d-8f76-1938b779e48d')" To iSuccess

    Send ComSetRequestHeader To hoHttp "Content-type" "application/json"

    // Adds the "Authorization: Bearer ACCESS_TOKEN" header.
    Set ComAuthToken Of hoHttp To "ACCESS_TOKEN"

    Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
    If (Not(IsComObjectCreated(hoResp))) Begin
        Send CreateComObject of hoResp
    End
    Get pvComObject of hoJson to vJson
    Get pvComObject of hoResp to vResp
    Get ComHttpJson Of hoHttp "POST" "https://graph.microsoft.com/v1.0/teams" vJson "application/json" vResp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // A successful response is indicated by a 202 response status code and an empty response body.
    Get ComStatusCode Of hoResp To iTemp1
    Showln "Response Status Code: " iTemp1
    Showln "Response Body:"
    Get ComBodyStr Of hoResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iTemp1
    If (iTemp1 >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
    End



End_Procedure