使用 v1.0 团队图形 API 创建团队团队Microsoft获取频道名称不得为空



我们使用Microsoft Graph API "POST teams/v1.0"以编程方式创建Microsoft团队。此终结点允许创建具有预定义内容(如设置、应用、频道和选项卡)的团队。但是,在尝试创建具有预定义选项卡的团队时,我们开始遇到今天的问题。该问题可以在Microsoft图形资源管理器中轻松重现。示例请求如下所示:

POST https://graph.microsoft.com/v1.0/teams
{
"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')",
"displayName": "A Pinned Website",
"configuration": {
"contentUrl": "https://learn.microsoft.com/microsoftteams/microsoft-teams"
}
},
{
"teamsApp@odata.bind": "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('com.microsoft.teamspace.tab.youtube')",
"displayName": "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')"
}
]
}

以下是错误响应包括的内容:

[
"message":"Tabs with duplicate DisplayName are not allowed.",
"errorCode":"Unknown",
"message":"'Channel Name' must not be empty.",
"errorCode":"Unknown",
"message":"'Channel Name' should not be empty.",
"errorCode":"Unknown",
"message":"'Channel Name' must not be empty.",
"errorCode":"Unknown",
"message":"'Channel Name' should not be empty.",
"errorCode":"Unknown"
]

如果 JSON 对象不包含任何选项卡配置,则 POST v1.0/团队终结点将正常工作。以下是我们介绍的测试场景:

  • 发布测试版/团队 API
  • 发布 v1.0/团队 API
  • 委派权限
  • 应用程序权限

思潮?

我无法对此进行测试,但我怀疑您的选项卡 json 应该具有displayName属性而不是name.因为我没有看到这里列出的name属性:https://learn.microsoft.com/en-us/graph/api/resources/teamstab?view=graph-rest-1.0

因此,您的选项卡部分将是:

"tabs":[
{
"teamsApp@odata.bind":"https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('com.microsoft.teamspace.tab.web')",
"displayName":"A Pinned Website",
"configuration":{
"contentUrl":"https://learn.microsoft.com/microsoftteams/microsoft-teams"
}
},
{
"teamsApp@odata.bind":"https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('com.microsoft.teamspace.tab.youtube')",
"displayName":"A Pinned YouTube Video",
"configuration":{
"contentUrl":"https://tabs.teams.microsoft.com/Youtube/Home/YoutubeTab?videoId=X8krAMdGvCQ",
"websiteUrl":"https://www.youtube.com/watch?v=X8krAMdGvCQ"
}
}
]

编辑:我刚刚尝试过,也无法让它工作。

但是,我找到了一个解决方法,首先发布没有选项卡部分的完整请求,然后通过发布到 https://graph.microsoft.com/v1.0/teams/{team-id}/channels/{channel-id}/tabs 来单独添加选项卡

我手动执行此操作的方式(我确信有更好的方法可以检索到团队 ID 和频道 ID):

  1. 发布不带选项卡部分的请求。
  2. 使用 GET https://graph.microsoft.com/v1.0/me/joinedTeams 检索已创建团队的 ID。
  3. 调用 GET https://graph.microsoft.com/v1.0/teams/{team-id}/channels以检索通道。
  4. 我将下面的选项卡段发布到 https://graph.microsoft.com/v1.0/teams/{team-id}/channels/{channel-id}/tabs,并检索了 201 创建的响应。
{
"teamsApp@odata.bind": "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('com.microsoft.teamspace.tab.web')",
"displayName": "A Pinned Website",
"configuration": {
"contentUrl": "https://learn.microsoft.com/microsoftteams/microsoft-teams"
}
}

这是一个与具有带有选项卡的通道的有效负载有关的问题 - 而不是namedisplayName属性。它已在 MS 图形v1.0中修复。

另请注意,选项卡上的namedisplayName都可以使用,但记录的属性displayName,所以我建议您切换到该属性而不是name

这是我自己测试的有效载荷样本。文档中的示例应与选项卡配置上的displayName一起使用。

最新更新