Sample code for 30+ languages & platforms
PowerBuilder

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

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_Json
oleobject loo_Resp

li_Success = 0

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

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

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.UpdateString("~"template@odata.bind~"","https://graph.microsoft.com/v1.0/teamsTemplates('standard')")
loo_Json.UpdateString("visibility","Private")
loo_Json.UpdateString("displayName","Sample Engineering Team")
loo_Json.UpdateString("description","This is a sample engineering team, used to showcase the range of properties supported by this API")
loo_Json.UpdateString("channels[0].displayName","Announcements")
loo_Json.UpdateBool("channels[0].isFavoriteByDefault",1)
loo_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.")
loo_Json.UpdateString("channels[1].displayName","Training")
loo_Json.UpdateBool("channels[1].isFavoriteByDefault",1)
loo_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.")
loo_Json.UpdateString("channels[1].tabs[0].~"teamsApp@odata.bind~"","https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('com.microsoft.teamspace.tab.web')")
loo_Json.UpdateString("channels[1].tabs[0].name","A Pinned Website")
loo_Json.UpdateString("channels[1].tabs[0].configuration.contentUrl","https://docs.microsoft.com/microsoftteams/microsoft-teams")
loo_Json.UpdateString("channels[1].tabs[1].~"teamsApp@odata.bind~"","https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('com.microsoft.teamspace.tab.youtube')")
loo_Json.UpdateString("channels[1].tabs[1].name","A Pinned YouTube Video")
loo_Json.UpdateString("channels[1].tabs[1].configuration.contentUrl","https://tabs.teams.microsoft.com/Youtube/Home/YoutubeTab?videoId=X8krAMdGvCQ")
loo_Json.UpdateString("channels[1].tabs[1].configuration.websiteUrl","https://www.youtube.com/watch?v=X8krAMdGvCQ")
loo_Json.UpdateString("channels[2].displayName","Planning")
loo_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.")
loo_Json.UpdateBool("channels[2].isFavoriteByDefault",0)
loo_Json.UpdateString("channels[3].displayName","Issues and Feedback")
loo_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.")
loo_Json.UpdateBool("memberSettings.allowCreateUpdateChannels",1)
loo_Json.UpdateBool("memberSettings.allowDeleteChannels",1)
loo_Json.UpdateBool("memberSettings.allowAddRemoveApps",1)
loo_Json.UpdateBool("memberSettings.allowCreateUpdateRemoveTabs",1)
loo_Json.UpdateBool("memberSettings.allowCreateUpdateRemoveConnectors",1)
loo_Json.UpdateBool("guestSettings.allowCreateUpdateChannels",0)
loo_Json.UpdateBool("guestSettings.allowDeleteChannels",0)
loo_Json.UpdateBool("funSettings.allowGiphy",1)
loo_Json.UpdateString("funSettings.giphyContentRating","Moderate")
loo_Json.UpdateBool("funSettings.allowStickersAndMemes",1)
loo_Json.UpdateBool("funSettings.allowCustomMemes",1)
loo_Json.UpdateBool("messagingSettings.allowUserEditMessages",1)
loo_Json.UpdateBool("messagingSettings.allowUserDeleteMessages",1)
loo_Json.UpdateBool("messagingSettings.allowOwnerDeleteMessages",1)
loo_Json.UpdateBool("messagingSettings.allowTeamMentions",1)
loo_Json.UpdateBool("messagingSettings.allowChannelMentions",1)
loo_Json.UpdateBool("discoverySettings.showInTeamsSearchAndSuggestions",1)
loo_Json.UpdateString("installedApps[0].~"teamsApp@odata.bind~"","https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('com.microsoft.teamspace.tab.vsts')")
loo_Json.UpdateString("installedApps[1].~"teamsApp@odata.bind~"","https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('1542629c-01b3-4a6d-8f76-1938b779e48d')")

loo_Http.SetRequestHeader("Content-type","application/json")

// Adds the "Authorization: Bearer ACCESS_TOKEN" header.
loo_Http.AuthToken = "ACCESS_TOKEN"

loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")

li_Success = loo_Http.HttpJson("POST","https://graph.microsoft.com/v1.0/teams",loo_Json,"application/json",loo_Resp)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    destroy loo_Resp
    return
end if

// A successful response is indicated by a 202 response status code and an empty response body.
Write-Debug "Response Status Code: " + string(loo_Resp.StatusCode)
Write-Debug "Response Body:"
Write-Debug loo_Resp.BodyStr

if loo_Resp.StatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
end if



destroy loo_Http
destroy loo_Json
destroy loo_Resp