Create a Teams Private Channel using Graph API and Power Automate (Flow)

Have you thought about creating a private channel in Teams using a API? Yes, it is possible to do so in case you were wondering is that really supported or not. Using Graph Explorer is simple, fast and easy for this testing.

First you need to figure out a few IDs:

Creating a private channel with creator as owner

Create a POST call with following information. All POST calls are with Content-type of application/json

POST https://graph.microsoft.com/beta/teams/{teamID}/channels

{
  "@odata.type": "#Microsoft.Teams.Core.channel",
  "membershipType": "private",
  "displayName": "Private corner",
  "description": "This is for private content"
}

Looking at Members-information (… menu and Manage channel) you can see the current user became the owner of the channel

Creating a private channel with two owners

This is very similar as before but we include a user block in the POST call. The actual call URL remains the same.

POST https://graph.microsoft.com/beta/teams/{teamID}/channels

{
  "@odata.type": "#Microsoft.Teams.Core.channel",
  "membershipType": "private",
  "displayName": "Private corner too",
  "description": "This is for private content",
  "members":
     [
        {
         "@odata.type":"#microsoft.graph.aadUserConversationMember",
           "user@odata.bind":"https://graph.microsoft.com/beta/users('{UserID1}')",
           "roles":["owner"]
        },
        {
           "@odata.type":"#microsoft.graph.aadUserConversationMember",
           "user@odata.bind":"https://graph.microsoft.com/beta/users('{UserID2}')",
           "roles":["owner"]
        },

     ]
}

Now we have two owners in the channel.

Creating a private channel with a specific owner and adding a member

The last variation is to add owners and members when creating a private channel:

POST https://graph.microsoft.com/beta/teams/{teamID}/channels

{
  "@odata.type": "#Microsoft.Teams.Core.channel",
  "membershipType": "private",
  "displayName": "Private corner again",
  "description": "This is for private content",
  "members":
     [
        {
         "@odata.type":"#microsoft.graph.aadUserConversationMember",
           "user@odata.bind":"https://graph.microsoft.com/beta/users('{UserID1}')",
           "roles":["owner"]
        },
        {
           "@odata.type":"#microsoft.graph.aadUserConversationMember",
           "user@odata.bind":"https://graph.microsoft.com/beta/users('{UserID2}')",
           "roles":["member"]
        },

     ]
}

And we can see Amy being a member on this channel.

As usual, read Docs.Microsoft.Com article about channel creation for details and updates. The API is in beta, so it may change.

Let’s use Power Automate (Flow) for creation

I needed to switch the environment here (yeah, licenses…) but using a Power Automate to create a channel based on a trigger isn’t difficult in case you have a provisioning process in place. Let’s assume that we have a list somewhere that will trigger the creation of a team and it will automatically create a private channel there. Simple POC case.

  1. Create a team using Graph API in a flow.
  2. Ensure you get the freshly created team id. The provisioning may take some time, so I have added a 15 second delay and then start listing teams to find out the created team id
  3. Create the POST uri call for Private channel creation (above in this post)
  4. I couldn’t get the @odata.type to work in a request call so I ended up putting it into a variable.. Fix for this: I was told that using double at-sign (@@odata.type) when entering information to the request body actually solves this one without a need to use variable workaround. You learn something new every day!
  5. Place the private channel call into request

Creation was started when a new item was added to the list. After Power Automate run successfully the team appeared with the private channel that has one owner (me) as defined in the call.


Yksi vastaus artikkeliiin “Create a Teams Private Channel using Graph API and Power Automate (Flow)

Vastaa

Täytä tietosi alle tai klikkaa kuvaketta kirjautuaksesi sisään:

WordPress.com-logo

Olet kommentoimassa WordPress.com -tilin nimissä. Log Out /  Muuta )

Google photo

Olet kommentoimassa Google -tilin nimissä. Log Out /  Muuta )

Twitter-kuva

Olet kommentoimassa Twitter -tilin nimissä. Log Out /  Muuta )

Facebook-kuva

Olet kommentoimassa Facebook -tilin nimissä. Log Out /  Muuta )

Muodostetaan yhteyttä palveluun %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.