I have list of channel id of particular group, I want the group Id and name from channel Id.
Is there any such api in Microsoft graph api?
I have list of channel id of particular group, I want the group Id and name from channel Id.
Is there any such api in Microsoft graph api?
This is not possible with the Graph API. This has been confirmed by Microsoft.
However, when you are working with a channel object and have its id, you usually also have an id of the team it belongs to - for example in the bot framework, it's part of the activity's channelData
.
Be prepared not to always have this information, since not all channels of conversations might be Teams channels! But let's assume you're working with Teams channels exclusively.
The id of the team is also the id of its implicitly-generated General channel. You can distinguish that one by the id format 19:…@thread.tacv2
- a normal channel has a hex string whereas the team itself has a longer base62 string and includes a -
. Without this id, you're basically lost.
Unfortunately, this team id is still mostly useless. It is not the UUID that you use in the Graph API for the Team
resources (at /teams/{team-id}
), Channel
resources (at /teams/{team-id}/channels/{channel-id}
) and Group
resources ("Every team is associated with a Microsoft 365 group. The group has the same ID as the team - for example, /groups/{id}/team
is the same as /teams/{id}
").
Rather, it is the value of the internalId
property of the team. It is also the main part of its webUrl
. So how to get the groupId
/teamId
UUID of the team from its internalId
string?
The best you can do with the Graph API is to get a list of all teams (either via /groups
or via /teams
, or at least the teams that you are part of or are otherwise associated with), and then for each team fetch the whole object by id and compare its internalId
with the channel id / internal team id that you are looking for.
Unfortunately, /teams?$filter=internalId eq '19%3A…%40thread.tacv2'
only gives the response Filter on property 'internalId' is not supported. :-/
However, looking outside of the Graph API, there is the Bot Framework REST API (part of Azure Bot Services), which does provide an undocumented endpoint. I discovered it via this StackOverflow answer, which shows that the Bot Framework SDK for .NET does have a method to fetch this information: FetchTeamDetailsWithHttpMessagesAsync
. It takes an internal teamId
(which is not distinguished in the documentation) and returns a TeamDetails
object which contains an AadGroupId
property: "Azure Active Directory (AAD) Group Id for the team." That's the one we want!
And since the code is open-sourced on Github, we can find its implementation:
// Construct URL
var baseUrl = Client.BaseUri.AbsoluteUri;
var url = new System.Uri(new System.Uri(baseUrl + (baseUrl.EndsWith("/", System.StringComparison.InvariantCulture) ? string.Empty : "/")), "v3/teams/{teamId}").ToString();
url = url.Replace("{teamId}", System.Uri.EscapeDataString(teamId));
This works similar in JavaScript/TypeScript, except the SDK doesn't expose the method itself. Turns out I need to look better, it's available as TeamsInfo.getTeamDetails
(working from the current TurnContext
) or new Teams(client).fetchTeamDetails
. Looking at its implementation, it uses
const fetchTeamDetailsOperationSpec: msRest.OperationSpec = {
httpMethod: 'GET',
path: 'v3/teams/{teamId}',
…
};
I'll leave my custom implementation up for posterity still, it has slightly more accurate types:
const SERVICE_URL = 'https://smba.trafficmanager.net/…/';
async function fetchTeamDetails(teamInternalId: string): Promise<TeamDetails> {
const adapter = new BotFrameworkAdapter({
…
});
const client = adapter.createConnectorClient(SERVICE_URL);
const response = await client.sendRequest({
method: 'GET',
url: `${SERVICE_URL}/v3/teams/${encodeURIComponent(teamInternalId)}`,
});
return response.parsedBody as TeamDetails;
}
/** Details related to a team. Modelled after https://learn.microsoft.com/en-us/dotnet/api/microsoft.bot.schema.teams.teamdetails (which is lacking `tenantId` though) */
interface TeamDetails {
/** Unique identifier representing a team. */
id: string;
/** Tenant Id for the team. */
tenantId: string; // UUID
/** Azure Active Directory (AAD) Group Id for the team. */
aadGroupId: string; // UUID
/** type of the team */
type: 'standard' | 'sharedChannel' | 'privateChannel';
/** Name of team. */
name: string;
/** Number of channels in the team. */
channelCount: number;
/** Number of members in the team. */
memberCount: number;
}
Reverse is possible. If you have Group/team id, can get channels. But no API to get Group id based on Channel id.
© 2022 - 2024 — McMap. All rights reserved.