Writing data from AI Agent node to Notion page

Hey everyone :waving_hand:

I’m trying to build a workflow where my AI Agent receives a text (like a course summary), and writes it to Notion in a structured way — with titles, bullet points, paragraphs, etc.

I don’t want to map each block manually in n8n, I want the Agent to do the formatting and just send the structured result to Notion.

:backhand_index_pointing_right: The problem is: even when I give the Agent instructions to write the right format, I get an error when trying to send the output to Notion.

I feel like I’m missing something obvious, but I can’t figure it out.


:puzzle_piece: Here’s my current n8n workflow:

{
  "nodes": [
    {
      "parameters": {
        "formTitle": "Convertir les notes de Coursera",
        "formDescription": "=Utilise ce formulaire afin de transformer les transcript de cours coursera en note afin de pouvoir les réviser.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Nom du module",
              "placeholder": "Titre module",
              "requiredField": true
            },
            {
              "fieldLabel": "Transcription",
              "fieldType": "file",
              "acceptFileTypes": ".txt",
              "requiredField": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        -100,
        0
      ],
      "id": "f177386a-57b2-46d7-8d00-3961c997a0ed",
      "name": "On form submission",
      "webhookId": "6348b7ff-2de9-46f1-9a8f-cba8a22d26de"
    },
    {
      "parameters": {
        "operation": "text",
        "binaryPropertyName": "=Transcription",
        "options": {}
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        120,
        0
      ],
      "id": "4a211079-59eb-43b4-b386-8ea75c0e6c82",
      "name": "Extract from File",
      "alwaysOutputData": false
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $('Extract from File').item.json.data }}",
        "options": {
          "systemMessage": "=### 🎯 Objectif : Résumer un transcript et ajouter le contenu structuré dans une page Notion\n\nTu reçois un transcript de cours.\n\n1. Tu dois produire un résumé **structuré** (titres, sections, bullet points).\n2. Tu vas l'ajouter à une page Notion **via l'outil appelé `append_notion_blocks`**.\n3. Tu dois découper ton contenu en plusieurs blocs Notion, en utilisant les formats suivants :\n\n- `heading_1`: pour le titre du résumé\n- `heading_2`: pour les sections\n- `bulleted_list_item`: pour les idées principales\n- `paragraph`: pour des explications\n\n4. Tu n’as pas à envoyer tout le contenu en une fois : tu peux appeler plusieurs fois l’outil `append_notion_blocks` avec une liste de blocs à chaque fois (2000 caractères max).\n\n---\n\n### ✅ Exemple de format de bloc à utiliser :\n\n```json\n{\n  \"type\": \"heading_2\",\n  \"heading_2\": {\n    \"rich_text\": [\n      { \"type\": \"text\", \"text\": { \"content\": \"Les fondamentaux de la vente\" } }\n    ]\n  }\n}\n"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        960,
        0
      ],
      "id": "49e24e0d-73c7-4700-9d04-18a89aebd2c4",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4.1",
          "mode": "list",
          "cachedResultName": "gpt-4.1"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        880,
        200
      ],
      "id": "f01bd74a-47ae-468e-a0eb-509c1d32ea13",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "nEUxMYfTBw9JTeMf",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "chatgpt-4o-latest",
          "mode": "list",
          "cachedResultName": "CHATGPT-4O-LATEST"
        },
        "messages": {
          "values": [
            {
              "content": "=Lie le texte et extrait le titre dans la même langue du texte : \n\n {{ $json.data }}"
            },
            {
              "content": "Tu dois créer un titre à partir d'un texte, tu ne propose jamais plusieurs titre, rien de superflu juste la réponse .\n\nLe titre doit être dans la même langue du texte",
              "role": "system"
            }
          ]
        },
        "jsonOutput": true,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        340,
        0
      ],
      "id": "1d9baa35-acb5-4ade-889d-7086b8b904aa",
      "name": "Message a model",
      "credentials": {
        "openAiApi": {
          "id": "nEUxMYfTBw9JTeMf",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "pageId": {
          "__rl": true,
          "value": "https://www.notion.so/Formation-la-vente-HubSpot-223902c2362080149b2ae62a0d17e378",
          "mode": "url"
        },
        "title": "={{ $json.message.content.titre }}",
        "options": {}
      },
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        700,
        0
      ],
      "id": "0ba49565-33ef-4a47-9499-f24953001e89",
      "name": "Create a page",
      "credentials": {
        "notionApi": {
          "id": "4Y12d0A1j4d7mzEd",
          "name": "Notion account"
        }
      }
    },
    {
      "parameters": {
        "resource": "block",
        "blockId": {
          "__rl": true,
          "value": "={{ $json.id }}",
          "mode": "id"
        },
        "blockUi": {
          "blockValues": [
            {
              "richText": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('blockValues0_Rich_Text', ``, 'boolean') }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.notionTool",
      "typeVersion": 2.2,
      "position": [
        1120,
        300
      ],
      "id": "eadfbb9c-22c3-4067-91c3-9d4bd1a0b489",
      "name": "Append notion blocks",
      "credentials": {
        "notionApi": {
          "id": "4Y12d0A1j4d7mzEd",
          "name": "Notion account"
        }
      }
    }
  ],
  "connections": {
    "On form submission": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Message a model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Message a model": {
      "main": [
        [
          {
            "node": "Create a page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create a page": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append notion blocks": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "1148135d8af09935f1fbc9043e7cde1c4aacf716a7ce6f442c7af6891f4db26e"
  }
}```

---

### ❌ Here’s the error I get:

![Capture d’écran 2025-07-01 à 20.37.45|690x431](upload://1pNOCg2D23ZlNrZFSRwrYV8Ja6H.png)

The Notion node expects a block ID to append children to, not a page ID. If you pass the page’s ID, it may work once or randomly, but then it errors out because that’s not a valid block reference

You have to pass a valid Notion block ID, not the page URL/id, and append blocks in a loop, mapping AI-generated arrays to individual append calls.
Once that’s in place, the AI agent’s structured output will flow into Notion.

1 Like