创建频道

命名空间:microsoft.graph

根据请求正文中的指定,在团队中创建新 频道 。 创建通道时,通道 displayName 的最大长度为 50 个字符。 这是在 Microsoft Teams 中向用户显示的名称。

如果要创建专用频道,最多可以添加 200 个成员。

注意

  • 通道名称中的某些特殊字符将导致 获取文件Folder API 返回错误。 有关详细信息,请参阅已知问题
  • 创建专用/共享频道时,SharePoint 网站可能无法预配。 如果站点在 5 分钟后无法预配,请使用 Get filesFolder API 触发预配。

此 API 可用于以下国家级云部署

全局服务 美国政府 L4 美国政府 L5 (DOD) 由世纪互联运营的中国

权限

要调用此 API,需要以下权限之一。 若要了解详细信息,包括如何选择权限的信息,请参阅权限

权限类型 权限(从最低特权到最高特权)
委派(工作或学校帐户) Channel.Create、Group.ReadWrite.All、Directory.ReadWrite.All
委派(个人 Microsoft 帐户) 不支持。
应用程序 Channel.Create.Group*、Channel.Create、Teamwork.Migrate.All、Group.ReadWrite.All、Directory.ReadWrite.All

注意:仅支持向后兼容,才支持 Group.ReadWrite.All 和 Directory.ReadWrite.All 权限。 建议更新解决方案,以使用上表中列出的替代权限,并避免今后使用这些权限。 标记为 * 的权限使用 特定于资源的许可

此 API 支持管理员权限。 全局管理员和 Microsoft Teams 服务管理员可以访问自己不是其中成员的团队。

将来,Microsoft 可能会要求你或你的客户根据使用 Teamwork.Migrate.All 和/或 迁移 API 导入的数据量支付额外的费用。

HTTP 请求

POST /teams/{team-id}/channels

请求标头

标头
Authorization 持有者 {token}。 必填。 详细了解 身份验证和授权
Content-Type application/json. 必需。

请求正文

在请求正文中,提供 channel 对象的 JSON 表示形式。

响应

如果成功,此方法在响应正文中为 membershipType 值为 standardprivate的通道返回201 Created响应代码和通道对象。 对于 membershipType 值为 的 shared通道,此方法返回 202 Accepted 响应代码和 teamsAsyncOperation 的链接。

示例

示例 1:创建标准通道

请求

以下示例显示了创建标准通道的请求。

POST https://graph.microsoft.com/v1.0/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"
}

响应

以下示例显示了相应的响应。

注意:为了提高可读性,可能缩短了此处显示的响应对象。

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

示例 2:代表用户创建专用频道

请求

以下示例演示了创建专用频道并将用户添加为团队所有者的请求。

POST https://graph.microsoft.com/v1.0/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/v1.0/users('62855810-484b-4823-9e01-60667f8b12ae')",
           "roles":["owner"]
        }
     ]
}

注意: 若要将来宾帐户添加到通道,对于 roles 属性,请使用 值 guest

响应

以下示例显示了相应的响应。

HTTP/1.1 201 Created
Content-type: application/json

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$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"
}

示例 3:在迁移模式下创建通道

请求

以下示例演示如何创建将用于导入消息的通道。

POST https://graph.microsoft.com/v1.0/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"
}

响应

以下示例显示了相应的响应。 响应中的 Content-Location 标头指定正在预配的通道的路径。 预配后,此通道可用于 导入消息

HTTP/1.1 201 Created
Location: /teams('57fb72d0-d811-46f4-8947-305e6072eaa5')/channels('19:4b6bed8d24574f6a9e436813cb2617d8@thread.tacv2')

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$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
}

示例 4:使用用户主体名称代表用户创建专用频道

请求

以下示例演示了创建专用频道并将用户添加为团队所有者的请求。

POST https://graph.microsoft.com/v1.0/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/v1.0/users('jacob@contoso.com')",
           "roles":["owner"]
        }
     ]
}

注意: 若要将来宾帐户添加到通道,对于 roles 属性,请使用 值 guest

响应

以下示例显示了相应的响应。

HTTP/1.1 201 Created
Content-type: application/json

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$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"
}

示例 5:代表用户创建共享频道

请求

以下示例演示如何创建共享频道。

POST https://graph.microsoft.com/v1.0/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/v1.0/users('7640023f-fe43-573f-9ff4-84a9efe4acd6')",
      "roles": [
        "owner"
      ]
    }
  ]
}

注意: 若要将来宾帐户添加到通道,对于 roles 属性,请使用 值 guest

响应

以下示例显示了相应的响应。

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

示例 7:创建与主机团队共享的共享频道

请求

以下示例演示如何创建与主机团队共享的共享频道。

POST https://graph.microsoft.com/v1.0/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-573f-9ff4-84a9efe4acd6')",
      "roles": [
        "owner"
      ]
    }
  ],
  "sharedWithTeams":[
    {
      "id": "57fb72d0-d811-46f4-8947-305e6072eaa5"
    }
  ]
}

响应

以下示例显示了相应的响应。

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

Microsoft Graph 特定于服务的节流限制