Namespace: microsoft.graph
Important
APIs under the /beta
version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.
Create a new channel in a team, as specified in the request body. When you create a channel, the maximum length of the channel's displayName
is 50 characters. This display name appears to the user in Microsoft Teams.
You can add a maximum of 200 members when you create a private channel.
Note
- Some special characters in the channel name cause the Get filesFolder API to return an error. For details, see Known issues.
- When you create a private/shared channel, the SharePoint site might fail to provision. If the site fails to provision after 5 minutes, use the Get filesFolder API to trigger provisioning.
- You can create shared channels with only one owner initially. Adding multiple owners results in a
400 Bad Request
error code. After the initial request, you can add more owners using the Add member to channel API.
This API is available in the following national cloud deployments.
Global service |
US Government L4 |
US Government L5 (DOD) |
China operated by 21Vianet |
✅ |
✅ |
✅ |
✅ |
Permissions
Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.
This API supports admin permissions. Microsoft Teams service admins can access teams that they aren't a member of.
Permission type |
Least privileged permissions |
Higher privileged permissions |
Delegated (work or school account) |
Channel.Create |
Directory.ReadWrite.All, Group.ReadWrite.All |
Delegated (personal Microsoft account) |
Not supported. |
Not supported. |
Application |
Channel.Create.Group |
Channel.Create, Directory.ReadWrite.All, Group.ReadWrite.All, Teamwork.Migrate.All |
Note
- The Channel.Create.Group permission uses resource-specific consent.
- The Group.ReadWrite.All and Directory.ReadWrite.All permissions are supported only for backward compatibility. We recommend that you update your solutions to use an alternative permission listed in the previous table and avoid using these permissions going forward.
Note: In the future, Microsoft may require you or your customers to pay additional fees based on the amount of data imported
using Teamwork.Migrate.All and/or migration APIs.
HTTP request
POST /teams/{team-id}/channels
Request body
In the request body, supply a JSON representation of a channel object.
Response
If successful, this method returns a 201 Created
response code and a channel object in the response body for a channel with a membershipType value of standard
or private
. For a channel with a membershipType value of shared
, this method returns a 202 Accepted
response code and a link to the teamsAsyncOperation.
If the request is unsuccessful, this method returns a 400 Bad Request
response code. The following are common reasons for this response:
- createdDateTime is set in the future.
- createdDateTime is correctly specified but the channelCreationMode instance attribute is missing or set to an invalid value.
Examples
Example 1: Create a standard channel
Request
The following example shows a request to create a standard channel.
POST https://graph.microsoft.com/beta/teams/57fb72d0-d811-46f4-8947-305e6072eaa5/channels
Content-type: application/json
{
"displayName": "Architecture Discussion",
"description": "This channel is where we debate all future architecture plans",
"membershipType": "standard"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new Channel
{
DisplayName = "Architecture Discussion",
Description = "This channel is where we debate all future architecture plans",
MembershipType = ChannelMembershipType.Standard,
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Teams["{team-id}"].Channels.PostAsync(requestBody);
mgc-beta teams channels create --team-id {team-id} --body '{\
"displayName": "Architecture Discussion",\
"description": "This channel is where we debate all future architecture plans",\
"membershipType": "standard"\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewChannel()
displayName := "Architecture Discussion"
requestBody.SetDisplayName(&displayName)
description := "This channel is where we debate all future architecture plans"
requestBody.SetDescription(&description)
membershipType := graphmodels.STANDARD_CHANNELMEMBERSHIPTYPE
requestBody.SetMembershipType(&membershipType)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
channels, err := graphClient.Teams().ByTeamId("team-id").Channels().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Channel channel = new Channel();
channel.setDisplayName("Architecture Discussion");
channel.setDescription("This channel is where we debate all future architecture plans");
channel.setMembershipType(ChannelMembershipType.Standard);
Channel result = graphClient.teams().byTeamId("{team-id}").channels().post(channel);
const options = {
authProvider,
};
const client = Client.init(options);
const channel = {
displayName: 'Architecture Discussion',
description: 'This channel is where we debate all future architecture plans',
membershipType: 'standard'
};
await client.api('/teams/57fb72d0-d811-46f4-8947-305e6072eaa5/channels')
.version('beta')
.post(channel);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\Channel;
use Microsoft\Graph\Beta\Generated\Models\ChannelMembershipType;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Channel();
$requestBody->setDisplayName('Architecture Discussion');
$requestBody->setDescription('This channel is where we debate all future architecture plans');
$requestBody->setMembershipType(new ChannelMembershipType('standard'));
$result = $graphServiceClient->teams()->byTeamId('team-id')->channels()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Teams
$params = @{
displayName = "Architecture Discussion"
description = "This channel is where we debate all future architecture plans"
membershipType = "standard"
}
New-MgBetaTeamChannel -TeamId $teamId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.channel import Channel
from msgraph_beta.generated.models.channel_membership_type import ChannelMembershipType
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Channel(
display_name = "Architecture Discussion",
description = "This channel is where we debate all future architecture plans",
membership_type = ChannelMembershipType.Standard,
)
result = await graph_client.teams.by_team_id('team-id').channels.post(request_body)
Response
The following example shows the response.
Note: The response object shown here might be shortened for readability.
HTTP/1.1 201 Created
Content-type: application/json
{
"id": "19:4b6bed8d24574f6a9e436813cb2617d8@thread.tacv2",
"displayName": "Architecture Discussion",
"description": "This channel is where we debate all future architecture plans"
}
Example 2: Create private channel on behalf of user
Request
The following example shows a request to create a private channel and add a user as a team owner.
POST https://graph.microsoft.com/beta/teams/57fb72d0-d811-46f4-8947-305e6072eaa5/channels
Content-type: application/json
{
"@odata.type": "#Microsoft.Graph.channel",
"membershipType": "private",
"displayName": "My First Private Channel",
"description": "This is my first private channels",
"members":
[
{
"@odata.type":"#microsoft.graph.aadUserConversationMember",
"user@odata.bind":"https://graph.microsoft.com/beta/users('62855810-484b-4823-9e01-60667f8b12ae')",
"roles":["owner"]
}
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new Channel
{
OdataType = "#Microsoft.Graph.channel",
MembershipType = ChannelMembershipType.Private,
DisplayName = "My First Private Channel",
Description = "This is my first private channels",
Members = new List<ConversationMember>
{
new AadUserConversationMember
{
OdataType = "#microsoft.graph.aadUserConversationMember",
Roles = new List<string>
{
"owner",
},
AdditionalData = new Dictionary<string, object>
{
{
"user@odata.bind" , "https://graph.microsoft.com/beta/users('62855810-484b-4823-9e01-60667f8b12ae')"
},
},
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Teams["{team-id}"].Channels.PostAsync(requestBody);
mgc-beta teams channels create --team-id {team-id} --body '{\
"@odata.type": "#Microsoft.Graph.channel",\
"membershipType": "private",\
"displayName": "My First Private Channel",\
"description": "This is my first private channels",\
"members":\
[\
{\
"@odata.type":"#microsoft.graph.aadUserConversationMember",\
"user@odata.bind":"https://graph.microsoft.com/beta/users('62855810-484b-4823-9e01-60667f8b12ae')",\
"roles":["owner"]\
}\
]\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewChannel()
membershipType := graphmodels.PRIVATE_CHANNELMEMBERSHIPTYPE
requestBody.SetMembershipType(&membershipType)
displayName := "My First Private Channel"
requestBody.SetDisplayName(&displayName)
description := "This is my first private channels"
requestBody.SetDescription(&description)
conversationMember := graphmodels.NewAadUserConversationMember()
roles := []string {
"owner",
}
conversationMember.SetRoles(roles)
additionalData := map[string]interface{}{
"user@odata.bind" : "https://graph.microsoft.com/beta/users('62855810-484b-4823-9e01-60667f8b12ae')",
}
conversationMember.SetAdditionalData(additionalData)
members := []graphmodels.ConversationMemberable {
conversationMember,
}
requestBody.SetMembers(members)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
channels, err := graphClient.Teams().ByTeamId("team-id").Channels().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Channel channel = new Channel();
channel.setOdataType("#Microsoft.Graph.channel");
channel.setMembershipType(ChannelMembershipType.Private);
channel.setDisplayName("My First Private Channel");
channel.setDescription("This is my first private channels");
LinkedList<ConversationMember> members = new LinkedList<ConversationMember>();
AadUserConversationMember conversationMember = new AadUserConversationMember();
conversationMember.setOdataType("#microsoft.graph.aadUserConversationMember");
LinkedList<String> roles = new LinkedList<String>();
roles.add("owner");
conversationMember.setRoles(roles);
HashMap<String, Object> additionalData = new HashMap<String, Object>();
additionalData.put("user@odata.bind", "https://graph.microsoft.com/beta/users('62855810-484b-4823-9e01-60667f8b12ae')");
conversationMember.setAdditionalData(additionalData);
members.add(conversationMember);
channel.setMembers(members);
Channel result = graphClient.teams().byTeamId("{team-id}").channels().post(channel);
const options = {
authProvider,
};
const client = Client.init(options);
const channel = {
'@odata.type': '#Microsoft.Graph.channel',
membershipType: 'private',
displayName: 'My First Private Channel',
description: 'This is my first private channels',
members:
[
{
'@odata.type':'#microsoft.graph.aadUserConversationMember',
'user@odata.bind':'https://graph.microsoft.com/beta/users(\'62855810-484b-4823-9e01-60667f8b12ae\')',
roles: ['owner']
}
]
};
await client.api('/teams/57fb72d0-d811-46f4-8947-305e6072eaa5/channels')
.version('beta')
.post(channel);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\Channel;
use Microsoft\Graph\Beta\Generated\Models\ChannelMembershipType;
use Microsoft\Graph\Beta\Generated\Models\ConversationMember;
use Microsoft\Graph\Beta\Generated\Models\AadUserConversationMember;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Channel();
$requestBody->setOdataType('#Microsoft.Graph.channel');
$requestBody->setMembershipType(new ChannelMembershipType('private'));
$requestBody->setDisplayName('My First Private Channel');
$requestBody->setDescription('This is my first private channels');
$membersConversationMember1 = new AadUserConversationMember();
$membersConversationMember1->setOdataType('#microsoft.graph.aadUserConversationMember');
$membersConversationMember1->setRoles(['owner', ]);
$additionalData = [
'user@odata.bind' => 'https://graph.microsoft.com/beta/users(\'62855810-484b-4823-9e01-60667f8b12ae\')',
];
$membersConversationMember1->setAdditionalData($additionalData);
$membersArray []= $membersConversationMember1;
$requestBody->setMembers($membersArray);
$result = $graphServiceClient->teams()->byTeamId('team-id')->channels()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Teams
$params = @{
"@odata.type" = "#Microsoft.Graph.channel"
membershipType = "private"
displayName = "My First Private Channel"
description = "This is my first private channels"
members = @(
@{
"@odata.type" = "#microsoft.graph.aadUserConversationMember"
"user@odata.bind" = "https://graph.microsoft.com/beta/users('62855810-484b-4823-9e01-60667f8b12ae')"
roles = @(
"owner"
)
}
)
}
New-MgBetaTeamChannel -TeamId $teamId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.channel import Channel
from msgraph_beta.generated.models.channel_membership_type import ChannelMembershipType
from msgraph_beta.generated.models.conversation_member import ConversationMember
from msgraph_beta.generated.models.aad_user_conversation_member import AadUserConversationMember
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Channel(
odata_type = "#Microsoft.Graph.channel",
membership_type = ChannelMembershipType.Private,
display_name = "My First Private Channel",
description = "This is my first private channels",
members = [
AadUserConversationMember(
odata_type = "#microsoft.graph.aadUserConversationMember",
roles = [
"owner",
],
additional_data = {
"user@odata_bind" : "https://graph.microsoft.com/beta/users('62855810-484b-4823-9e01-60667f8b12ae')",
}
),
],
)
result = await graph_client.teams.by_team_id('team-id').channels.post(request_body)
Note: To add a guest account to the channel, for the roles property, use the value guest
.
Response
The following example shows the response.
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#teams('57fb72d0-d811-46f4-8947-305e6072eaa5')/channels/$entity",
"id": "19:33b76eea88574bd1969dca37e2b7a819@thread.skype",
"displayName": "My First Private Channel",
"description": "This is my first private channels",
"isFavoriteByDefault": null,
"email": "",
"webUrl": "https://teams.microsoft.com/l/channel/19:33b76eea88574bd1969dca37e2b7a819@thread.skype/My%20First%20Private%20Channel?groupId=57fb72d0-d811-46f4-8947-305e6072eaa5&tenantId=0fddfdc5-f319-491f-a514-be1bc1bf9ddc",
"membershipType": "private"
}
Example 3: Create a channel in migration mode
Request
The following example shows how to create a channel for importing messages.
POST https://graph.microsoft.com/beta/teams/57fb72d0-d811-46f4-8947-305e6072eaa5/channels
Content-Type: application/json
{
"@microsoft.graph.channelCreationMode": "migration",
"displayName": "Import_150958_99z",
"description": "Import_150958_99z",
"createdDateTime": "2020-03-14T11:22:17.067Z"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new Channel
{
DisplayName = "Import_150958_99z",
Description = "Import_150958_99z",
CreatedDateTime = DateTimeOffset.Parse("2020-03-14T11:22:17.067Z"),
AdditionalData = new Dictionary<string, object>
{
{
"@microsoft.graph.channelCreationMode" , "migration"
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Teams["{team-id}"].Channels.PostAsync(requestBody);
mgc-beta teams channels create --team-id {team-id} --body '{\
"@microsoft.graph.channelCreationMode": "migration",\
"displayName": "Import_150958_99z",\
"description": "Import_150958_99z",\
"createdDateTime": "2020-03-14T11:22:17.067Z"\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
"time"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewChannel()
displayName := "Import_150958_99z"
requestBody.SetDisplayName(&displayName)
description := "Import_150958_99z"
requestBody.SetDescription(&description)
createdDateTime , err := time.Parse(time.RFC3339, "2020-03-14T11:22:17.067Z")
requestBody.SetCreatedDateTime(&createdDateTime)
additionalData := map[string]interface{}{
"@microsoft.graph.channelCreationMode" : "migration",
}
requestBody.SetAdditionalData(additionalData)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
channels, err := graphClient.Teams().ByTeamId("team-id").Channels().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Channel channel = new Channel();
channel.setDisplayName("Import_150958_99z");
channel.setDescription("Import_150958_99z");
OffsetDateTime createdDateTime = OffsetDateTime.parse("2020-03-14T11:22:17.067Z");
channel.setCreatedDateTime(createdDateTime);
HashMap<String, Object> additionalData = new HashMap<String, Object>();
additionalData.put("@microsoft.graph.channelCreationMode", "migration");
channel.setAdditionalData(additionalData);
Channel result = graphClient.teams().byTeamId("{team-id}").channels().post(channel);
const options = {
authProvider,
};
const client = Client.init(options);
const channel = {
'@microsoft.graph.channelCreationMode': 'migration',
displayName: 'Import_150958_99z',
description: 'Import_150958_99z',
createdDateTime: '2020-03-14T11:22:17.067Z'
};
await client.api('/teams/57fb72d0-d811-46f4-8947-305e6072eaa5/channels')
.version('beta')
.post(channel);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\Channel;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Channel();
$requestBody->setDisplayName('Import_150958_99z');
$requestBody->setDescription('Import_150958_99z');
$requestBody->setCreatedDateTime(new \DateTime('2020-03-14T11:22:17.067Z'));
$additionalData = [
'@microsoft.graph.channelCreationMode' => 'migration',
];
$requestBody->setAdditionalData($additionalData);
$result = $graphServiceClient->teams()->byTeamId('team-id')->channels()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Teams
$params = @{
"@microsoft.graph.channelCreationMode" = "migration"
displayName = "Import_150958_99z"
description = "Import_150958_99z"
createdDateTime = [System.DateTime]::Parse("2020-03-14T11:22:17.067Z")
}
New-MgBetaTeamChannel -TeamId $teamId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.channel import Channel
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Channel(
display_name = "Import_150958_99z",
description = "Import_150958_99z",
created_date_time = "2020-03-14T11:22:17.067Z",
additional_data = {
"@microsoft_graph_channel_creation_mode" : "migration",
}
)
result = await graph_client.teams.by_team_id('team-id').channels.post(request_body)
Response
The following example shows the response. The Content-Location
header in the response specifies the path to the channel that is being provisioned.
Once provisioned, this channel can be used for importing messages.
HTTP/1.1 201 Created
Location: /teams('57fb72d0-d811-46f4-8947-305e6072eaa5')/channels('19:4b6bed8d24574f6a9e436813cb2617d8@thread.tacv2')
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#teams('57fb72d0-d811-46f4-8947-305e6072eaa5')/channels/$entity",
"id": "19:987c7a9fbe6447ccb3ea31bcded5c75c@thread.tacv2",
"createdDateTime": null,
"displayName": "Import_150958_99z",
"description": "Import_150958_99z",
"isFavoriteByDefault": null,
"email": null,
"webUrl": null,
"membershipType": null,
"moderationSettings": null
}
Example 4: Create standard channel with moderation settings
Request
The following example shows a request to create a standard channel with moderation settings. This operation can only be performed for a standard channel.
POST https://graph.microsoft.com/beta/teams/57fb72d0-d811-46f4-8947-305e6072eaa5/channels
Content-type: application/json
{
"displayName": "TestChannelModeration",
"description": "Test channel moderation.",
"membershipType": "standard",
"moderationSettings": {
"userNewMessageRestriction": "everyoneExceptGuests",
"replyRestriction": "everyone",
"allowNewMessageFromBots": true,
"allowNewMessageFromConnectors": true
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new Channel
{
DisplayName = "TestChannelModeration",
Description = "Test channel moderation.",
MembershipType = ChannelMembershipType.Standard,
ModerationSettings = new ChannelModerationSettings
{
UserNewMessageRestriction = UserNewMessageRestriction.EveryoneExceptGuests,
ReplyRestriction = ReplyRestriction.Everyone,
AllowNewMessageFromBots = true,
AllowNewMessageFromConnectors = true,
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Teams["{team-id}"].Channels.PostAsync(requestBody);
mgc-beta teams channels create --team-id {team-id} --body '{\
"displayName": "TestChannelModeration",\
"description": "Test channel moderation.",\
"membershipType": "standard",\
"moderationSettings": {\
"userNewMessageRestriction": "everyoneExceptGuests",\
"replyRestriction": "everyone",\
"allowNewMessageFromBots": true,\
"allowNewMessageFromConnectors": true\
}\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewChannel()
displayName := "TestChannelModeration"
requestBody.SetDisplayName(&displayName)
description := "Test channel moderation."
requestBody.SetDescription(&description)
membershipType := graphmodels.STANDARD_CHANNELMEMBERSHIPTYPE
requestBody.SetMembershipType(&membershipType)
moderationSettings := graphmodels.NewChannelModerationSettings()
userNewMessageRestriction := graphmodels.EVERYONEEXCEPTGUESTS_USERNEWMESSAGERESTRICTION
moderationSettings.SetUserNewMessageRestriction(&userNewMessageRestriction)
replyRestriction := graphmodels.EVERYONE_REPLYRESTRICTION
moderationSettings.SetReplyRestriction(&replyRestriction)
allowNewMessageFromBots := true
moderationSettings.SetAllowNewMessageFromBots(&allowNewMessageFromBots)
allowNewMessageFromConnectors := true
moderationSettings.SetAllowNewMessageFromConnectors(&allowNewMessageFromConnectors)
requestBody.SetModerationSettings(moderationSettings)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
channels, err := graphClient.Teams().ByTeamId("team-id").Channels().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Channel channel = new Channel();
channel.setDisplayName("TestChannelModeration");
channel.setDescription("Test channel moderation.");
channel.setMembershipType(ChannelMembershipType.Standard);
ChannelModerationSettings moderationSettings = new ChannelModerationSettings();
moderationSettings.setUserNewMessageRestriction(UserNewMessageRestriction.EveryoneExceptGuests);
moderationSettings.setReplyRestriction(ReplyRestriction.Everyone);
moderationSettings.setAllowNewMessageFromBots(true);
moderationSettings.setAllowNewMessageFromConnectors(true);
channel.setModerationSettings(moderationSettings);
Channel result = graphClient.teams().byTeamId("{team-id}").channels().post(channel);
const options = {
authProvider,
};
const client = Client.init(options);
const channel = {
displayName: 'TestChannelModeration',
description: 'Test channel moderation.',
membershipType: 'standard',
moderationSettings: {
userNewMessageRestriction: 'everyoneExceptGuests',
replyRestriction: 'everyone',
allowNewMessageFromBots: true,
allowNewMessageFromConnectors: true
}
};
await client.api('/teams/57fb72d0-d811-46f4-8947-305e6072eaa5/channels')
.version('beta')
.post(channel);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\Channel;
use Microsoft\Graph\Beta\Generated\Models\ChannelMembershipType;
use Microsoft\Graph\Beta\Generated\Models\ChannelModerationSettings;
use Microsoft\Graph\Beta\Generated\Models\UserNewMessageRestriction;
use Microsoft\Graph\Beta\Generated\Models\ReplyRestriction;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Channel();
$requestBody->setDisplayName('TestChannelModeration');
$requestBody->setDescription('Test channel moderation.');
$requestBody->setMembershipType(new ChannelMembershipType('standard'));
$moderationSettings = new ChannelModerationSettings();
$moderationSettings->setUserNewMessageRestriction(new UserNewMessageRestriction('everyoneExceptGuests'));
$moderationSettings->setReplyRestriction(new ReplyRestriction('everyone'));
$moderationSettings->setAllowNewMessageFromBots(true);
$moderationSettings->setAllowNewMessageFromConnectors(true);
$requestBody->setModerationSettings($moderationSettings);
$result = $graphServiceClient->teams()->byTeamId('team-id')->channels()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Teams
$params = @{
displayName = "TestChannelModeration"
description = "Test channel moderation."
membershipType = "standard"
moderationSettings = @{
userNewMessageRestriction = "everyoneExceptGuests"
replyRestriction = "everyone"
allowNewMessageFromBots = $true
allowNewMessageFromConnectors = $true
}
}
New-MgBetaTeamChannel -TeamId $teamId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.channel import Channel
from msgraph_beta.generated.models.channel_membership_type import ChannelMembershipType
from msgraph_beta.generated.models.channel_moderation_settings import ChannelModerationSettings
from msgraph_beta.generated.models.user_new_message_restriction import UserNewMessageRestriction
from msgraph_beta.generated.models.reply_restriction import ReplyRestriction
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Channel(
display_name = "TestChannelModeration",
description = "Test channel moderation.",
membership_type = ChannelMembershipType.Standard,
moderation_settings = ChannelModerationSettings(
user_new_message_restriction = UserNewMessageRestriction.EveryoneExceptGuests,
reply_restriction = ReplyRestriction.Everyone,
allow_new_message_from_bots = True,
allow_new_message_from_connectors = True,
),
)
result = await graph_client.teams.by_team_id('team-id').channels.post(request_body)
Response
The following example shows the response.
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#teams('57fb72d0-d811-46f4-8947-305e6072eaa5')/channels/$entity",
"id": "19:12b76eea88574bd1969dca37e2b7a819@thread.skype",
"displayName": "My First Private Channel",
"description": "This is my first private channels",
"isFavoriteByDefault": null,
"email": "",
"webUrl": "https://teams.microsoft.com/l/channel/19:12b76eea88574bd1969dca37e2b7a819@thread.skype/My%20First%20Private%20Channel?groupId=57fb72d0-d811-46f4-8947-305e6072eaa5&tenantId=0fddfdc5-f319-491f-a514-be1bc1bf9ddc",
"membershipType": "standard"
}
Example 5: Create private channel on behalf of user using user principal name
Request
The following example shows a request to create a private channel and add a user as a team owner.
POST https://graph.microsoft.com/beta/teams/57fb72d0-d811-46f4-8947-305e6072eaa5/channels
Content-type: application/json
{
"@odata.type": "#Microsoft.Graph.channel",
"membershipType": "private",
"displayName": "My First Private Channel",
"description": "This is my first private channels",
"members":
[
{
"@odata.type":"#microsoft.graph.aadUserConversationMember",
"user@odata.bind":"https://graph.microsoft.com/beta/users('jacob@contoso.com')",
"roles":["owner"]
}
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new Channel
{
OdataType = "#Microsoft.Graph.channel",
MembershipType = ChannelMembershipType.Private,
DisplayName = "My First Private Channel",
Description = "This is my first private channels",
Members = new List<ConversationMember>
{
new AadUserConversationMember
{
OdataType = "#microsoft.graph.aadUserConversationMember",
Roles = new List<string>
{
"owner",
},
AdditionalData = new Dictionary<string, object>
{
{
"user@odata.bind" , "https://graph.microsoft.com/beta/users('jacob@contoso.com')"
},
},
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Teams["{team-id}"].Channels.PostAsync(requestBody);
mgc-beta teams channels create --team-id {team-id} --body '{\
"@odata.type": "#Microsoft.Graph.channel",\
"membershipType": "private",\
"displayName": "My First Private Channel",\
"description": "This is my first private channels",\
"members":\
[\
{\
"@odata.type":"#microsoft.graph.aadUserConversationMember",\
"user@odata.bind":"https://graph.microsoft.com/beta/users('jacob@contoso.com')",\
"roles":["owner"]\
}\
]\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewChannel()
membershipType := graphmodels.PRIVATE_CHANNELMEMBERSHIPTYPE
requestBody.SetMembershipType(&membershipType)
displayName := "My First Private Channel"
requestBody.SetDisplayName(&displayName)
description := "This is my first private channels"
requestBody.SetDescription(&description)
conversationMember := graphmodels.NewAadUserConversationMember()
roles := []string {
"owner",
}
conversationMember.SetRoles(roles)
additionalData := map[string]interface{}{
"user@odata.bind" : "https://graph.microsoft.com/beta/users('jacob@contoso.com')",
}
conversationMember.SetAdditionalData(additionalData)
members := []graphmodels.ConversationMemberable {
conversationMember,
}
requestBody.SetMembers(members)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
channels, err := graphClient.Teams().ByTeamId("team-id").Channels().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Channel channel = new Channel();
channel.setOdataType("#Microsoft.Graph.channel");
channel.setMembershipType(ChannelMembershipType.Private);
channel.setDisplayName("My First Private Channel");
channel.setDescription("This is my first private channels");
LinkedList<ConversationMember> members = new LinkedList<ConversationMember>();
AadUserConversationMember conversationMember = new AadUserConversationMember();
conversationMember.setOdataType("#microsoft.graph.aadUserConversationMember");
LinkedList<String> roles = new LinkedList<String>();
roles.add("owner");
conversationMember.setRoles(roles);
HashMap<String, Object> additionalData = new HashMap<String, Object>();
additionalData.put("user@odata.bind", "https://graph.microsoft.com/beta/users('jacob@contoso.com')");
conversationMember.setAdditionalData(additionalData);
members.add(conversationMember);
channel.setMembers(members);
Channel result = graphClient.teams().byTeamId("{team-id}").channels().post(channel);
const options = {
authProvider,
};
const client = Client.init(options);
const channel = {
'@odata.type': '#Microsoft.Graph.channel',
membershipType: 'private',
displayName: 'My First Private Channel',
description: 'This is my first private channels',
members:
[
{
'@odata.type':'#microsoft.graph.aadUserConversationMember',
'user@odata.bind':'https://graph.microsoft.com/beta/users(\'jacob@contoso.com\')',
roles: ['owner']
}
]
};
await client.api('/teams/57fb72d0-d811-46f4-8947-305e6072eaa5/channels')
.version('beta')
.post(channel);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\Channel;
use Microsoft\Graph\Beta\Generated\Models\ChannelMembershipType;
use Microsoft\Graph\Beta\Generated\Models\ConversationMember;
use Microsoft\Graph\Beta\Generated\Models\AadUserConversationMember;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Channel();
$requestBody->setOdataType('#Microsoft.Graph.channel');
$requestBody->setMembershipType(new ChannelMembershipType('private'));
$requestBody->setDisplayName('My First Private Channel');
$requestBody->setDescription('This is my first private channels');
$membersConversationMember1 = new AadUserConversationMember();
$membersConversationMember1->setOdataType('#microsoft.graph.aadUserConversationMember');
$membersConversationMember1->setRoles(['owner', ]);
$additionalData = [
'user@odata.bind' => 'https://graph.microsoft.com/beta/users(\'jacob@contoso.com\')',
];
$membersConversationMember1->setAdditionalData($additionalData);
$membersArray []= $membersConversationMember1;
$requestBody->setMembers($membersArray);
$result = $graphServiceClient->teams()->byTeamId('team-id')->channels()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Teams
$params = @{
"@odata.type" = "#Microsoft.Graph.channel"
membershipType = "private"
displayName = "My First Private Channel"
description = "This is my first private channels"
members = @(
@{
"@odata.type" = "#microsoft.graph.aadUserConversationMember"
"user@odata.bind" = "https://graph.microsoft.com/beta/users('jacob@contoso.com')"
roles = @(
"owner"
)
}
)
}
New-MgBetaTeamChannel -TeamId $teamId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.channel import Channel
from msgraph_beta.generated.models.channel_membership_type import ChannelMembershipType
from msgraph_beta.generated.models.conversation_member import ConversationMember
from msgraph_beta.generated.models.aad_user_conversation_member import AadUserConversationMember
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Channel(
odata_type = "#Microsoft.Graph.channel",
membership_type = ChannelMembershipType.Private,
display_name = "My First Private Channel",
description = "This is my first private channels",
members = [
AadUserConversationMember(
odata_type = "#microsoft.graph.aadUserConversationMember",
roles = [
"owner",
],
additional_data = {
"user@odata_bind" : "https://graph.microsoft.com/beta/users('jacob@contoso.com')",
}
),
],
)
result = await graph_client.teams.by_team_id('team-id').channels.post(request_body)
Note: To add a guest account to the channel, for the roles property, use the value guest
.
Response
The following example shows the response.
HTTP/1.1 201 Created
Content-Type: application/json
Content-Length: 0
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#teams('57fb72d0-d811-46f4-8947-305e6072eaa5')/channels/$entity",
"id": "19:33b76eea88574bd1969dca37e2b7a819@thread.skype",
"displayName": "My First Private Channel",
"description": "This is my first private channels",
"isFavoriteByDefault": null,
"email": "",
"webUrl": "https://teams.microsoft.com/l/channel/19:33b76eea88574bd1969dca37e2b7a819@thread.skype/My%20First%20Private%20Channel?groupId=57fb72d0-d811-46f4-8947-305e6072eaa5&tenantId=0fddfdc5-f319-491f-a514-be1bc1bf9ddc",
"membershipType": "private"
}
Example 6: Create a shared channel on behalf of a user
Request
The following example shows how to create a shared channel.
POST https://graph.microsoft.com/beta/teams/57fb72d0-d811-46f4-8947-305e6072eaa5/channels
Content-type: application/json
{
"displayName": "My First Shared Channel",
"description": "This is my first shared channel",
"membershipType": "shared",
"members": [
{
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"user@odata.bind": "https://graph.microsoft.com/beta/users('7640023f-fe43-gv3f-9gg4-84a9efe4acd6')",
"roles": [
"owner"
]
}
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new Channel
{
DisplayName = "My First Shared Channel",
Description = "This is my first shared channel",
MembershipType = ChannelMembershipType.Shared,
Members = new List<ConversationMember>
{
new AadUserConversationMember
{
OdataType = "#microsoft.graph.aadUserConversationMember",
Roles = new List<string>
{
"owner",
},
AdditionalData = new Dictionary<string, object>
{
{
"user@odata.bind" , "https://graph.microsoft.com/beta/users('7640023f-fe43-gv3f-9gg4-84a9efe4acd6')"
},
},
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Teams["{team-id}"].Channels.PostAsync(requestBody);
mgc-beta teams channels create --team-id {team-id} --body '{\
"displayName": "My First Shared Channel",\
"description": "This is my first shared channel",\
"membershipType": "shared",\
"members": [\
{\
"@odata.type": "#microsoft.graph.aadUserConversationMember",\
"user@odata.bind": "https://graph.microsoft.com/beta/users('7640023f-fe43-gv3f-9gg4-84a9efe4acd6')",\
"roles": [\
"owner"\
]\
}\
]\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewChannel()
displayName := "My First Shared Channel"
requestBody.SetDisplayName(&displayName)
description := "This is my first shared channel"
requestBody.SetDescription(&description)
membershipType := graphmodels.SHARED_CHANNELMEMBERSHIPTYPE
requestBody.SetMembershipType(&membershipType)
conversationMember := graphmodels.NewAadUserConversationMember()
roles := []string {
"owner",
}
conversationMember.SetRoles(roles)
additionalData := map[string]interface{}{
"user@odata.bind" : "https://graph.microsoft.com/beta/users('7640023f-fe43-gv3f-9gg4-84a9efe4acd6')",
}
conversationMember.SetAdditionalData(additionalData)
members := []graphmodels.ConversationMemberable {
conversationMember,
}
requestBody.SetMembers(members)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
channels, err := graphClient.Teams().ByTeamId("team-id").Channels().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Channel channel = new Channel();
channel.setDisplayName("My First Shared Channel");
channel.setDescription("This is my first shared channel");
channel.setMembershipType(ChannelMembershipType.Shared);
LinkedList<ConversationMember> members = new LinkedList<ConversationMember>();
AadUserConversationMember conversationMember = new AadUserConversationMember();
conversationMember.setOdataType("#microsoft.graph.aadUserConversationMember");
LinkedList<String> roles = new LinkedList<String>();
roles.add("owner");
conversationMember.setRoles(roles);
HashMap<String, Object> additionalData = new HashMap<String, Object>();
additionalData.put("user@odata.bind", "https://graph.microsoft.com/beta/users('7640023f-fe43-gv3f-9gg4-84a9efe4acd6')");
conversationMember.setAdditionalData(additionalData);
members.add(conversationMember);
channel.setMembers(members);
Channel result = graphClient.teams().byTeamId("{team-id}").channels().post(channel);
const options = {
authProvider,
};
const client = Client.init(options);
const channel = {
displayName: 'My First Shared Channel',
description: 'This is my first shared channel',
membershipType: 'shared',
members: [
{
'@odata.type': '#microsoft.graph.aadUserConversationMember',
'user@odata.bind': 'https://graph.microsoft.com/beta/users(\'7640023f-fe43-gv3f-9gg4-84a9efe4acd6\')',
roles: [
'owner'
]
}
]
};
await client.api('/teams/57fb72d0-d811-46f4-8947-305e6072eaa5/channels')
.version('beta')
.post(channel);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\Channel;
use Microsoft\Graph\Beta\Generated\Models\ChannelMembershipType;
use Microsoft\Graph\Beta\Generated\Models\ConversationMember;
use Microsoft\Graph\Beta\Generated\Models\AadUserConversationMember;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Channel();
$requestBody->setDisplayName('My First Shared Channel');
$requestBody->setDescription('This is my first shared channel');
$requestBody->setMembershipType(new ChannelMembershipType('shared'));
$membersConversationMember1 = new AadUserConversationMember();
$membersConversationMember1->setOdataType('#microsoft.graph.aadUserConversationMember');
$membersConversationMember1->setRoles(['owner', ]);
$additionalData = [
'user@odata.bind' => 'https://graph.microsoft.com/beta/users(\'7640023f-fe43-gv3f-9gg4-84a9efe4acd6\')',
];
$membersConversationMember1->setAdditionalData($additionalData);
$membersArray []= $membersConversationMember1;
$requestBody->setMembers($membersArray);
$result = $graphServiceClient->teams()->byTeamId('team-id')->channels()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Teams
$params = @{
displayName = "My First Shared Channel"
description = "This is my first shared channel"
membershipType = "shared"
members = @(
@{
"@odata.type" = "#microsoft.graph.aadUserConversationMember"
"user@odata.bind" = "https://graph.microsoft.com/beta/users('7640023f-fe43-gv3f-9gg4-84a9efe4acd6')"
roles = @(
"owner"
)
}
)
}
New-MgBetaTeamChannel -TeamId $teamId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.channel import Channel
from msgraph_beta.generated.models.channel_membership_type import ChannelMembershipType
from msgraph_beta.generated.models.conversation_member import ConversationMember
from msgraph_beta.generated.models.aad_user_conversation_member import AadUserConversationMember
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Channel(
display_name = "My First Shared Channel",
description = "This is my first shared channel",
membership_type = ChannelMembershipType.Shared,
members = [
AadUserConversationMember(
odata_type = "#microsoft.graph.aadUserConversationMember",
roles = [
"owner",
],
additional_data = {
"user@odata_bind" : "https://graph.microsoft.com/beta/users('7640023f-fe43-gv3f-9gg4-84a9efe4acd6')",
}
),
],
)
result = await graph_client.teams.by_team_id('team-id').channels.post(request_body)
Note: To add a guest account to the channel, for the roles property, use the value guest
.
Response
The following example shows the response.
HTTP/1.1 202 Accepted
Content-Type: application/json
Content-Location: /teams/7640023f-fe43-4cc7-9bd3-84a9efe4acd6/operations/359d75f6-2bb8-4785-ab2d-377bf3d573fa
Content-Length: 0
Example 7: Create a shared channel shared with host team
Request
The following example shows how to create a shared channel shared with host team.
POST https://graph.microsoft.com/beta/teams/57fb72d0-d811-46f4-8947-305e6072eaa5/channels
Content-type: application/json
{
"displayName": "My First Shared Channel",
"description": "This is my first shared channel",
"membershipType": "shared",
"members": [
{
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"user@odata.bind": "https://graph.microsoft.com/beta/users('7640023f-fe43-gv3f-9gg4-84a9efe4acd6')",
"roles": [
"owner"
]
}
],
"sharedWithTeams":[
{
"id": "57fb72d0-d811-46f4-8947-305e6072eaa5"
}
]
}
Response
The following example shows the response.
HTTP/1.1 202 Accepted
Content-Type: application/json
Content-Location: /teams/7640023f-fe43-4cc7-9bd3-84a9efe4acd6/operations/359d75f6-2bb8-4785-ab2d-377bf3d573fa
Content-Length: 0
Related content