');
51 | });
52 | $("#classNotebooksList").append(listElements.join(''));
53 |
54 | // Populate drop down menus
55 | var dropDownMenuElements = [];
56 | $.each(response.value, function (i, item) {
57 | dropDownMenuElements.push('');
58 | });
59 | $(".classNotebooksDropDown").append(dropDownMenuElements.join(''));
60 |
61 | $("#loading").hide();
62 | $("#demos").show();
63 | }).fail(function() {
64 | $errorMessage.html("Error when trying to access class notebooks");
65 | });
66 | });
67 | }
68 | }());
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | OneNote Class Notebook APIs Sample
2 | ===================================
3 |
4 | The OneNote Class Notebook APIs let you programmatically create and edit class notebooks. This sample
5 | demonstrates the basics on how you would call these APIs using JavaScript, jQuery and ADAL for authentication.
6 | To learn more about ADAL you can visit its
7 | [GitHub page](https://github.com/AzureAD/azure-activedirectory-library-for-js). For full documentation on
8 | the class notebook APIs take a look at our
9 | [article on MSDN](https://msdn.microsoft.com/office/office365/howto/onenote-classnotebook).
10 |
11 | Please keep in mind that this sample is meant to illustrate how you would reach our APIs in JavaScript
12 | and does not necessarily contain all the code you would want for a production-ready application. In a
13 | more complete web app you would probably use a framework like AngularJS, add more specific error handling,
14 | etc.
15 |
16 | If you would like to see a live version of this app we have an instance running on Azure that
17 | you can access [here](http://onenoteedusample.azurewebsites.net/).
18 |
19 | ## How To Run This Sample
20 |
21 | ### Step 1. You will need the following
22 | - An Azure subscription
23 | - An Office 365 subscription
24 |
25 | The Azure subscription should be associated with the Office 365 subscription.
26 | [Authenticate using Azure AD (enterprise apps)](https://msdn.microsoft.com/office/office365/howto/onenote-auth#aad-auth)
27 | has details on how to do just that.
28 |
29 | ### Step 2. Register your app in Azure and add permissions
30 | Again, follow the instructions under
31 | [Authenticate using Azure AD (enterprise apps)](https://msdn.microsoft.com/office/office365/howto/onenote-auth#aad-auth)
32 | to register your application in Azure. You will also need to give your app Notes.ReadWrite permissions.
33 |
34 | Since this web app uses OAuth 2's implicit grant flow, you should
35 | enable it in your app's manifest in Azure.
36 | [This article](https://azure.microsoft.com/en-us/documentation/articles/active-directory-authentication-scenarios/#single-page-application-spa)
37 | has details on the implicit grant flow and how to enable in Azure. In particular, you'll want to download
38 | your app's manifest in the Azure Management Portal, set the "oauth2AllowImplicitFlow" field to true, and
39 | upload the manifest to the portal.
40 |
41 | ### Step 3. Fill in your clientId in app.js
42 | You will need to specify the clientId for your app in app.js. You can get the clientId in the Azure Management
43 | Portal.
44 |
45 | ### Step 4. Run your application
46 | If you are using Visual Studio, build and run your application. To test your application locally you will
47 | also need to add the local URL as a reply URL in your app's page in the Azure Management Portal. The sample is
48 | set to run at localhost:55407.
49 |
50 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
51 |
--------------------------------------------------------------------------------
/src/OneNoteCNApiSample/wwwroot/scripts/copycontents.js:
--------------------------------------------------------------------------------
1 | (function() {
2 | var authContext = new AuthenticationContext(config);
3 | var user = authContext.getCachedUser();
4 | var sectionSelectorTitle = '';
5 |
6 | // Get copy contents-related UI elements
7 | var $message = $("#copyContentsMessage");
8 | var $sourceSelector = $("#copyContentsSelectSource");
9 | var $sectionSelector = $("#copyContentsSelectSection");
10 | var $destinationSelector = $("#copyContentsSelectDestination");
11 | var $copyContentsButton = $("#copyContentsButton");
12 |
13 | $sourceSelector.change(function () {
14 | if (!user) { return; }
15 |
16 | // Load sections into second drop-down menu. Disable menu until contents are ready.
17 | $sectionSelector.prop("disabled", true);
18 | var notebookId = $sourceSelector.val();
19 |
20 | // Don't attempt to load sections if user selected the drop-down title
21 | if (notebookId === "0") {
22 | $sectionSelector.html(sectionSelectorTitle);
23 | return;
24 | }
25 |
26 | authContext.acquireToken("https://onenote.com/", function (error, authToken) {
27 | if (error || !authToken) {
28 | $message.html(error);
29 | }
30 | getSections(notebookId, authToken);
31 | });
32 | });
33 |
34 | $copyContentsButton.click(function () {
35 | clearMessage();
36 | if ($sectionSelector.val() === "0" || $destinationSelector.val() === "0") {
37 | $message.html("Please select a section to copy and a destination notebook");
38 | return;
39 | }
40 | if ($sourceSelector.val() === $destinationSelector.val()) {
41 | $message.html("Please select a destination notebook that is different from the source notebook");
42 | return;
43 | }
44 |
45 | authContext.acquireToken("https://onenote.com/", function (error, authToken) {
46 | if (error || !authToken) {
47 | $message.html(error);
48 | }
49 | copyContents($sectionSelector.val(), $destinationSelector.val(), authToken);
50 | });
51 | });
52 |
53 | function getSections(notebookId, authToken) {
54 | $.ajax({
55 | type: "GET",
56 | url: "https://www.onenote.com/api/v1.0/me/notes/notebooks/" + notebookId + "/sections",
57 | dataType: "json",
58 | headers: {
59 | "Authorization": "Bearer " + authToken
60 | }
61 | }).done(function (response) {
62 | // Populate second drop-down menu with sections
63 | var dropDownMenuElements = [sectionSelectorTitle];
64 | $.each(response.value, function (i, item) {
65 | dropDownMenuElements.push('');
66 | });
67 | $sectionSelector.html(dropDownMenuElements.join(''));
68 | $sectionSelector.prop("disabled", false);
69 | }).fail(function () {
70 | $message.html("Error: could not get the list of section groups for the selected notebook.");
71 | });
72 | }
73 |
74 | function copyContents(sectionId, destinationNotebookId, authToken) {
75 | $.ajax({
76 | type: "POST",
77 | url: "https://www.onenote.com/api/beta/me/notes/classNotebooks/" + destinationNotebookId + "/copySectionsToContentLibrary",
78 | contentType: "application/json",
79 | headers: {
80 | "Authorization": "Bearer " + authToken
81 | },
82 | data: JSON.stringify({ "sectionIds": [sectionId] })
83 | }).done(function () {
84 | $message.html("Section successfully copied to target notebook!");
85 | }).fail(function () {
86 | $message.html("Error: could not copy sections to destination notebook.");
87 | });
88 | }
89 |
90 | function clearMessage() {
91 | $message.empty();
92 | }
93 | }());
--------------------------------------------------------------------------------
/src/OneNoteCNApiSample/wwwroot/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | OneNote Class Notebook API Sample
6 |
7 |
8 |
9 |
10 |
OneNote Class Notebook API Sample
11 |
12 | The OneNote Class Notebook APIs let you programmatically create and edit class notebooks.
13 | This sample demonstrates the basics on how you would call these APIs using JavaScript, jQuery
14 | and ADAL for authentication.
15 | For full documentation on the class notebook APIs take a look at our article on MSDN.
16 | We are also making the source code for this app available on GitHub.
17 | To learn more about ADAL you can visit its GitHub page.
18 |
19 |
20 | To use this app please log in using your Office 365 account.
21 |
35 | The Class Notebook APIs let you view, create, and edit OneNote class notebooks. In
36 | this example we retrieve all the class notebooks that you are a part of along with
37 | links to access them via the web client. If you'd like to create additional class
38 | notebooks you can use our Class Notebook app.
39 |
40 |
41 |
42 |
Teacher-only section group
43 |
44 | A teacher-only section group is an area of the class notebook that is not
45 | visible to the students. It's a great way for teachers and co-teachers can
46 | collaborate and share notes. Use the following form to add a teacher-only
47 | section group to one of your existing notebooks.
48 |
55 | The copy content API enables you to share sectiongs between notebooks. You can copy
56 | a section from one of your notebooks into the Content Library of one of your other
57 | existing notebooks. This example shows how you can use the regular OneNote APIs along
58 | with the Class Notebook APIs to give you a lot of control over the structure of the
59 | notebooks you create.
60 |
61 |
62 | In the following form, first select the notebook that holds the
63 | section you want to copy. Then select the section in that notebook that you want to
64 | copy. Finally select the notebook you want to copy the section to. The section will
65 | be copied to the Content Library of the target notebook. Please note that this form
66 | will expose only sections on top of the notebook hierarchy, meaning that sections
67 | within section groups won't show up. However, you can re-write this to access any
68 | section within your notebook.
69 |