Episode #116 – Latest news about Microsoft Teams APIs in Microsoft Graph

Here you can find the transcript of Episode #116 of PiaSys TechBites.

Welcome back to PiaSys Tech Bites.

Today, I want to talk with you about some new capabilities that Microsoft introduced in the Microsoft Graph APIs regarding Microsoft Teams. As we know, Microsoft Graph is continuously growing and evolving. And in the last few months, Microsoft introduced the capability to upload or get the image for a team, to get the primary channel of a team, as well as to get and list the messages in a channel of a team, and to reply to a message. As well as, you can also get the files folder in a specific target channel. These are just some of the new functionalities that Microsoft introduced in Microsoft Graph. And I want to go to the demo environment to show you how to play with them.

Let’s start having a look at the official documentation of Microsoft Graph under docs.microsoft.com. Here you can see under the beta endpoint reference that in the team category, under the teamwork category, we have a bunch of actions available, like for example, the get team photo, the updating photo, the get primary channel. While in the channel category, we have the capability to list the channel messages, to get a specific channel message, to reply to a message, and to get the files folder for a specific target channel. Here I also have a team in Microsoft Teams, which I’m using for the sake of making a demo.

So, let me switch to Graph Explorer and let me start playing with that specific target team. First of all, in order to access the team, we need the ID of the team and we can do that by retrieving the group backing the team. So I will switch to the beta endpoint because I will mainly use beta functionalities, even if not all of them will be under the beta endpoint only. And let me get the list of groups in my target tenant. For every single group, I get the unique ID of the group. I get the displayName and many other information.

So, I can make a query, using the OData protocol, to filter based on the display name. And I want to have the displayName equal to the value that we have for the displayName of our target team, which is “Teams Development Series”, URL encoded. So let me do that. Teams, space, development, space, series. That’s the name. So let me query this group and I’ll get back the unique ID of my group. I can eventually specify with $select, if I just want to retrieve the ID for the sake of saving some space. So now I can get all of the information that I need about the target group by providing the ID of that group. And for example, I can get the photo of the group, and I get the binary value of that photo.

Let me run the query again. And as you can see, this is the icon that we have in Teams for this specific team. Now I can copy this URL and using another tool, which is Fiddler right now, I can make a PUT request targeting the group, which is backing my team groups and providing a new value for the photo of my group. So I can add to this request, the authorization header from an open authorization point of view, which will be a Bearertoken, and I can copy the value of the access token from here from the Graph Explorer, and I can provide the file that will replace the picture of my group, like this one, for example. Let me execute this PUT request.

And as you can see right now, I’ve got back a 200 OK response. So, if I will make another query in the Graph Explorer for the icon, I will get the new one. So really, really simple and easy. Another thing that I can do targeting a team is to retrieve a reference to the primary channel of my team. By doing that, I can get back the information about what the primary channel is. Of course, in my team, the primary channel is the general channel. And as you can see here, it is that one, but I can also see the ID of the channel so that I can, for example, make a query for all of the channels in my team, providing the specific ID of the channel that I’m looking for, which is still the general channel, but for the general channel, for example, I can make a request for the files folder.

So let me do that. Right after the ID, I will specify that I want to have the information about the files folder. Once I’ve done that, I will get back the information about a OneDrive folder in my Microsoft 365 infrastructure. And as such, for example, I can get the ID of the drive in which my folder is stored. And let me place this information in the URL of my request. So I can say that through Microsoft Graph, I want to have access to the drives in my tenant. And specifically, I want to access that drive, which contains the folder for my channel and I can get then the ID of the folder item. So that right after the ID of the drive that I’m targeting, I can specify that I want to access the collection of items and that specific item with that specific ID. Let me run this query and I will get back a JSON response, including all of the information about my files folder.

Of course, I can make a query for the children items of that folder. And by doing that, I will get back, again, this is JSON response, all of the items in my folder using the OneDrive API’s. As you can see, if I go to the files folder here, I can see that I have five sample files. So I can use this response to get access to a specific item, for example. So I can say that for the very first file, like this one, I want to get the unique ID in OneDrive. And I want to get that specific item. And by providing the new ID in the collection of items of my target drive, I can get the specific file. So very useful and interesting. Moreover, if I go back to the channel of my team and I make a query, I can make a query for all of the messages in the channel.

Let me show you. Here are the messages that I have, and I can get a specific message by ID, for example. So let me write a new message in the channel. Let me start a new conversation for “PiaSys Tech Bites”. Okay, let me post it. Let me make a new query and let me search for Tech Bites. And here we are. This is my new conversation. I have my message. I have the ID of that message. So I can retrieve that message specifically, simply by providing in the collection of messages the ID of the message that I’m targeting. Let’s do that. And if I want to reply by using the Microsoft Graph to that message, I can simply say “replies”, “collection of replies”, and I can POST to that collection of replies a new reply, which will be a JSON message. And it will be just “here is my reply”. Let me run this query again. And if I go back to Teams, we can see that I have a reply right here. So really simple, really straightforward like always.

Like always, thank you for watching this video. I hope you found it interesting. And remember to subscribe to this channel, to see many more videos. Thank you.