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

时间:2021-02-19 15:56:14

标签: microsoft-graph-api microsoft-teams microsoft-graph-teams

我们使用 Microsoft Graph API“POST team/v1.0”以编程方式创建 Microsoft Teams 团队。此端点允许创建具有预定义内容(例如设置、应用程序、频道和选项卡)的团队。但是,我们今天在尝试创建具有预定义选项卡的团队时开始面临问题。该问题可以在 Microsoft Graph Explorer 中轻松重现。这是示例请求的样子:

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://docs.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/teams 端点可以正常工作。以下是我们涵盖的测试场景:

  • POST 测试版/团队 API
  • POST v1.0/teams API
  • 委托权限
  • 申请许可

想法?

2 个答案:

答案 0 :(得分:0)

我无法对此进行测试,但我怀疑您的标签 json 应该具有 displayName 属性而不是 name。因为我没有看到此处列出了 name 属性:https://docs.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://docs.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

单独添加标签

我手动执行此操作的方式(我确定有更好的方法可以检索到 team-id 和 channel-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://docs.microsoft.com/microsoftteams/microsoft-teams"
    }
}

答案 1 :(得分:0)

这是一个与带有标签的通道的负载有关的问题 - 而不是 namedisplayName 属性。它已在 MS Graph v1.0 中修复。

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

这是我自己测试过的有效载荷示例。 example in documentation 应与选项卡配置中的 displayName 一起使用。