Copying files to Private Channel using Graph API

I was approached with a scenario: Once I have created a Private Channel how can I automatically copy files there? Since I didn’t have a direct answer it was time to open Graph Explorer and start digging.

Create a Private Channel

You need to have a suitable team first.
/me/joinedTeams is quite a good Graph API path for that.
Store that TeamID and create a private channel:

  "@odata.type": "",
  "membershipType": "private",
  "displayName": "Inner loop",
  "description": "This is for private content"

In return you get a Private Channel ID. Store that too. Just for kicks check that do you get any tabs returned.{TeamID}/channels/{PrivateChannelID}/tabs?$expand=teamsApp

Of course you don’t get any tabs. Posts and Files are not returned with tabs query!
So let’s create tab.

  "displayName": "website",
  "teamsApp@odata.bind" : "",
  "configuration": {
     "contentUrl": ""

Now if you try to retrieve tabs you get the website tab in the return set.

Get the Site

If you are thinking to use the source team to retrieve private channel’s drive.. you are going down the wrong path easily.

#1: Private Channel is it’s own site collection.
#2: Private Channel is not a group
#3: Private channel site collection is named: sourceteamsite-privatechannelname

First we need to get the source team’s site collection name.{TeamID}/sites/root

Store the Sitename and add private channel internal name to it without spaces.

Now we can retrieve the Site information:

Again: store the SiteId. This id is a long one.

Get the Drive and Folder ID

Next: get drives of the Site. You need to look for the Document Library ( wheredriveType=”documentLibrary in the result set){SiteID}/drives

Store the Document Library Drive id

And no, you are not done. You need to retrieve the drive’s root id.{DocumentLibraryDriveID)/root

Store the RootID

Now.. Retrieve all items of that drive’s root.{DocumentLibraryDriveID}/items/{RootID}/children

There should be only one entity: the folder named by your Private channel team! Store PrivateChannelFolderID.

Copy the file into Private Channel

Copying file is tricky if you don’t pay attention. You need to use URL for the source file and JSON body for the target (=your Private channel folder).

  "parentReference": {
    "driveId": "{DocumentLibraryDriveID}",
    "id": "{PrivateChannelFolderID}"
  "name": "Teams Spotlight 20200218.pptx"

And you are done!

You can retrieve files with Graph API using /drives/{DocumentLibraryDriveID}/items/{PrivateChannelFolderID}/children

But of course it is easier to check with Teams app:

And yes – that is the new Files Experience. It just appeared on my dev tenant today!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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