How to merge all data from different notion pages in one single content?

Hi dear Community,

(First time I use n8n :wink: )

In Notion, I have a “dummy” database of user interviews. My goal is to get all answers from all interviews and merge them into one single content and send it to OpenAI.

I’ve managed until now to get the database, get all the pages, get all content from all pages. The JS function’s return is always empty…
I want in the JS function to extract all “content” dynamically from type “paragraph”.

  1. Output GetTheDatabase
[
  {
    "id": "18b299d1-8572-81d7-bebf-df5786e888ae",
    "name": "Interviews Database",
    "url": "https://www.notion.so/18b299d1857281d7bebfdf5786e888ae"
  }
]
  1. Output getAllPages
[
  {
    "id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "name": "Test 2 - Interview",
    "url": "https://www.notion.so/Test-2-Interview-18c299d185728051b9fdceb72bbabd7b",
    "property_topic": "",
    "property_status": "To Do",
    "property_interviewer": [],
    "property_occupation": [],
    "property_company": [],
    "property_date": null,
    "property_user_name": "Test 2 - Interview"
  },
  {
    "id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "name": "Test 1 - Interview",
    "url": "https://www.notion.so/Test-1-Interview-18c299d1857280e390f5d4d9592431de",
    "property_topic": "",
    "property_status": "To Do",
    "property_interviewer": [],
    "property_occupation": [],
    "property_company": [],
    "property_date": null,
    "property_user_name": "Test 1 - Interview"
  }
]
  1. Output getAllContentFromAllPages
