/OneNoteClassPowerShell

Script API OneNote Class

Primary LanguagePowerShellMIT LicenseMIT

OneNote Class Notebooks API PowerShell Sample README

Created by Microsoft Corporation, 2016. Provided as-is without warranty. Trademarks mentioned here are the property of their owners.

API functionality demonstrated in this sample

The following aspects of the API are covered in this sample.

Prerequisites

  • Azure PowerShell - used to obtain an access token to talk to the OneNote Class Notebooks API.
  • An Office 365 account with OneDrive set up - the class notebook that this sample script creates will be located in your OneDrive. To ensure that your OneDrive is set up, log on to Office 365 and click the blue "OneDrive" icon in the app launcher. If you are taken to your OneDrive, you are all set.
  • Four additional Office 365 accounts - this sample script will add students and co-teachers to the class notebook it creates using these accounts.

Using the sample

  1. Obtain a client ID as described under Authenticate using Azure AD (enterprise apps). When asked for a redirect URI, "http://localhost" will suffice:

Image of redirect URI

When asked for OneNote delegated permissions, check the following:

Image of permissions

  1. Download this repo as a ZIP file to your local computer, and extract the files. Or, clone the repository into a local copy of Git.

  2. Edit OneNoteClassNotebooksApiSample.ps1. Find and replace the following tokens with real values:

    • <AZURE_AD_TENANT_NAME> - This is your Azure tenant, e.g. "contoso.com".
    • <CLIENT_ID> - This is the client ID of your app, e.g. "471afe29-4aee-4bc5-9aaf-468ee5bbe20a".
    • <REDIRECT_URI> - This is the redirect URI of your app, e.g. "http://localhost".
    • <MY_LOGIN> - This is your Office 365 login name. You will be added as the teacher to the class notebook this script creates.
    • <COTEACHER_LOGIN> - This is the Office 365 login name for an account that will be added as a co-teacher to the class notebook this script creates.
    • <STUDENT_1_LOGIN>, <STUDENT_2_LOGIN>, <STUDENT_3_LOGIN> - These are the Office 365 login names for accounts that will be added as students to the class notebook this script creates.
  3. Once all the placeholders above have been replaced with real values (remember to enclose each value in double quotes), simply execute the script.

  4. Once the script has successfully executed, go to your OneDrive where you will see a folder named "Class Notebooks". In this folder you will find the "Math 101" class notebook this script created.

Next steps

This sample script demonstrated creating a class notebook in your personal OneDrive. If you are an IT administrator, you can also programmatically create class notebooks for teachers. Refer to the Construct the request URI section, in particular the Shared notebooks on OneDrive for Business section. Specifically, you would issue the create request to:

	POST https://www.onenote.com/api/v1.0/users/<teacher_id>/notes/classnotebooks

where <teacher_id> is the Office 365 login name of the teacher you wish to create a class notebook for.

Note that before creating class notebooks for teachers, an IT administrator needs to ensure OneDrive is provisioned and access is granted (IT administrators do not have access to users' OneDrives by default). These [OneDrive for Business setup cmdlets] (https://github.com/OneNoteDev/OneDriveForBusiness-SetupPowerShellCmdlets) should come in handy

Version info

This is the initial public release for this code sample.

Learning more