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

20 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?

    Liked by 1 person

    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

  5. Hope all is well with you and yours.

    I appreciate your post,and have some questions. I have no need to create the Notebook as it already exists, I am merely trying to add a tab within a channel of the Notebook. I see that you have the Notebook URL as the content and website URL, are they not different? I have been working on this for over a week now and can’t seem to get it right. I finally have the website URL correct as to when I get an error in the Teams channel, it allows me to click a button to open in SharePoint, that works fine. It is only in Teams that it has an error, at first it was Resource ID was incorrect, and now it is Error 20130. Your support would be greatly appreciated

    Like

    1. Website and Content URLs are different. I recall when writing the blog post using content URL as website URL didn’t have much effect.
      Website URL is what is opened when you click the globe icon (ie: opens the URL in browser).
      Content URL is what Teams tries to use to retrieve contents to show inside the tab. That is why getting Content URL right is important.
      When I was building those content URLs it took several iterations to get it right.

      Perhaps my later example, from ECS session in late 2021, might help you.
      You can get the PowerShell script from GitHub. Search for OneNote there and you find out place where a new book is created and after that it is attached to the channel as tab.
      https://github.com/veskunopanen/Teams-Graph-API/blob/master/ECS%202021%20Graph%20API%20Demos.ps1

      Like

  6. hello Vesa,
    interesting concept.
    Questions: instead of a premium subscription, could one do a work around with the “Send Http request” from Groups Connector?

    And – do you have a similar concept for adding ONLY a page from a section) as tab to channel?

    Name / Header of the page would be these same as the channel name.

    Thanks!

    Like

    1. I have not tested the Send Http request from Groups Connector yet, if that supports these scenarios or not.
      But it is surely something worth checking, because one might imagine OneNote is a type of content it should support.

      As far as I know you can’t add only a single page to the tab. The OneNote App supports the whole book and when you do sharing with OneNote it affects at book level. I have not had the need to check this one either. You might want to wait for upcoming Notes feature (replacing Wikis) if there is anything different than OneNotes today. Those should be OneNotes but with the new features there is always a chance for new API options as well.

      Like

  7. Hello Mr. Metaverse,

    I have been working on this for a while. I have managed to create a notebook and add it as a tab. Unfortunately, the link to the tab can’t get resolved. It would be a great help if I could make you take a look at this thread, where my struggles are documented, and give me your thoughts.

    https://powerusers.microsoft.com/t5/Building-Flows/Create-OneNote-notebook-as-a-tab-in-Teams/m-p/2085893#M230938

    Best regards,
    Thomas Michelsen

    Like

    1. It has been some time since I did this. 🙂 Unfortunately I can’t go and check has there been changes that might have changed something.
      If you haven’t check, see my PowerShell how I created those tabs.
      https://github.com/veskunopanen/Teams-Graph-API/blob/master/ECS%202021%20Graph%20API%20Demos.ps1
      And as you did – use Graph Explorer to get it work.
      Now – pay attention to the user here. Graph Explorer is using identity you logged into that. Then you may have application (or something else) used when you are running it in your code. Permissions and what is possible can be an effect here.

      I suggest that you try to create the JSON and call in the code and put it somewhere that you can use to grab it and run it inside Graph Explorer.
      If it works in the GE, then it is probably a delegation/application permission problem. That can be the difference between code and GE – if your calls & payloads are the same.

      I recall it was sometimes a bit touchy to get URL format right. From my .ps1 file you can see how I formatted those.

      Like

Leave a comment

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