[
  {
    "object": "block",
    "parent_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "id": "18c299d1-8572-814e-8a43-d5830beca6be",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "heading_3",
    "root_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "content": "Question : Peux-tu décrire ton utilisation quotidienne de l'application ?"
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "id": "18c299d1-8572-8190-acf9-fe73a873f3f7",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "paragraph",
    "root_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "content": "🗣 Réponse : \"Je l'utilise principalement le matin pour consulter mes tâches et programmer ma journée. En fin de journée, je vérifie mes progrès et coche les éléments complétés.\""
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "id": "18c299d1-8572-8132-a42d-cac647e60da3",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "heading_3",
    "root_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "content": "Question : As-tu rencontré des difficultés en utilisant l'application ?"
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "id": "18c299d1-8572-81a1-a434-cb1bc1b7d5b2",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "paragraph",
    "root_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "content": "🗣 Réponse : \"Oui, la navigation n'est pas très intuitive. Il m'a fallu du temps pour comprendre où trouver certaines fonctionnalités, surtout dans les paramètres.\""
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "id": "18c299d1-8572-81c5-a0a4-c9d212579a4c",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "heading_3",
    "root_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "content": "Question : Qu'est-ce que tu apprécies le plus dans l'application ?"
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "id": "18c299d1-8572-8123-a49a-de9b738e6006",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "paragraph",
    "root_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "content": "🗣 Réponse : \"J'adore la synchronisation automatique avec mon calendrier. Cela me permet d'avoir tout centralisé et de ne rien oublier.\""
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "id": "18c299d1-8572-8198-8829-d6c8c6f42a53",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "heading_3",
    "root_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "content": "Question : Y a-t-il une fonctionnalité que tu aimerais voir améliorée ou ajoutée ?"
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "id": "18c299d1-8572-812a-b12f-c97a8c2c9457",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "paragraph",
    "root_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "content": "🗣 Réponse : \"J'aimerais un mode hors-ligne. Lorsque je suis en déplacement sans connexion, je ne peux pas accéder à mes notes, ce qui est frustrant.\""
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "id": "18c299d1-8572-81d7-838a-ff0f3584a28d",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "heading_3",
    "root_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "content": "Question : Recommanderais-tu cette application à d'autres personnes ? Pourquoi ?"
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "id": "18c299d1-8572-81cb-8eb3-d3c012a72005",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "paragraph",
    "root_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "content": "🗣 Réponse : \"Oui, mais avec quelques réserves. Elle est très utile pour l'organisation, mais elle gagnerait à être plus intuitive et accessible aux nouveaux utilisateurs.\""
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "id": "18c299d1-8572-81f5-ad6c-dddedd014010",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "heading_3",
    "root_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "content": ""
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "id": "18c299d1-8572-81f0-a058-eac5b3011c57",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "heading_3",
    "root_id": "18c299d1-8572-8051-b9fd-ceb72bbabd7b",
    "content": ""
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "id": "18c299d1-8572-8065-8233-f9c148382ee8",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-80e3-90f5-d4d9592431de"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "heading_3",
    "root_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "content": "Question : Peux-tu décrire ton utilisation quotidienne de l'application ?"
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "id": "18c299d1-8572-8060-88c8-c4aace4b28a1",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-80e3-90f5-d4d9592431de"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "paragraph",
    "root_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "content": "🗣 Réponse : \"Je l'utilise principalement le matin pour consulter mes tâches et programmer ma journée. En fin de journée, je vérifie mes progrès et coche les éléments complétés.\""
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "id": "18c299d1-8572-8086-9399-f3fcf4224c47",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-80e3-90f5-d4d9592431de"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "heading_3",
    "root_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "content": "Question : As-tu rencontré des difficultés en utilisant l'application ?"
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "id": "18c299d1-8572-8078-9d65-c230ab61e322",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-80e3-90f5-d4d9592431de"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "paragraph",
    "root_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "content": "🗣 Réponse : \"Oui, la navigation n'est pas très intuitive. Il m'a fallu du temps pour comprendre où trouver certaines fonctionnalités, surtout dans les paramètres.\""
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "id": "18c299d1-8572-8080-b735-c0be6b030034",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-80e3-90f5-d4d9592431de"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "heading_3",
    "root_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "content": "Question : Qu'est-ce que tu apprécies le plus dans l'application ?"
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "id": "18c299d1-8572-8059-afae-d2ed0c9d0e43",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-80e3-90f5-d4d9592431de"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "paragraph",
    "root_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "content": "🗣 Réponse : \"J'adore la synchronisation automatique avec mon calendrier. Cela me permet d'avoir tout centralisé et de ne rien oublier.\""
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "id": "18c299d1-8572-802d-938e-cff2042958d3",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-80e3-90f5-d4d9592431de"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "heading_3",
    "root_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "content": "Question : Y a-t-il une fonctionnalité que tu aimerais voir améliorée ou ajoutée ?"
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "id": "18c299d1-8572-8098-ba4e-f83cb1985c79",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-80e3-90f5-d4d9592431de"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "paragraph",
    "root_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "content": "🗣 Réponse : \"J'aimerais un mode hors-ligne. Lorsque je suis en déplacement sans connexion, je ne peux pas accéder à mes notes, ce qui est frustrant.\""
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "id": "18c299d1-8572-8035-8c3e-d9098b2481b2",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-80e3-90f5-d4d9592431de"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "heading_3",
    "root_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "content": "Question : Recommanderais-tu cette application à d'autres personnes ? Pourquoi ?"
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "id": "18c299d1-8572-8013-bd5c-d7c2dbd06b85",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-80e3-90f5-d4d9592431de"
    },
    "last_edited_by": {
      "object": "user",
      "id": "eb2f28a3-d6de-4085-bebf-97819e562e68"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "paragraph",
    "root_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "content": "🗣 Réponse : \"Oui, mais avec quelques réserves. Elle est très utile pour l'organisation, mais elle gagnerait à être plus intuitive et accessible aux nouveaux utilisateurs.\""
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "id": "18c299d1-8572-816f-bda0-c55d7f35d1ba",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-80e3-90f5-d4d9592431de"
    },
    "last_edited_by": {
      "object": "user",
      "id": "4f0e3042-8410-4c0a-8a91-96802a5dd855"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "heading_3",
    "root_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "content": ""
  },
  {
    "object": "block",
    "parent_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "id": "18c299d1-8572-81b6-b4fd-ecae14a99928",
    "parent": {
      "type": "page_id",
      "page_id": "18c299d1-8572-80e3-90f5-d4d9592431de"
    },
    "last_edited_by": {
      "object": "user",
      "id": "4f0e3042-8410-4c0a-8a91-96802a5dd855"
    },
    "has_children": false,
    "archived": false,
    "in_trash": false,
    "type": "heading_3",
    "root_id": "18c299d1-8572-80e3-90f5-d4d9592431de",
    "content": ""
  }
]

** Output JS Code**

// 1️⃣ Check if input exists and contains results
if (!$input || !$input.length) {
    console.log("Error: No valid input data received.");
    return [{ json: { answersPerPage: [] } }];
}

// 2️⃣ Process each page's blocks
const answersPerPage = $input.map(page => {
    // Extract all answers from "paragraph" blocks
    const answers = page.json
        .filter(block => block.type === "paragraph" && typeof block.content === "string")
        .map(block => block.content.trim());

    return {
        pageId: page.json[0]?.parent?.page_id || "Unknown Page", // Identify the page
        answers
    };
});

// 3️⃣ Debugging: Show extracted answers
console.log("Extracted Answers Per Page:", answersPerPage);

// 4️⃣ Return all answers, grouped by page
return [{ json: { answersPerPage } }];

  1. Output from the JS code
[
  {
    "answersPerPage": []
  }
]
  1. Workflow

Thanks for the help !

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Welcome to the community @Benoit_Husson !

Tip for sharing information

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

That implies to any JSON output you would like to share with us.

Make sure that you have removed any sensitive information from your workflow and include dummy or pinned data with it!


You do not need complex coding for the task at hand. You can use Summarize node (in place of Code) to concatinate all the blocks in all pages.

1 Like

Thank you @ihortom !

Damn. I haven’t seen it at all. I will try that and look how it works. Merci beaucoup!

And it works like a charm. I will have a beer in your honor tonight @ihortom.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.