How to: create and add a OneNote tab to your Microsoft Teams team channel using Power Automate + Graph API

I was asked to share how I have been adding new OneNote tabs to a team channel in Microsoft Teams using Power Automate + Graph API. If you look at the documentation it shows you this:

Of course I never believed that but found earlier a way to hack OneNote into a channel as tab but also updated my methods when it became much simpler than before. In this blog post I show you the simple way how to add OneNote book as a tab.

  1. You need t use a Premium licensing if you are using Power Automate since this is done using Graph API calls.
  2. Set up Azure AD App Registration with application id and client secret with required permissions for OneNote and to adding a tab to create OneNote books and adding them to tabs.
  3. You need a team id and a channel id you want to put the OneNote book into as a tab

Adding a new notebook is done directly to the team. The creation is quite simple – I used the team name as part of the Notebook’s name.

Once you have created the notebook you need to parse the body for some important variabled.

I created the schema based on one creation body to retrieve essential info about notebook ID and also it’s weburl.

 
{
     "type": "object",
     "properties": {
         "@@odata.context": {
             "type": "string"
         },
         "id": {
             "type": "string"
         },
         "self": {
             "type": "string"
         },
         "createdDateTime": {
             "type": "string"
         },
         "displayName": {
             "type": "string"
         },
         "lastModifiedDateTime": {
             "type": "string"
         },
         "isDefault": {
             "type": "boolean"
         },
         "userRole": {
             "type": "string"
         },
         "isShared": {
             "type": "boolean"
         },
         "sectionsUrl": {
             "type": "string"
         },
         "sectionGroupsUrl": {
             "type": "string"
         },
         "createdBy": {
             "type": "object",
             "properties": {
                 "user": {
                     "type": "object",
                     "properties": {
                         "id": {
                             "type": "string"
                         },
                         "displayName": {
                             "type": "string"
                         }
                     }
                 }
             }
         },
         "lastModifiedBy": {
             "type": "object",
             "properties": {
                 "user": {
                     "type": "object",
                     "properties": {
                         "id": {
                             "type": "string"
                         },
                         "displayName": {
                             "type": "string"
                         }
                     }
                 }
             }
         },
         "links": {
             "type": "object",
             "properties": {
                 "oneNoteClientUrl": {
                     "type": "object",
                     "properties": {
                         "href": {
                             "type": "string"
                         }
                     }
                 },
                 "oneNoteWebUrl": {
                     "type": "object",
                     "properties": {
                         "href": {
                             "type": "string"
                         }
                     }
                 }
             }
         }
     }
 } 

The final piece is to use this information to add OneNote as a tab to a channel. For this you need the notebook id, the channel id along with the team id.

And that’s that.

Of course we could take this further by adding new sections and pages to the OneNote – or even content. But even as this is now this is very useful when doing a custom team provisioning. If you have premium licenses for Power Automate.

Instead of using Power Automate Premium this could be very well done with Azure Logic Apps, which can provide a cost-effective way to use occasional Graph API calls (it always depends): do the ROI calculation for your situation/platform

