Sample code for 30+ languages & platforms
Lua

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

Lua
local chilkat = require("chilkat")

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

local http = chilkat.Http.new()

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

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

http:set_request_header("Content-type", "application/json")

-- Adds the "Authorization: Bearer ACCESS_TOKEN" header.
http.auth_token = "ACCESS_TOKEN"

local resp = chilkat.HttpResponse.new()
local success = http:http_json("POST", "https://graph.microsoft.com/v1.0/teams", json, "application/json", resp)
if not success then
    print(http.last_error_text)
    return
end

-- A successful response is indicated by a 202 response status code and an empty response body.
print("Response Status Code: " .. resp.status_code)
print("Response Body:")
print(resp.body_str)

if resp.status_code >= 400 then
    print("Response Header:")
    print(resp.header)
    print("Failed.")
end