How to Update a Notion Database Item and Add Content to Its Page Blocks?

This topic was automatically generated from Slack. You can find the original thread here.

I need to update a Notion database item and add content to it’s page blocks, how do I do that?

To update a Notion database item and add content to its page blocks, you can use the Notion API with Pipedream. Below are the steps and code snippets to help you achieve this. ### Step-by-Step Guide 1. Search for the Notion app from the step menu in Pipedream. 2. Select the Update Page action. 3. Connect your Notion account. 4. Select a Parent Database ID or pass a string from a previous step. 5. Select a Page ID or pass a string from a previous step. 6. At the bottom of the step, click Test to run the action and test the configuration. ### Example Pipedream Component Code Here’s an example of how you can update a Notion database item and add content to its page blocks using Pipedream: ``` import { axios } from “@pipedream/platform”; export default defineComponent({ props: { notion: { type: “app”, app: “notion”, }, pageId: { type: “string”, label: “Page ID”, }, content: { type: “string”, label: “Content”, }, }, async run({ steps, $ }) { // Update the page properties (e.g., title) await axios($, { method: “patch”, url: https://api.notion.com/v1/pages/${this.pageId}, headers: { Authorization: Bearer ${this.notion.$auth.oauth_access_token}, “Notion-Version”: 2021-08-16, }, data: { properties: { title: [ { text: { content: “Updated Title”, }, }, ], }, }, }); // Add content to the page blocks return await axios($, { method: “patch”, url: https://api.notion.com/v1/blocks/${this.pageId}/children, headers: { Authorization: Bearer ${this.notion.$auth.oauth_access_token}, “Notion-Version”: 2021-08-16, }, data: { children: [ { object: “block”, type: “paragraph”, paragraph: { text: [ { type: “text”, text: {

can you show me a Python snippet on how to add a content block to a Notion page?

To add a content block to a Notion page using Python, you can use the Notion API. Below is a Python snippet that demonstrates how to add a content block to a Notion page. This example assumes you have already set up your Notion integration and have the necessary credentials. import requests def add_content_block_to_notion(page_id, content, notion_token): url = f"https://api.notion.com/v1/blocks/{page_id}/children" headers = { "Authorization": f"Bearer {notion_token}", "Content-Type": "application/json", "Notion-Version": "2021-08-16" } data = { "children": [ { "object": "block", "type": "paragraph", "paragraph": { "text": [ { "type": "text", "text": { "content": content } } ] } } ] } response = requests.patch(url, json=data, headers=headers) return response.json() # Example usage: page_id = "your_page_id" content = "This is a new content block." notion_token = "your_notion_token" response = add_content_block_to_notion(page_id, content, notion_token) print(response) ### Explanation 1. Imports: The requests library is used to make HTTP requests. 2. Function Definition: add_content_block_to_notion function takes three parameters: page_id, content, and notion_token. 3. URL: Constructs the URL to add a child block to the specified page. 4. Headers: Sets the necessary headers, including the Notion token for authorization and the Notion API version. 5. Data: Defines the content block to be added. In this case, it’s a paragraph block with the specified content. 6. Request: Makes a PATCH request to the Notion API to add the content block. 7. Response: Returns the JSON response from the API. ### Usage Replace your_page_id with the ID of the Notion page you want to add the content block to, your_notion_token with your Notion integration token, and content with the text you want to add. For more details on the Notion API,

how do I strip all Markdown and formatting from a Slack message to be able to copy it to a page in Notion?

To strip all Markdown and formatting from a Slack message and copy it to a page in Notion, you can use Pipedream to create a workflow that processes the Slack message and then sends the plain text to Notion. Here’s a step-by-step guide: 1. Trigger: Use a Slack trigger to capture the message. 2. Action: Use a Formatting action to strip the Markdown. 3. Action: Use a Notion action to create a page with the plain text. ### Step 1: Slack Trigger First, set up a Slack trigger to capture the message. You can use the “New Message Posted to Channel” trigger. ### Step 2: Formatting Action Next, use a Formatting action to strip the Markdown from the Slack message. Pipedream provides a pre-built action for this. 1. Search for the Formatting app from the step menu. 2. Select the [Text] Convert Markdown to Plain Text action. 3. Connect your Formatting account. 4. Select the Input or pass the string from the previous step (the Slack message). 5. At the bottom of the step, click Test to run the action and test the configuration. ### Step 3: Notion Action Finally, use a Notion action to create a page with the plain text. 1. Search for the Notion app from the step menu. 2. Select the Create Page action. 3. Connect your Notion account. 4. Configure the action to use the plain text from the previous step. Here’s an example of what the Pipedream component code might look like: ``` import { axios } from “@pipedream/platform”; export default defineComponent({ props: { slack: { type: “app”, app: “slack”, }, notion: { type: “app”, app: “notion”, }, }, async run({ steps, $ }) { // Step 1: Capture the Slack message const slackMessage = steps.trigger.event.text; // Step 2: Strip Markdown using Formatting action const plainText = slackMessage.replace(/[*_~]/g, ''); // Step 3: Create a page in Notion return await axios($, { url: https://api.notion.com/v1/pages`, method: “POST”, headers: { Authorization: `Bearer ${this