14 thoughts on “How to: create and add a OneNote tab to your Microsoft Teams team channel using Power Automate + Graph API

  1. HI Vesa, thanks so much for this article. I was able to use it to create a OneNote tab in my Team’s General channel but now every time I test my flow, I get the error “No modern group was found that matches the ID xxxxxxxx-xxxx-xxxx-xxxx-….” at the first step of adding onenote to the team, which used to work just fine. I introduced a delay of at most 5 minutes before that step which didn’t help either. Any help and insight would be greatly appreciated.

    Like

      1. Thanks so much for your response. I think I have an idea of what could be the problem. After creating the team, the team’s Files tab and Wiki tab were not loading up and SharePoint site wasn’t accessible for a long time. I kept seeing this message under Files tab, “We can’t get your files. We’re working on getting them back.”
        This made me think that there was probably an issue with provisioning the SharePoint site. I tried creating a team with a different name and it worked just fine. I have been testing with the same name and deleting the teams so could be something didn’t cleanup properly and now that name can’t be provisioned in SharePoint. I couldn’t find the site in SharePoint admin fyi. I will report back if the issue comes up again. Thank you for your time.

        Like

  2. I am glad to hear about the follow-up! Thank you for sharing ideas already. Your description sounds like a plausible issue. I have done a few mistakes, once on a stage, by reusing a team name when doing provisioning. I make sure these days I always have a unique name..

    Like

  3. Hi Vesa, many thanks for this useful blog post! I have slightly modified the procedure to get the URL of a section within a section group to link to this section directly. Everything working fine so far, as long as I am using the Tab with the User who run the Power Automate Workflow. If I try with a different User, the Window in the Teams Desktop Client stays blank, the Web Version works fine. After troubleshooting with Teams Client Dev Tools, I found out that once the other User tries to access the Notebook, it tries to authenticate via Azure AD, which is blocked as OneNote is running within an iframe in Teams. Do you know an easy Way to bypass authentication or do I need to integrate OAuth 2 / SSO in the Team Tab?

    Like

    1. Hi! You shouldn’t have any need to bypass the authentication. Especially if it works in the web browser.
      Do your other OneNotes (manually added) work in both clients? To me it sounds more like an issue that you can’t really affect.
      If it is about permissions (it should be not, it is in a team I presume) then you could always grant more permissions there but I would be careful not to expose the OneNote too much. And when it is inside a team then everyone in the team has by default permissions to it.(and working in web client but not in desktop sounds like it is not about permissions).

      I am wondering if that would be more about how you configured it in. Added as a web page?

      Like

  4. Hi Vesa, thank you for your response! Yes, other OneNotes work fine in both clients. My workflow adds New Section Groups with new sections and pages to a specific notebook, I want to add a URL to the Tab that opens the newly created section in the Teams-Tab. I have tried to increase permission level (Up to SharePoint Site owner), but with no success. I have added the URL with the following structure: https://.sharepoint.com/sites/<NameOfSharePointSite/_layouts/15/Doc.aspx?sourcedoc={e7beb206-xxxxxxx-a70f-bac84xxxxx}&action=edit&wd=target%28%2F.one%7C1-1d2xxx-3dba-41eb-8xxxxxxx7ededd12%2F%29&wdorigin=717

    This works fine for the User in which context to Flow ran, but all other Users get a blank page in Teams, I have inspected with DevTools and got the following error Message: Refused to display ‘https://login.microsoftonline.com/’ in a frame because it set ‘X-Frame-Options’ to ‘deny’.

    Best regards,
    Philipp

    Like

    1. I think the content URL structure may be a bit too complex. I did some testing with this and found out if I added a section to a OneNote and then just added OneNote normally I got the same result as you did (login issue) but if I added the Section URL as ContentURL it started to work.

      When you create the Section get it’s URL out from the response:
      “oneNoteWebUrl”: {
      “href”: “https://xxxx.sharepoint.com/sites//Shared%20Documents/Notebooks/Testing%20teamname1?wd=target%28%2F%2FCustom%20Section.one%7C%2F%29”
      }
      Testing teamsname1 is the name of OneNote in my case. Custom Section was the section name I added.

      Something I also noticed to fix the issue was that the other user needed just open the OneNote in web and the original way worked in that case. But it didn’t seem to be required once I had provided the direct link to the Section there.

      In my test I created these OneNotes directly to Teams (or actually to Groups) using Graph API all the way.

      Like

      1. Hi Vesa, many thanks for your reply!
        I have added a new Tab with the URL I got from the response when creating the new Section, but unfortunately, the Tab now doesn´t work for any User in Teams (Blank page, Login required) 😦
        I have also tried the following:
        -Setting the Microsoft 365 Group as Public Group -> same effect, blank Tab as Login is required
        -Opened the URL in Browser (which works) before opening it in Teams -> Tab stays blank
        -Added the URL as a Website-Tab -> I am prompted to Login. After I am logged in and I have selected to stay logged in, also the other Tabs work, because I am logged in. This seems to work, but I don´t know how often a Re-Authentication is required

        The Notebook I am using was originally copied from another Notebook directly in the SharePoint Web UI, could this be the reason I am experiencing these issues now?

        Best regards,
        Philipp

        Like

      2. Could you try to create a new notebook to the team directly and check out if you have the same issues with that?
        Issues like this are quite a pure example of problem-solving where some trial & error is needed to pinpoint the problem source.

        Like

    1. Only Microsoft support can check out what’s wrong based on tracking ID. I don’t have access to there.
      If you could try to open what you were trying to do when getting the error I might be able to help you.

      Like

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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.