### Start Local Notion Demo Project Source: https://developers.notion.com/docs/create-a-notion-integration This command initiates the local demo project. After setting up the environment variables and installing dependencies, running this command will start the server, allowing you to access the Notion API integration through your browser. ```shell npm start ``` -------------------------------- ### Clone Notion Demo Repo and Install Dependencies Source: https://developers.notion.com/docs/create-a-notion-integration This snippet demonstrates how to clone the Notion cookbook repository and install the necessary Node.js dependencies (Express.js, dotenv, and Notion SDK for JavaScript) to run the web form demo locally. It assumes you have Git and npm installed. ```shell git clone https://github.com/makenotion/notion-cookbook.git cd notion-cookbook/examples/javascript/web-form-with-express/ npm install ``` -------------------------------- ### Initialize Notion Client with Authentication Token (JavaScript) Source: https://developers.notion.com/docs/authorization-asisd03rii This JavaScript code snippet shows how to initialize the Notion SDK client using an authentication token stored in an environment variable. It demonstrates the basic setup for making authenticated calls to the Notion API. ```JavaScript const { Client } = require("@notionhq/client") // Initializing a client const notion = new Client({ auth: process.env.NOTION_TOKEN, }) const getUsers = async () => { const listUsersResponse = await notion.users.list({}) } ``` -------------------------------- ### Database Object Example (JSON) Source: https://developers.notion.com/docs/working-with-databases An example of a Notion database object, illustrating its structure, including ID, title, parent, data sources, and other metadata. ```json { "object": "database", "id": "248104cd-477e-80fd-b757-e945d38000bd", "title": [ { "type": "text", "text": { "content": "Grocery DB", "// ...": "" }, "// ...": "" } ], "parent": { "type": "page_id", "page_id": "255104cd-477e-808c-b279-d39ab803a7d2" }, "is_inline": false, "in_trash": false, "created_time": "2025-08-07T10:11:07.504-07:00", "last_edited_time": "2025-08-10T15:53:11.386-07:00", "data_sources": [ { "id": "248104cd-477e-80af-bc30-000bd28de8f9", "name": "Grocery list" } ], "url": "https://www.notion.so/example/248104cd477e80fdb757e945d38000bd", "icon": null, "cover": { "type": "external", "external": { "url": "https://website.domain/images/image.png" } } } ``` -------------------------------- ### Refresh Access Token (Node.js) Source: https://developers.notion.com/docs/authorization-asisd03rii This Node.js example shows how to refresh an access token using the fetch API. It covers setting up client credentials, base64 encoding them for Basic authentication, and constructing the POST request with the appropriate headers and JSON body. ```javascript const clientId = process.env.OAUTH_CLIENT_ID; const clientSecret = process.env.OAUTH_CLIENT_SECRET; // encode in base 64 const encoded = btoa(`${clientId}:${clientSecret}`); const response = await fetch("https://api.notion.com/v1/oauth/token", { method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json", Authorization: `Basic ${encoded}`, }, body: JSON.stringify({ grant_type: "refresh_token", refresh_token: "your-refresh-token", }), }); ``` -------------------------------- ### Install Notion SDK for JavaScript Source: https://developers.notion.com/docs/api-sdk-for-typescript-and-javascript Installs the Notion SDK for JavaScript using npm. This is the first step to integrating Notion's API into your JavaScript applications. ```bash npm install @notionhq/client ``` -------------------------------- ### External Authorization Setup Form Source: https://developers.notion.com/docs/build-a-link-preview-integration This section outlines the fields required in the External Authorization Setup form within Notion to enable user authentication and link previews. ```APIDOC ## External Authorization Setup ### Description Configure Notion to authenticate users with your service and enable Link Preview functionality by providing the necessary OAuth credentials and URLs. ### Method Not Applicable (Form Configuration) ### Endpoint Not Applicable (Form Configuration) ### Parameters #### Form Fields - **OAuth Authorize URL** (string) - Required - The URL Notion redirects users to for authorization. It receives a `code` query parameter for token exchange. - **OAuth Token URL** (string) - Required - The URL Notion POSTs to, exchanging a `code` for an `access_token` to make authenticated requests to your systems. - **OAuth Client ID** (string) - Required - The client ID used by Notion in requests to your OAuth URLs. - **OAuth Client Secret** (string) - Required - The client secret used by Notion in requests to your OAuth URLs. - **OAuth Scopes** (string) - Optional - A string of scopes to be sent as a parameter in the request to your OAuth Authorize URL. - **Deleted Token Callback URL** (string) - Optional - A URL that receives a DELETE request from Notion when a user disconnects your integration or removes a Link Preview, allowing you to revoke tokens. ### Request Example Not Applicable (Form Configuration) ### Response #### Success Response (200) Not Applicable (Form Configuration) #### Response Example Not Applicable (Form Configuration) ``` -------------------------------- ### Data Source Object Example (JSON) Source: https://developers.notion.com/docs/working-with-databases An example of a Notion data source object, detailing its properties, schema, parent information, and metadata. The 'properties' object defines the columns of the data source. ```json { "object": "data_source", "id": "248104cd-477e-80af-bc30-000bd28de8f9", "created_time": "2021-07-08T23:50:00.000Z", "last_edited_time": "2021-07-08T23:50:00.000Z", "properties": { "Grocery item": { "id": "fy%3A%7B", "type": "title", "title": {} }, "Price": { "id": "dia%5B", "type": "number", "number": { "format": "dollar" } }, "Last ordered": { "id": "%5D%5C%5CR%5B", "type": "date", "date": {} } }, "parent": { "type": "database_id", "database_id": "248104cd-477e-80fd-b757-e945d38000bd" }, "database_parent": { "type": "page_id", "page_id": "255104cd-477e-808c-b279-d39ab803a7d2" }, "archived": false, "icon": { "type": "emoji", "emoji": "🎉" }, "title": [ { "type": "text", "text": { "content": "Grocery list", "link": null } } ] } ``` -------------------------------- ### Set Required Headers for Notion API Requests (JSON) Source: https://developers.notion.com/docs/authorization-asisd03rii This example shows the necessary headers for making requests to the Notion API when not using the JavaScript SDK. It includes the Authorization token, Notion-Version, and Content-Type, which are crucial for successful API interactions. ```JSON headers: { Authorization: `Bearer ${process.env.NOTION_TOKEN}`, "Notion-Version": "2022-06-28", "Content-Type": "application/json", } ``` -------------------------------- ### Example Bot User API Response for File Size Limits (JSON) Source: https://developers.notion.com/docs/working-with-files-and-media An example JSON object representing a response from the Notion Bot User API, illustrating the structure for a free workspace with a file upload limit of 5 MiB. This helps developers understand the data format for `max_file_upload_size_in_bytes`. ```json { "object": "user", "id": "be51669b-1932-4a11-8d35-38fbc2e1e4fd", "type": "bot", "bot": { "owner": { "type": "workspace" }, "workspace_name": "Cat's Notion", "workspace_limits": { "max_file_upload_size_in_bytes": 5242880 } } } ``` -------------------------------- ### Environment Variables for Notion Integration Secrets Source: https://developers.notion.com/docs/authorization Example of an .env file to store sensitive integration credentials like client ID, client secret, and authorization URL. These should not be committed to version control. ```shell #.env OAUTH_CLIENT_ID= OAUTH_CLIENT_SECRET= NOTION_AUTH_URL= ``` -------------------------------- ### Link Preview Integrations Updates Source: https://developers.notion.com/docs/historical-changelog Documentation updates for Link Preview integrations, including getting started, introduction, building guides, and unfurl attribute object reference. ```APIDOC ## Link Preview Integrations ### Description Guides and API reference documentation for Link Preview integrations have been updated to enhance clarity and ease of use for developers. ### Method N/A (Documentation Update) ### Endpoint N/A (Documentation Update) ### Parameters N/A ### Request Example N/A ### Response N/A **Updated Guides and References:** * Getting started guide: https://developers.notion.com/docs/getting-started * Introduction to Link Previews guide: https://developers.notion.com/docs/link-previews * Building a Link Preview integration guide: https://developers.notion.com/docs/build-a-link-preview-integration * Unfurl attribute object docs: https://developers.notion.com/reference/unfurl-attribute-object ``` -------------------------------- ### Initialize Express Server and Notion Client (server.ts) Source: https://developers.notion.com/docs/create-a-notion-integration Sets up an Express.js server, configures static file serving, defines a root route, and initializes the Notion client using an API key from environment variables. This is the foundational setup for interacting with the Notion API. ```typescript require("dotenv").config(); const express = require("express"); const app = express(); // Notion SDK for JavaScript const { Client } = require("@notionhq/client"); const notion = new Client({ auth: process.env.NOTION_KEY }); // app.use(express.static("public")); // app.get("/", function(request, response) { response.sendFile(__dirname + "/views/index.html"); }); // listen for requests const listener = app.listen(process.env.PORT, function() { console.log("Your app is listening on port " + listener.address().port); }); ``` -------------------------------- ### Rich Text Property Name Change in Notion API Versions Source: https://developers.notion.com/docs/versioning This example illustrates a backwards-incompatible change in the Notion API where the 'text' property for rich text was renamed to 'rich_text' starting from version '2021-05-13'. It shows the JSON structure before and after the change. ```json // Prior to version 2021-05-13, the rich text property is called "text" "properties": { "Description": { "type": "text", "text": [/* ... */] } } // In version 2021-05-13, the rich text property is now called "rich_text" "properties": { "Description": { "type": "rich_text", "rich_text": [/* ... */] } } ``` -------------------------------- ### Create Notion Database using SDK (server.ts) Source: https://developers.notion.com/docs/create-a-notion-integration Demonstrates the core logic for creating a new database using the Notion SDK. It specifies the parent page, the database title, and the initial properties for the database schema. ```typescript await notion.databases.create({...options}) ``` -------------------------------- ### Retrieve a Block with Notion API (cURL) Source: https://developers.notion.com/docs/historical-changelog This example demonstrates how to retrieve a specific block using the Notion API's GET endpoint. It requires an authorization token and specifies the API version. The response is a JSON object representing the block. ```curl curl 'https://api.notion.com/v1/blocks/9bc30ad4-9373-46a5-84ab-0a7845ee52e6' \ -H 'Authorization: Bearer '"$NOTION_API_KEY"'' \ -H 'Notion-Version: 2021-05-13' ``` -------------------------------- ### Exchange Authorization Code for Access Token (HTTP & Node.js) Source: https://developers.notion.com/docs/authorization-asisd03rii Shows how to make a POST request to the Notion API's token endpoint to exchange a temporary authorization code for an access token. It includes examples for raw HTTP requests and a Node.js implementation using fetch, demonstrating the required headers and JSON body. ```http POST /v1/oauth/token HTTP/1.1 Authorization: Basic "CLIENT_ID:CLIENT_SECRET" Content-Type: application/json {"grant_type":"authorization_code","code":"e202e8c9-0990-40af-855f-ff8f872b1ec6", "redirect_uri":"https://example.com/auth/notion/callback"} ``` ```javascript const clientId = process.env.OAUTH_CLIENT_ID; const clientSecret = process.env.OAUTH_CLIENT_SECRET; const redirectUri = process.env.OAUTH_REDIRECT_URI; // encode in base 64 const encoded = btoa(`${clientId}:${clientSecret}`); const response = await fetch("https://api.notion.com/v1/oauth/token", { method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json", Authorization: `Basic ${encoded}`, }, body: JSON.stringify({ grant_type: "authorization_code", code: "your-temporary-code", redirect_uri: redirectUri, }), }); // Handle the response to get the access_token const data = await response.json(); ``` -------------------------------- ### notion-create-database Source: https://developers.notion.com/docs/mcp-supported-tools Creates a new Notion database, initial data source, and initial view with the specified properties. ```APIDOC ## POST /api/notion/create-database ### Description Creates a new Notion database with specified properties and an initial view. ### Method POST ### Endpoint /api/notion/create-database ### Parameters #### Request Body - **parent_page_id** (string) - Required - The ID of the parent page where the database will be created. - **title** (string) - Required - The title of the new database. - **properties** (object) - Required - An object defining the properties (columns) of the database. - Example: `{"Name": {"title": {}}}` - **initial_view_name** (string) - Optional - The name for the initial view of the database. ### Request Example ```json { "parent_page_id": "parent_page_id_for_database", "title": "Customer Feedback Tracker", "properties": { "Customer Name": {"rich_text": {}}, "Feedback Type": {"select": {"options": [{"name": "Bug Report"}, {"name": "Feature Request"}, {"name": "General"}]}}, "Priority": {"select": {"options": [{"name": "High"}, {"name": "Medium"}, {"name": "Low"}]}}, "Status": {"select": {"options": [{"name": "Open"}, {"name": "In Progress"}, {"name": "Closed"}]}} }, "initial_view_name": "All Feedback" } ``` ### Response #### Success Response (200) - **database_id** (string) - The ID of the newly created database. - **url** (string) - The URL of the new database. #### Response Example ```json { "database_id": "new_database_id_abc", "url": "https://notion.so/new_database_id_abc" } ``` ``` -------------------------------- ### Database Object Example Source: https://developers.notion.com/docs/historical-changelog An example of a Notion database object, illustrating its structure and properties. ```APIDOC ## GET /databases/{database_id} ### Description Retrieves a database object, providing details about its structure, properties, and parent page. ### Method GET ### Endpoint `/databases/{database_id}` ### Parameters #### Path Parameters - **database_id** (string) - Required - The ID of the database to retrieve. ### Response #### Success Response (200) - **object** (string) - Type of object, should be "database". - **id** (string) - The unique identifier for the database. - **created_time** (string) - The date and time the database was created. - **last_edited_time** (string) - The date and time the database was last edited. - **title** (array) - An array of rich text objects representing the database title. - **properties** (object) - An object containing the schema of the database's properties. - **parent** (object) - An object describing the parent of the database. #### Response Example ```json { "object": "database", "id": "bc1211ca-e3f1-4939-ae34-5260b16f627c", "created_time": "2021-07-08T23:50:00.000Z", "last_edited_time": "2021-07-08T23:50:00.000Z", "title": [ { "type": "text", "text": { "content": "Grocery List", "link": null }, "annotations": { "bold": false, "italic": false, "strikethrough": false, "underline": false, "code": false, "color": "default" }, "plain_text": "Grocery List", "href": null } ], "properties": { "+1": { "id": "PNEQ", "type": "people", "people": {} }, "In stock": { "id": "V>GQ", "type": "checkbox", "checkbox": {} }, "Price": { "id": "V@]u", "type": "number", "number": { "format": "dollar" } }, "Description": { "id": "V}lX", "type": "rich_text", "rich_text": {} }, "Last ordered": { "id": "eVnV", "type": "date", "date": {} }, "Store availability": { "id": "s}Kq", "type": "multi_select", "multi_select": { "options": [ { "id": "cb79b393-d1c1-4528-b517-c450859de766", "name": "Duc Loi Market", "color": "blue" }, { "id": "58aae162-75d4-403b-a793-3bc7308e4cd2", "name": "Rainbow Grocery", "color": "gray" }, { "id": "22d0f199-babc-44ff-bd80-a9eae3e3fcbf", "name": "Nijiya Market", "color": "purple" }, { "id": "0d069987-ffb0-4347-bde2-8e4068003dbc", "name": "Gus's Community Market", "color": "yellow" } ] } }, "Photo": { "id": "yfiK", "type": "files", "files": {} }, "Food group": { "id": "|JKd", "type": "select", "select": { "options": [ { "id": "6d4523fa-88cb-4ffd-9364-1e39d0f4e566", "name": "🥦Vegetable", "color": "green" }, { "id": "268d7e75-de8f-4c4b-8b9d-de0f97021833", "name": "🍎Fruit", "color": "red" }, { "id": "1b234a00-dc97-489c-b987-829264cfdfef", "name": "💪Protein", "color": "yellow" } ] } }, "Name": { "id": "title", "type": "title", "title": {} } }, "parent": { "type": "page_id", "page_id": "98ad959b-2b6a-4774-80ee-00246fb0ea9b" } } ``` ``` -------------------------------- ### Making API Requests with Internal Integration Token Source: https://developers.notion.com/docs/authorization Demonstrates how to make an HTTP GET request to the Notion API, including the required Authorization header with an integration token. It also shows how to initialize the Notion SDK for JavaScript client with the token. ```http GET /v1/pages/b55c9c91-384d-452b-81db-d1ef79372b75 HTTP/1.1 Authorization: Bearer {INTEGRATION_TOKEN} ``` ```javascript const { Client } = require("@notionhq/client") // Initializing a client const notion = new Client({ auth: process.env.NOTION_TOKEN, }) const getUsers = async () => { const listUsersResponse = await notion.users.list({}) } ``` -------------------------------- ### Database Query Filtering and Sorting Examples Source: https://developers.notion.com/docs/historical-changelog Expanded code examples for filtering and sorting database queries using the Notion SDK for JavaScript. ```APIDOC ## Database Query Filtering and Sorting ### Description Documentation for filtering and sorting database queries now includes more code examples, specifically for developers using the Notion SDK for JavaScript. ### Method N/A (Documentation Update) ### Endpoint N/A (Documentation Update) ### Parameters N/A ### Request Example N/A ### Response N/A **Relevant Documentation:** * Filtering: https://developers.notion.com/reference/post-database-query-filter * Sorting: https://developers.notion.com/reference/post-database-query-sort * Notion SDK for JavaScript: https://github.com/makenotion/notion-sdk-js ``` -------------------------------- ### Working with Comments Guide Update Source: https://developers.notion.com/docs/historical-changelog The guide on 'Working with comments' has been updated to clarify the process of retrieving and adding comments via the REST API. ```APIDOC ## Working with Comments ### Description The guide on working with comments has been revised to provide clearer instructions on how to retrieve and add comments using the Notion REST API. ### Method N/A (Documentation Update) ### Endpoint N/A (Documentation Update) ### Parameters N/A ### Request Example N/A ### Response N/A **Learn more:** * Working with comments guide: https://developers.notion.com/docs/working-with-comments ``` -------------------------------- ### POST /databases Source: https://developers.notion.com/docs/create-a-notion-integration Handles the creation of a new Notion database. It takes a database name from the request body and uses environment variables for authentication and parent page ID. ```APIDOC ## POST /databases ### Description Creates a new Notion database with a specified title and a single 'Name' property. ### Method POST ### Endpoint /databases ### Parameters #### Query Parameters None #### Path Parameters None #### Request Body - **dbName** (string) - Required - The desired name for the new Notion database. ### Request Example ```json { "dbName": "My New Database" } ``` ### Response #### Success Response (200) - **message** (string) - Indicates the success of the operation ('success!'). - **data** (object) - The response object from the Notion API containing details of the created database. #### Error Response (e.g., 500) - **message** (string) - Indicates an error occurred ('error'). - **error** (object) - The error object returned from the Notion API. #### Response Example (Success) ```json { "message": "success!", "data": { "object": "database", "id": "", "title": [ { "type": "text", "text": { "content": "My New Database", "link": null } } ], "properties": { "Name": { "title": {} } } // ... other database properties } } ``` #### Response Example (Error) ```json { "message": "error", "error": { "code": "unauthorized", "message": "Invalid API key provided." } } ``` ``` -------------------------------- ### Exchange Authorization Code for Access Token (Node.js) Source: https://developers.notion.com/docs/authorization Provides a Node.js example using `fetch` to exchange the authorization code for an access token. It shows how to retrieve client credentials from environment variables, base64 encode them for the Authorization header, and construct the JSON body for the POST request to the Notion API's token endpoint. ```javascript const clientId = process.env.OAUTH_CLIENT_ID; const clientSecret = process.env.OAUTH_CLIENT_SECRET; const redirectUri = process.env.OAUTH_REDIRECT_URI; // encode in base 64 const encoded = btoa(`${clientId}:${clientSecret}`); const response = await fetch("https://api.notion.com/v1/oauth/token", { method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json", Authorization: `Basic ${encoded}`, }, body: JSON.stringify({ grant_type: "authorization_code", code: "your-temporary-code", redirect_uri: redirectUri, }), }); ... ``` -------------------------------- ### Make a Notion API Request (List Users) Source: https://developers.notion.com/docs/api-sdk-for-typescript-and-javascript Demonstrates making a request to the Notion API to list users. The SDK abstracts away the complexities of request formatting and response handling. ```javascript ;(async () => { const listUsersResponse = await notion.users.list({}) }) () ``` -------------------------------- ### Relation Property Response Example Source: https://developers.notion.com/docs/upgrade-guide-2025-09-03 An example JSON response illustrating a relation property in Notion, showing both `database_id` and `data_source_id`. This is used for understanding how relations are represented. ```json "Projects": { "id": "~pex", "name": "Projects", "type": "relation", "relation": { "database_id": "6c4240a9-a3ce-413e-9fd0-8a51a4d0a49b", "data_source_id": "a42a62ed-9b51-4b98-9dea-ea6d091bc508", "dual_property": { "synced_property_name": "Tasks", "synced_property_id": "JU]K" } } } ``` -------------------------------- ### Initialize Notion Client with Token Source: https://developers.notion.com/docs/api-sdk-for-typescript-and-javascript Initializes the Notion client using an integration token or an OAuth access token. The token is typically stored in environment variables for security. ```javascript const { Client } = require("@notionhq/client") // Initializing a client const notion = new Client({ auth: process.env.NOTION_TOKEN, }) ``` -------------------------------- ### Query and Filter Database Entries Examples Source: https://developers.notion.com/docs/historical-changelog Additional code examples have been added to the 'Query a database' and 'Filter database entries' documentation, illustrating the use of single and multiple filters. ```APIDOC ## Query and Filter Database Entries ### Description Documentation for querying and filtering database entries has been updated with more code examples demonstrating how to pass single and multiple filters. ### Method N/A (Documentation Update) ### Endpoint N/A (Documentation Update) ### Parameters N/A ### Request Example N/A ### Response N/A **Relevant Documentation:** * Query a database: https://developers.notion.com/reference/post-database-query * Filter database entries: https://developers.notion.com/reference/post-database-query-filter ``` -------------------------------- ### HTML Form for Database Creation (index.html) Source: https://developers.notion.com/docs/create-a-notion-integration This HTML snippet defines a form for users to create a new database by providing a name. It also includes a designated table cell (`dbResponse`) where API responses will be displayed. The structure is set up to work with client-side JavaScript for dynamic interactions. ```html ... ... ... ...

