PureBasic
PureBasic
Microsoft Teams - Create Team (complex request)
See more Microsoft Teams Examples
Create a team with multiple channels, installed apps, and pinned tabs using delegated permissionsChilkat PureBasic Downloads
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkJsonObject.pb"
Procedure ChilkatExample()
success.i = 0
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; 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.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckUpdateString(json,Chr(34) + "template@odata.bind" + Chr(34),"https://graph.microsoft.com/v1.0/teamsTemplates('standard')")
CkJsonObject::ckUpdateString(json,"visibility","Private")
CkJsonObject::ckUpdateString(json,"displayName","Sample Engineering Team")
CkJsonObject::ckUpdateString(json,"description","This is a sample engineering team, used to showcase the range of properties supported by this API")
CkJsonObject::ckUpdateString(json,"channels[0].displayName","Announcements")
CkJsonObject::ckUpdateBool(json,"channels[0].isFavoriteByDefault",1)
CkJsonObject::ckUpdateString(json,"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.")
CkJsonObject::ckUpdateString(json,"channels[1].displayName","Training")
CkJsonObject::ckUpdateBool(json,"channels[1].isFavoriteByDefault",1)
CkJsonObject::ckUpdateString(json,"channels[1].description","This is a sample training channel, that is favorited by default, and contains an example of pinned website and YouTube tabs.")
CkJsonObject::ckUpdateString(json,"channels[1].tabs[0]." + Chr(34) + "teamsApp@odata.bind" + Chr(34),"https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('com.microsoft.teamspace.tab.web')")
CkJsonObject::ckUpdateString(json,"channels[1].tabs[0].name","A Pinned Website")
CkJsonObject::ckUpdateString(json,"channels[1].tabs[0].configuration.contentUrl","https://docs.microsoft.com/microsoftteams/microsoft-teams")
CkJsonObject::ckUpdateString(json,"channels[1].tabs[1]." + Chr(34) + "teamsApp@odata.bind" + Chr(34),"https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('com.microsoft.teamspace.tab.youtube')")
CkJsonObject::ckUpdateString(json,"channels[1].tabs[1].name","A Pinned YouTube Video")
CkJsonObject::ckUpdateString(json,"channels[1].tabs[1].configuration.contentUrl","https://tabs.teams.microsoft.com/Youtube/Home/YoutubeTab?videoId=X8krAMdGvCQ")
CkJsonObject::ckUpdateString(json,"channels[1].tabs[1].configuration.websiteUrl","https://www.youtube.com/watch?v=X8krAMdGvCQ")
CkJsonObject::ckUpdateString(json,"channels[2].displayName","Planning")
CkJsonObject::ckUpdateString(json,"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.")
CkJsonObject::ckUpdateBool(json,"channels[2].isFavoriteByDefault",0)
CkJsonObject::ckUpdateString(json,"channels[3].displayName","Issues and Feedback")
CkJsonObject::ckUpdateString(json,"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.")
CkJsonObject::ckUpdateBool(json,"memberSettings.allowCreateUpdateChannels",1)
CkJsonObject::ckUpdateBool(json,"memberSettings.allowDeleteChannels",1)
CkJsonObject::ckUpdateBool(json,"memberSettings.allowAddRemoveApps",1)
CkJsonObject::ckUpdateBool(json,"memberSettings.allowCreateUpdateRemoveTabs",1)
CkJsonObject::ckUpdateBool(json,"memberSettings.allowCreateUpdateRemoveConnectors",1)
CkJsonObject::ckUpdateBool(json,"guestSettings.allowCreateUpdateChannels",0)
CkJsonObject::ckUpdateBool(json,"guestSettings.allowDeleteChannels",0)
CkJsonObject::ckUpdateBool(json,"funSettings.allowGiphy",1)
CkJsonObject::ckUpdateString(json,"funSettings.giphyContentRating","Moderate")
CkJsonObject::ckUpdateBool(json,"funSettings.allowStickersAndMemes",1)
CkJsonObject::ckUpdateBool(json,"funSettings.allowCustomMemes",1)
CkJsonObject::ckUpdateBool(json,"messagingSettings.allowUserEditMessages",1)
CkJsonObject::ckUpdateBool(json,"messagingSettings.allowUserDeleteMessages",1)
CkJsonObject::ckUpdateBool(json,"messagingSettings.allowOwnerDeleteMessages",1)
CkJsonObject::ckUpdateBool(json,"messagingSettings.allowTeamMentions",1)
CkJsonObject::ckUpdateBool(json,"messagingSettings.allowChannelMentions",1)
CkJsonObject::ckUpdateBool(json,"discoverySettings.showInTeamsSearchAndSuggestions",1)
CkJsonObject::ckUpdateString(json,"installedApps[0]." + Chr(34) + "teamsApp@odata.bind" + Chr(34),"https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('com.microsoft.teamspace.tab.vsts')")
CkJsonObject::ckUpdateString(json,"installedApps[1]." + Chr(34) + "teamsApp@odata.bind" + Chr(34),"https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('1542629c-01b3-4a6d-8f76-1938b779e48d')")
CkHttp::ckSetRequestHeader(http,"Content-type","application/json")
; Adds the "Authorization: Bearer ACCESS_TOKEN" header.
CkHttp::setCkAuthToken(http, "ACCESS_TOKEN")
resp.i = CkHttpResponse::ckCreate()
If resp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkHttp::ckHttpJson(http,"POST","https://graph.microsoft.com/v1.0/teams",json,"application/json",resp)
If success = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
CkHttpResponse::ckDispose(resp)
ProcedureReturn
EndIf
; A successful response is indicated by a 202 response status code and an empty response body.
Debug "Response Status Code: " + Str(CkHttpResponse::ckStatusCode(resp))
Debug "Response Body:"
Debug CkHttpResponse::ckBodyStr(resp)
If CkHttpResponse::ckStatusCode(resp) >= 400
Debug "Response Header:"
Debug CkHttpResponse::ckHeader(resp)
Debug "Failed."
EndIf
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
CkHttpResponse::ckDispose(resp)
ProcedureReturn
EndProcedure