{
  "name": "Notion task desk",
  "nodes": [
    {
      "id": "cfe9ac9b-fd88-40ce-a93d-2eef3e36b4e9",
      "name": "Read me first",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -700,
        -290
      ],
      "parameters": {
        "content": "## Notion task desk\nEach morning it reads your Notion tasks and writes one dated report of what is overdue, blocked or done.\n\n### You need\n- A Notion task database with Status, Due (date) and Owner (people) fields\n- Notion and Google Sheets logins. Gmail, only for the digest\n- A Telegram bot and your chat ID, for the failure alert\n\n### Set it up\n1. Fill **Task desk settings**: Notion data source ID, sheet ID and your 4 Notion field names.\n2. Share the database with your Notion login. Add each login where a step asks. Use the same one in every step for that app.\n3. Set your time zone in Workflow settings.\n4. Failure alert: put your chat ID in **Write the failure alert** and your bot in **Send the failure alert**. Then in Workflow settings, set Error workflow to this workflow.\n\n### Test it\n- Click Test workflow with **Run task desk now** picked.\n- The Tasks and Daily Report tabs fill in.",
        "height": 676,
        "width": 560,
        "color": 4
      }
    },
    {
      "id": "723714e5-bd70-5ad3-a27b-bab79749f374",
      "name": "Check the whole task list",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1080,
        -290
      ],
      "parameters": {
        "content": "## Check the whole task list\n\nOne full Notion read drives both outputs. This run stops if the source is incomplete, so incomplete data does not clear someone’s work.",
        "width": 1110,
        "height": 150,
        "color": 7
      }
    },
    {
      "id": "77b96684-1898-57e5-a92a-a8baa1e61ae1",
      "name": "Keep the report current",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        2240,
        -290
      ],
      "parameters": {
        "content": "## Keep the report current\n\nUpdate rows by Notion page ID. A report on the same day updates its existing dated row. Completions use the first observation after setup; reopening resets it.",
        "width": 1300,
        "height": 150,
        "color": 6
      }
    },
    {
      "id": "0796ac7c-c783-5825-b254-fe75072a74df",
      "name": "Check at 8 AM",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -60,
        -5
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "days",
              "daysInterval": 1,
              "triggerAtHour": 8,
              "triggerAtMinute": 0
            }
          ]
        }
      }
    },
    {
      "id": "29d5bb42-7579-59f1-9f7c-114caad785d6",
      "name": "Run task desk now",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -60,
        165
      ],
      "parameters": {}
    },
    {
      "id": "d74401a6-70da-5c6b-891f-29e9da00889c",
      "name": "Task desk settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        170,
        75
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "5311085d-b344-53ef-910a-6a1891a3dde7",
              "name": "Spreadsheet ID",
              "type": "string",
              "value": ""
            },
            {
              "id": "3f6ae108-f5db-579e-9acb-1faab08f6dd8",
              "name": "Notion data source ID",
              "type": "string",
              "value": ""
            },
            {
              "id": "a07623a2-c42a-5bdf-879f-0b3a77b0dd8f",
              "name": "Title property",
              "type": "string",
              "value": "Name"
            },
            {
              "id": "857167be-c090-55bb-8348-0d75019c9128",
              "name": "Status property",
              "type": "string",
              "value": "Status"
            },
            {
              "id": "af89583f-5e7f-56de-87b7-65957c8d11f4",
              "name": "Due property",
              "type": "string",
              "value": "Due"
            },
            {
              "id": "5842b656-0921-529c-9dae-746c7fea804b",
              "name": "Owner property",
              "type": "string",
              "value": "Assignee"
            },
            {
              "id": "45a81b93-57cc-5764-a8ff-c3b5eb507063",
              "name": "Done statuses",
              "type": "string",
              "value": "Done,Completed"
            },
            {
              "id": "d28190b1-776e-5122-afb4-9bc981852ef7",
              "name": "Blocked statuses",
              "type": "string",
              "value": "Blocked"
            },
            {
              "id": "56e76f52-f6a8-5379-b023-683d6714cf93",
              "name": "Digest recipient",
              "type": "string",
              "value": ""
            }
          ]
        },
        "options": {}
      },
      "executeOnce": true
    },
    {
      "id": "649224c3-925b-505a-8e58-73722edcac45",
      "name": "Check workspace settings",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        410,
        75
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const c=$input.first().json;\nfor(const field of ['Spreadsheet ID','Notion data source ID']) if(!/^[A-Za-z0-9_-]+$/.test(c[field].trim())) throw new Error('Enter '+field+' in Task desk settings.');\nfor(const field of ['Title property','Status property','Due property','Owner property','Done statuses']) if(!c[field].trim()) throw new Error('Set '+field+' in Task desk settings.');\nreturn [{json:c}];"
      }
    },
    {
      "id": "c975e871-af24-5576-8894-76f19d59ef81",
      "name": "Ensure Tasks tab",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        650,
        75
      ],
      "parameters": {
        "resource": "sheet",
        "operation": "create",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $(\"Task desk settings\").first().json[\"Spreadsheet ID\"].trim() }}"
        },
        "options": {},
        "title": "Tasks"
      },
      "alwaysOutputData": true
    },
    {
      "id": "3de92abf-f8c4-5965-be13-362cbb6fd595",
      "name": "Ensure Daily Report tab",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        890,
        75
      ],
      "parameters": {
        "resource": "sheet",
        "operation": "create",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $(\"Task desk settings\").first().json[\"Spreadsheet ID\"].trim() }}"
        },
        "options": {},
        "title": "Daily Report"
      },
      "alwaysOutputData": true
    },
    {
      "id": "277ac6c5-e735-5320-849b-02c79ebad15d",
      "name": "Read previous task rows",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1130,
        75
      ],
      "parameters": {
        "resource": "sheet",
        "operation": "read",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $(\"Task desk settings\").first().json[\"Spreadsheet ID\"].trim() }}"
        },
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Tasks"
        }
      },
      "alwaysOutputData": true
    },
    {
      "id": "bd20c377-2df3-5b76-b837-4939ed66a020",
      "name": "Read every page of Notion tasks",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1370,
        75
      ],
      "parameters": {
        "url": "={{ 'https://api.notion.com/v1/data_sources/'+$(\"Task desk settings\").first().json[\"Notion data source ID\"].trim()+'/query' }}",
        "method": "POST",
        "options": {
          "timeout": 45000,
          "pagination": {
            "pagination": {
              "paginationMode": "updateAParameterInEachRequest",
              "parameters": {
                "parameters": [
                  {
                    "type": "body",
                    "name": "start_cursor",
                    "value": "={{ $response.body?.next_cursor || undefined }}"
                  }
                ]
              },
              "paginationCompleteWhen": "other",
              "completeExpression": "={{ $response.body.has_more !== true }}",
              "limitPagesFetched": true,
              "maxRequests": 20,
              "requestInterval": 350
            }
          }
        },
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "notionApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ {page_size:100} }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Notion-Version",
              "value": "2025-09-03"
            }
          ]
        }
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "executeOnce": true
    },
    {
      "id": "d1bd3f1f-bf0a-5f89-a1b8-ec2c2137a307",
      "name": "Reconcile task states and prepare today’s report",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1610,
        75
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const c=$('Task desk settings').first().json;\nconst pages=$input.all().map(({json})=>json);\nif(!pages.length || pages.some(p=>!Array.isArray(p.results)) || pages.at(-1).has_more) throw new Error('Notion did not return the full task list within the configured page budget.');\nconst ids=new Set();\nconst old=new Map($('Read previous task rows').all().filter(i=>i.json['Notion Page ID']).map(i=>[i.json['Notion Page ID'],i.json]));\nconst statuses=key=>new Set(c[key].split(',').map(x=>x.trim().toLowerCase()).filter(Boolean));\nconst done=statuses('Done statuses'),blocked=statuses('Blocked statuses');\nconst date=$now.toISODate(),at=$now.toISO(),week=$now.startOf('day').minus({days:6}).toMillis();\nconst pending=[],overdue=[],stalled=[],completed=[],unassigned=[],rows=[];\nconst clean=v=>String(v||'').replace(/\\s+/g,' ').trim();\nfor(const p of pages.flatMap(x=>x.results)){\n  if(p.object!=='page' || p.archived || p.in_trash) continue;\n  if(!p.id||ids.has(p.id)) throw new Error('Notion returned a repeated or invalid page ID.');\n  ids.add(p.id);\n  const a=p.properties;\n  const title=a?.[c['Title property']],stage=a?.[c['Status property']],due=a?.[c['Due property']],owner=a?.[c['Owner property']];\n  if(title?.type!=='title'||!['status','select'].includes(stage?.type)||due?.type!=='date'||owner?.type!=='people') throw new Error('Check the title, status, due date and owner property mappings.');\n  const task=clean(title.title.map(t=>t.plain_text||t.text?.content).join(''))||'Untitled task';\n  const status=clean(stage[stage.type]?.name)||'Unset';\n  const dueAt=due.date?.start||'';\n  const localDate=dueAt?DateTime.fromISO(dueAt,{zone:$now.zoneName}).toISODate()||'':'';\n  const names=(owner.people||[]).map(x=>clean(x.name)||'Assigned person');\n  const label=task+' · '+(names.join(', ')||'Unassigned')+(localDate?' · '+localDate:'');\n  const was=old.get(p.id)||{};\n  const complete=done.has(status.toLowerCase());\n  const completedAt=complete?(was.State==='Completed' && was['Completed At']?was['Completed At']:at):'';\n  const state=complete?'Completed':blocked.has(status.toLowerCase())?'Blocked':'Pending';\n  if(state==='Completed'&&Date.parse(completedAt)>=week) completed.push(label);\n  if(!complete){\n    pending.push(label);\n    if(state==='Blocked') stalled.push(label);\n    if(localDate && localDate<date) overdue.push(label);\n    if(!names.length) unassigned.push(label);\n  }\n  rows.push({'Notion Page ID':p.id,Task:task,Status:status,State:state,Due:dueAt,\n    Owner:names.join(', '),'Notion URL':p.url||'','Completed At':completedAt,'Last Checked':at});\n}\nfor(const [id,r] of old) if(!ids.has(id)&&r.State!=='Removed') rows.push({'Notion Page ID':id,State:'Removed','Last Checked':at});\nconst list=(label,values)=>label+' ('+values.length+')\\n'+(values.slice(0,12).join('\\n')||'None')+(values.length>12?'\\nSee Tasks for the remaining items.':'');\nconst summary=[list('Completed in the last seven days',completed),list('Pending now',pending),\n  list('Overdue',overdue),list('Blocked',stalled),list('Unassigned',unassigned)].join('\\n\\n');\nreturn [{json:{rows,summary,report:{'Report Date':date,'Last Checked':at,Pending:pending.length,Overdue:overdue.length,\n  Blocked:stalled.length,Unassigned:unassigned.length,'Completed Last 7 Days':completed.length,Report:summary}}}];"
      }
    },
    {
      "id": "257504b2-c31a-503f-9111-5d0b88e1f798",
      "name": "Task rows to write",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1850,
        75
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "14b68804-4d97-530b-9b16-9418341b49a4",
              "leftValue": "={{ $json.rows.length > 0 }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "95660cee-aeb9-580d-a0cd-80562b5e7c24",
      "name": "Expand the task snapshot",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2090,
        0
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return $input.first().json.rows.map(json=>({json}));"
      }
    },
    {
      "id": "3dc90e45-ee2f-5b3f-ad4f-fc407c05670b",
      "name": "Upsert task rows by Notion ID",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        2330,
        0
      ],
      "parameters": {
        "resource": "sheet",
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $(\"Task desk settings\").first().json[\"Spreadsheet ID\"].trim() }}"
        },
        "options": {
          "cellFormat": "RAW",
          "handlingExtraData": "insertInNewColumn",
          "useAppend": true
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Tasks"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "matchingColumns": [
            "Notion Page ID"
          ],
          "schema": []
        }
      }
    },
    {
      "id": "83013b5a-88e7-55db-8299-14383a56ae55",
      "name": "Prepare one daily report",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2570,
        75
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return [{json:$(\"Reconcile task states and prepare today’s report\").first().json.report}];"
      },
      "executeOnce": true
    },
    {
      "id": "f847352a-331f-505e-9eb6-e792366beff3",
      "name": "Save today’s report",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        2810,
        75
      ],
      "parameters": {
        "resource": "sheet",
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $(\"Task desk settings\").first().json[\"Spreadsheet ID\"].trim() }}"
        },
        "options": {
          "cellFormat": "RAW",
          "handlingExtraData": "insertInNewColumn",
          "useAppend": true
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Daily Report"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "matchingColumns": [
            "Report Date"
          ],
          "schema": []
        }
      }
    },
    {
      "id": "e394bb7f-2f9e-5e5d-ab1d-0e07fe23774b",
      "name": "Send an owner digest",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        3050,
        75
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "db41b721-1dfb-5803-ac5e-10ca757e23c7",
              "leftValue": "={{ $(\"Task desk settings\").first().json[\"Digest recipient\"].trim().length > 0 }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "fe25c789-3888-59e6-8aa7-9f0b543aa183",
      "name": "Email overdue work and completions",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        3290,
        0
      ],
      "parameters": {
        "resource": "message",
        "operation": "send",
        "sendTo": "={{ $(\"Task desk settings\").first().json[\"Digest recipient\"] }}",
        "subject": "={{ 'Notion task desk · '+$now.toISODate() }}",
        "emailType": "text",
        "message": "={{ $(\"Reconcile task states and prepare today’s report\").first().json.summary+'\\n\\nhttps://docs.google.com/spreadsheets/d/'+encodeURIComponent($(\"Task desk settings\").first().json[\"Spreadsheet ID\"]) }}",
        "options": {
          "appendAttribution": false
        }
      }
    },
    {
      "id": "07ca68bf-9dc3-4bad-a8de-e7fc6fd4fea6",
      "name": "When this workflow fails",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        -660,
        466
      ],
      "parameters": {}
    },
    {
      "id": "4ff673c0-b88f-4ae0-af9a-24c007d3803c",
      "name": "Write the failure alert",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -440,
        466
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f1",
              "name": "telegramChatId",
              "type": "string",
              "value": "YOUR_TELEGRAM_CHAT_ID"
            },
            {
              "id": "f2",
              "name": "message",
              "type": "string",
              "value": "={{ 'A workflow stopped.\\n\\nWorkflow: ' + (($json.workflow || {}).name || 'unknown') + '\\nFailed step: ' + (($json.execution || {}).lastNodeExecuted || 'unknown') + '\\nWhy: ' + String((($json.execution || {}).error || {}).message || 'n8n did not give a reason.').slice(0, 300) + (($json.execution || {}).url ? '\\nOpen the run: ' + $json.execution.url : '') }}"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      }
    },
    {
      "id": "d85577b0-7476-4e04-bd66-dc4284715722",
      "name": "Send the failure alert",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -220,
        466
      ],
      "parameters": {
        "chatId": "={{ $json.telegramChatId }}",
        "text": "={{ $json.message }}",
        "additionalFields": {
          "appendAttribution": false
        }
      }
    }
  ],
  "connections": {
    "Check at 8 AM": {
      "main": [
        [
          {
            "node": "Task desk settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run task desk now": {
      "main": [
        [
          {
            "node": "Task desk settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Task desk settings": {
      "main": [
        [
          {
            "node": "Check workspace settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check workspace settings": {
      "main": [
        [
          {
            "node": "Ensure Tasks tab",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ensure Tasks tab": {
      "main": [
        [
          {
            "node": "Ensure Daily Report tab",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ensure Daily Report tab": {
      "main": [
        [
          {
            "node": "Read previous task rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read previous task rows": {
      "main": [
        [
          {
            "node": "Read every page of Notion tasks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read every page of Notion tasks": {
      "main": [
        [
          {
            "node": "Reconcile task states and prepare today’s report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reconcile task states and prepare today’s report": {
      "main": [
        [
          {
            "node": "Task rows to write",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Task rows to write": {
      "main": [
        [
          {
            "node": "Expand the task snapshot",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Prepare one daily report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Expand the task snapshot": {
      "main": [
        [
          {
            "node": "Upsert task rows by Notion ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upsert task rows by Notion ID": {
      "main": [
        [
          {
            "node": "Prepare one daily report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare one daily report": {
      "main": [
        [
          {
            "node": "Save today’s report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save today’s report": {
      "main": [
        [
          {
            "node": "Send an owner digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send an owner digest": {
      "main": [
        [
          {
            "node": "Email overdue work and completions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When this workflow fails": {
      "main": [
        [
          {
            "node": "Write the failure alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write the failure alert": {
      "main": [
        [
          {
            "node": "Send the failure alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "saveDataSuccessExecution": "none",
    "saveManualExecutions": false
  },
  "pinData": {}
}
