Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

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 Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Http,
  Chilkat.HttpResponse,
  Chilkat.JsonObject;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  http: THttp;
  json: TJsonObject;
  resp: THttpResponse;

begin
  success := False;

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

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

  http.SetRequestHeader('Content-type','application/json');

  //  Adds the "Authorization: Bearer ACCESS_TOKEN" header.
  http.AuthToken := 'ACCESS_TOKEN';

  resp := THttpResponse.Create;
  success := http.HttpJson('POST','https://graph.microsoft.com/v1.0/teams',json,'application/json',resp);
  if (success = False) then
    begin
      WriteLn(http.LastErrorText);
      Exit;
    end;

  //  A successful response is indicated by a 202 response status code and an empty response body.
  WriteLn('Response Status Code: ' + resp.StatusCode);
  WriteLn('Response Body:');
  WriteLn(resp.BodyStr);

  if (resp.StatusCode >= 400) then
    begin
      WriteLn('Response Header:');
      WriteLn(resp.Header);
      WriteLn('Failed.');
    end;


  http.Free;
  json.Free;
  resp.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.