在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:makenotion/notion-sdk-js开源软件地址:https://github.com/makenotion/notion-sdk-js开源编程语言:TypeScript 99.6%开源软件介绍:Installation
Usage
Import and initialize a client using an integration token or an OAuth access token. const { Client } = require("@notionhq/client")
// Initializing a client
const notion = new Client({
auth: process.env.NOTION_TOKEN,
}) Make a request to any Notion API endpoint.
;(async () => {
const listUsersResponse = await notion.users.list({})
})() Each method returns a console.log(listUsersResponse)
Endpoint parameters are grouped into a single object. You don't need to remember which parameters go in the path, query, or body. const myPage = await notion.databases.query({
database_id: "897e5a76-ae52-4b48-9fdf-e71f5945d1af",
filter: {
property: "Landmark",
text: {
contains: "Bridge",
},
},
}) Handling errorsIf the API returns an unsuccessful response, the returned The error contains properties from the response, and the most helpful is const { Client, APIErrorCode } = require("@notionhq/client")
try {
const myPage = await notion.databases.query({
database_id: databaseId,
filter: {
property: "Landmark",
text: {
contains: "Bridge",
},
},
})
} catch (error) {
if (error.code === APIErrorCode.ObjectNotFound) {
//
// For example: handle by asking the user to select a different database
//
} else {
// Other error handling code
console.error(error)
}
} LoggingThe client emits useful information to a logger. By default, it only emits warnings and errors. If you're debugging an application, and would like the client to log response bodies, set the const { Client, LogLevel } = require("@notionhq/client")
const notion = new Client({
auth: process.env.NOTION_TOKEN,
logLevel: LogLevel.DEBUG,
}) You may also set a custom Client optionsThe
TypeScriptThis package contains type definitions for all request parameters and responses. Because errors in TypeScript start with type try {
const response = await notion.databases.query({
/* ... */
})
} catch (error: unknown) {
if (isNotionClientError(error)) {
// error is now strongly typed to NotionClientError
switch (error.code) {
case ClientErrorCode.RequestTimeout:
// ...
break
case APIErrorCode.ObjectNotFound:
// ...
break
case APIErrorCode.Unauthorized:
// ...
break
// ...
default:
// you could even take advantage of exhaustiveness checking
assertNever(error.code)
}
}
} RequirementsThis package supports the following minimum versions:
Earlier versions may still work, but we encourage people building new applications to upgrade to the current stable. Getting helpIf you want to submit a feature request for Notion's API, or are experiencing any issues with the API platform, please email us at To report issues with the SDK, it is possible to submit an issue to this repo. However, we don't monitor these issues very closely. We recommend you reach out to us at |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论