This repository was archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathpost-html-sample.html
95 lines (85 loc) · 3.58 KB
/
post-html-sample.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="http://i3.msdn.microsoft.com/Combined.css?resources=0:Topic,0:CodeSnippet,0:ProgrammingSelector,0:ExpandableCollapsibleArea,1:CommunityContent,0:TopicNotInScope,0:FeedViewerBasic,0:ImageSprite,2:header,2:SearchBox,2:ImageSprite,0:Breadcrumbs,1:Toc,1:NavigationResize,3:FeedbackCounter,3:Feedback,1:LibraryMemberFilter,2:footer,4:Metro;/Areas/Epx/Content/Css:0,/Areas/Library/Content:1,/Areas/Epx/Themes/Metro/Content:2,/Areas/Epx/Shared/Content:3,/Areas/Library/Themes/Metro/Content:4&amp;hashKey=6C88459BBE815E4612422961505E03CE">
</head>
<body>
<span class="LW_CollapsibleArea_Title">Creating a simple page in a Node.js app</span>
<p>This snippet creates a basic OneNote page from HTML by placing the HTML directly in the HTTPS request body.
It doesn't use the multi-part format. The snippet also adds the Content-Type and Authentication headers to the POST request.</p>
<div class="codeSnippetContainer">
<div class="codeSnippetContainerTabs">
<div class="codeSnippetContainerTabSingle" dir="ltr">
<a>Javascript</a>
</div>
</div>
<div class="codeSnippetContainerCodeContainer">
<div class="codeSnippetContainerCode" dir="ltr">
<div style="color:Black;">
<pre>
/**
* Create OneNote Page with Text
*
* @param {string} accessToken The access token
* @param {createPageCallback} callback The callback with response data
*/
this.createPageWithSimpleText = function (accessToken, callback) {
var htmlPayload =
"<!DOCTYPE html>" +
"<html>" +
"<head>" +
" <title>A page created from basic HTML-formatted text (Node.js Sample)</title>" +
" <meta name=\"created\" value=\"" + dateTimeNowISO() + "\">" +
"</head>" +
"<body>" +
" <p>This is a page that just contains some simple <i>formatted</i>" +
" <b>text</b></p>" +
"</body>" +
"</html>";
createPage(accessToken, htmlPayload, callback, false);
};
/**
* @callback createPageCallback
* @param {object} Error
* @param {object} HTTP Response
* @param {string} Response body
*/
var oneNotePagesApiUrl = 'https://www.onenote.com/api/v1.0/pages';
/* Pages API request builder & sender */
function createPage(accessToken, payload, callback, multipart) {
var options = {
url: oneNotePagesApiUrl,
headers: {'Authorization': 'Bearer ' + accessToken}
};
// Build simple request
if (!multipart) {
options.headers['Content-Type'] = 'text/html';
options.body = payload;
}
var r = request.post(options, callback);
// Build multi-part request
if (multipart) {
var CRLF = '\r\n';
var form = r.form(); // FormData instance
_.each(payload, function (partData, partId) {
form.append(partId, partData.body, {
// Use custom multi-part header
header: CRLF +
'--' + form.getBoundary() + CRLF +
'Content-Disposition: form-data; name=\"' + partId + '\"' + CRLF +
'Content-Type: ' + partData.contentType + CRLF + CRLF
});
});
}
}
function dateTimeNowISO() {
return new Date().toISOString();
}
</pre>
</div>
</div>
</div>
</div>
</body>
</html>