1. Create a new database

... ``` -------------------------------- ### Retrieve Inline Database Block Example (JSON) Source: https://developers.notion.com/docs/historical-changelog Example JSON response from the Retrieve block children endpoint showcasing an inline database block. This block contains a title for the database. ```json { "object": "list", "results": [ { "object": "block", "id": "0d6ff4f9-1211-4129-ab4a-19dfc33d4d7a", "created_time": "2021-09-27T20:25:00.000Z", "last_edited_time": "2021-09-27T20:25:00.000Z", "has_children": false, "archived": false, "type": "child_database", "child_database": { "title": "My child database" } } ], "next_cursor": null, "has_more": false } ``` -------------------------------- ### Example Paginated Response Structure Source: https://developers.notion.com/docs/working-with-page-content This is an example JSON structure for a paginated response from the Notion API when retrieving block children. It includes the list of results, a flag for more data, and a cursor for pagination. ```json { "object": "list", "results": [ { "object": "block", /* details omitted */ } ], "has_more": false, "next_cursor": null } ``` -------------------------------- ### Create a Page in Notion Data Source (cURL) Source: https://developers.notion.com/docs/working-with-databases Demonstrates how to send a POST request to the Notion API to create a new page. It includes the necessary headers for authorization, content type, and API version, along with the 'parent' and 'properties' in the request body. ```curl curl -X POST https://api.notion.com/v1/pages \ -H 'Authorization: Bearer שלך_NOTION_API_KEY' \ -H "Content-Type: application/json" \ -H "Notion-Version: 2022-06-28" \ --data '{ "parent": { "type": "data_source_id", "data_source_id": "248104cd-477e-80af-bc30-000bd28de8f9" }, "properties": { "Grocery item": { "type": "title", "title": [{ "type": "text", "text": { "content": "Tomatoes" } }] }, "Price": { "type": "number", "number": 1.49 }, "Last ordered": { "type": "date", "date": { "start": "2021-05-11" } } } }' ``` -------------------------------- ### Create a Page with Content using Notion API (JavaScript) Source: https://developers.notion.com/docs/working-with-page-content Example using the official Notion JavaScript client to create a new page. It demonstrates how to instantiate the client and call the 'pages.create' method with parent, properties, and children. ```javascript const { Client } = require('@notionhq/client'); const notion = new Client({ auth: process.env.NOTION_API_KEY }); (async () => { const response = await notion.pages.create({ parent: { page_id: '494c87d072c44cf6960f55f8427f7692', }, properties: { title: { type: 'title', title: [ { type: 'text', text: { content: 'A note from your pals at Notion', }, }, ], }, }, children: [ { object: 'block', type: 'paragraph', paragraph: { text: [ { type: 'text', text: { content: 'You made this page using the Notion API. Pretty cool, huh? We hope you enjoy building with us.', }, }, ], }, }, ], }); console.log(response); })(); ``` -------------------------------- ### Retrieve Code Block Example (JSON) Source: https://developers.notion.com/docs/historical-changelog Example JSON response from the Retrieve block children endpoint showing a code block. This block includes text content and specifies the programming language. ```json { "object": "list", "results": [ { "object": "block", "id": "ee27cd42-eaad-467f-9956-c0aa4efa94b5", "created_time": "2021-09-22T20:27:00.000Z", "last_edited_time": "2021-09-27T19:25:00.000Z", "has_children": false, "archived": false, "type": "code", "code": { "text": [ { "type": "text", "text": { "content": "const a = 21\nconst b = a + 5", "link": null }, "annotations": { "bold": false, "italic": false, "strikethrough": false, "underline": false, "code": false, "color": "default" }, "plain_text": "const a = 21\nconst b = a + 5", "href": null } ], "language": "javascript" } } ], "next_cursor": null, "has_more": false } ``` -------------------------------- ### Initialize Notion Client (server.ts) Source: https://developers.notion.com/docs/create-a-notion-integration Initializes the Notion client instance, which is essential for making authenticated requests to the Notion API. It uses the Notion API key stored in environment variables for authentication. ```jsx const { Client } = require("@notionhq/client"); const notion = new Client({ auth: process.env.NOTION_KEY }); ```