This topic was automatically generated from Slack. You can find the original thread here.
I need to create a workflow that takes updates from Notion database items and copies the page content into a new page, referencing each other using Notion’s “relation” property
To create a workflow that takes updates from Notion database items and copies the page content into a new page, referencing each other using Notion’s “relation” property, you can follow these steps: 1. Trigger: Use the “Updated Page in Database” trigger to detect updates in your Notion database. 2. Action: Use a custom code step to copy the page content and create a new page with a relation property. Here’s a step-by-step guide: ### Step 1: Set up the Trigger 1. Search for the Notion app from the trigger menu. 2. Select the “Updated Page in Database” trigger. 3. Connect your Notion account. 4. Select a Database ID or pass a string from a previous step. 5. Select “Include New Pages” or pass a boolean from a previous step. 6. Follow the instructions on the trigger configuration screen. You may need to generate a test event from Notion to get real data to test your workflow. ### Step 2: Add a Custom Code Step Add a custom code step to copy the page content and create a new page with a relation property. Here’s an example of how you can achieve this: ``` import { axios } from “@pipedream/platform”; export default defineComponent({ props: { notion: { type: “app”, app: “notion”, }, }, async run({ steps, $ }) { const updatedPageId = steps.trigger.event.id; // Fetch the updated page content const pageContent = await axios($, { url: https://api.notion.com/v1/blocks/${updatedPageId}/children, headers: { Authorization: Bearer ${this.notion.$auth.oauth_access_token}, “Notion-Version”: 2021-08-16, }, }); // Create a new page with the copied content const newPage = await axios($, { method: “POST”, url: https://api.notion.com/v1/pages, headers: { Authorization: Bearer ${this.notion.$auth.oauth_access_token}, “Notion-Version”: 2021-08-16, }, data: { parent: { database_id: “YOUR_DATABASE_ID” }, properties: { title: { title: [ { text: { content: "
It seems like the code snippet you received was incomplete. Could you please provide more details about the specific code snippet you are referring to? For example, what functionality was the code supposed to implement, or what was the context in which it was used? This will help me provide you with the complete and correct code. If you have any specific requirements or additional information, please share them as well.
The code was about: “Add a custom code step to copy the page content and create a new page with a relation property. Here’s an example of how you can achieve this:”
To help you add a custom code step to copy the page content and create a new page with a relation property in Pipedream, I’ll need a bit more information: 1. Which app or service are you using to manage the pages? For example, are you using Notion, Confluence, or another service? 2. What specific data or properties do you want to copy from the original page to the new page? 3. How do you want to define the relation property between the original and new page? Once I have this information, I can provide a more accurate and detailed example.
the code is: copy a Notion database page content into a new page in a different Database, and create a relation between both pages using the “relation” database property
To copy a Notion database page content into a new page in a different database and create a relation between both pages using the “relation” database property, you can use the Notion API within a Pipedream component. Below is an example of how you can achieve this: 1. Fetch the content of the original page. 2. Create a new page in the target database. 3. Update the relation property to link the two pages. Here’s the Pipedream component code to perform these steps: ``` import { axios } from “@pipedream/platform”; export default defineComponent({ props: { notion: { type: “app”, app: “notion”, }, sourcePageId: { type: “string”, label: “Source Page ID”, }, targetDatabaseId: { type: “string”, label: “Target Database ID”, }, relationPropertyId: { type: “string”, label: “Relation Property ID”, }, }, async run({ steps, $ }) { // Step 1: Fetch the content of the original page const sourcePage = await axios($, { url: https://api.notion.com/v1/pages/${this.sourcePageId}, headers: { Authorization: Bearer ${this.notion.$auth.oauth_access_token}, “Notion-Version”: 2021-08-16, }, }); // Extract the properties from the source page const sourceProperties = sourcePage.properties; // Step 2: Create a new page in the target database const newPage = await axios($, { method: “POST”, url: https://api.notion.com/v1/pages, headers: { Authorization: Bearer ${this.notion.$auth.oauth_access_token}, “Notion-Version”: 2021-08-16, }, data: { parent: { database_id: this.targetDatabaseId }, properties: sourceProperties, }, }); // Step 3: Update the relation property to link the two pages const updatedPage = await axios($, { method: “PATCH”, url: https://api.notion.com/v1/pages/${newPage.id}, headers: { Authorization: Bearer ${this.notion.$auth.oauth_access_token},