Onenote API 创建页面
Onenote API create page
我正在尝试通过 OneNote 创建新页面 API。我正在关注 Microsoft tutorial and documentation.
似乎 header() 不工作。
graph-tutorial\graph.js:
createPage: async function(sectionID, content, accessToken) {
const client = getAuthenticatedClient(accessToken);
console.log('DEBUG:', '[Creating Pages]', sectionID);
const res = await client
.api(`/me/onenote/sections/${sectionID}/pages`)
.header({
'Content-type': 'application/xhtml+xml'
})
.post(content);
return res;
}
route\onenote.js:
let content =
`<!DOCTYPE html>
<html>
<head>
<title>${subject}</title>
<meta name="created" content="${creationDate}" />
</head>
<body>
${description}
</body>
</html>`
let page = await graph.createPage(section.id, content, accessToken);
错误:
{ statusCode: 400,
code: 'BadRequest',
message: 'Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.'
.... }
Content-type 应该是 Content-Type,Type 中大写 'T'。
header
方法有两个字符串参数("Key" 和 "Value")。来自 SDK sample:
client
.api('/me')
.header("content-type", "application/json")
.update({
"birthday": "1908-12-22T00:00:00Z"
})
.then((res) => {
console.log("Updated my birthday");
})
.catch((err) => {
console.log(err);
});
在你的情况下,你想要:
const res = await client
.api(`/me/onenote/sections/${sectionID}/pages`)
.header('Content-type', 'application/xhtml+xml')
.post(content);
我正在尝试通过 OneNote 创建新页面 API。我正在关注 Microsoft tutorial and documentation.
似乎 header() 不工作。
graph-tutorial\graph.js:
createPage: async function(sectionID, content, accessToken) {
const client = getAuthenticatedClient(accessToken);
console.log('DEBUG:', '[Creating Pages]', sectionID);
const res = await client
.api(`/me/onenote/sections/${sectionID}/pages`)
.header({
'Content-type': 'application/xhtml+xml'
})
.post(content);
return res;
}
route\onenote.js:
let content =
`<!DOCTYPE html>
<html>
<head>
<title>${subject}</title>
<meta name="created" content="${creationDate}" />
</head>
<body>
${description}
</body>
</html>`
let page = await graph.createPage(section.id, content, accessToken);
错误:
{ statusCode: 400,
code: 'BadRequest',
message: 'Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.'
.... }
Content-type 应该是 Content-Type,Type 中大写 'T'。
header
方法有两个字符串参数("Key" 和 "Value")。来自 SDK sample:
client
.api('/me')
.header("content-type", "application/json")
.update({
"birthday": "1908-12-22T00:00:00Z"
})
.then((res) => {
console.log("Updated my birthday");
})
.catch((err) => {
console.log(err);
});
在你的情况下,你想要:
const res = await client
.api(`/me/onenote/sections/${sectionID}/pages`)
.header('Content-type', 'application/xhtml+xml')
.post(content);