如何对Microsoft组和团队名称的名称进行编码,以将其包含在 API 调用 URL 中



如果我有一个 ID 为"testteam@example.onmicrosoft.com"的 Office 365 组/Microsoft 团队,并且我想使用其中一个测试版 API 进行查询,例如 https://graph.microsoft.com/beta/groups/{id}/threads,我需要查询一个 URL,例如 。但是,我坚持对团队名称进行编码。 https://graph.microsoft.com/beta/groups/testteam@example.onmicrosoft.com/threadshttps://graph.microsoft.com/beta/groups/testteam@example%2Eonmicrosoft%2E/threadshttps://graph.microsoft.com/beta/groups/testteam@example/threadshttps://graph.microsoft.com/beta/groups/"testteam@example"/threads,https://graph.microsoft.com/beta/groups/"testteam@example.onmicrosoft.com"/threads 都返回以下错误

"error": {
    "code": "Request_BadRequest",
    "message": "Invalid object identifier 'whatever_I_entered'."

我了解,这只是常规的URL编码。例如,在JS中,您可以使用函数encodeURIComponent(str)。如果您想尝试使用在线网址编码器。例如,testteam@example.onmicrosoft.com的编码版本看起来像testteam%40example.onmicrosoft.com,而您的图形请求将https://graph.microsoft.com/beta/groups/testteam%40example.onmicrosoft.com/threads

编辑:

在请求中,您需要使用组的 ID。例如:获取组请求可能如下所示...并且组 ID 为c28c1cc9-e1ab-4c4d-98d1-d8fdf128b60f

https://graph.microsoft.com/v1,0/groups/c28c1cc9-e1ab-4c4d-98d1-d8fdf128b60f?$select=description,allowExternalSenders

最新更新