{
  "name": "WooCommerce order desk",
  "nodes": [
    {
      "id": "24444c2b-2b9d-42ab-9e42-7099f8f18c9b",
      "name": "Read me first",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -725,
        -340
      ],
      "parameters": {
        "content": "## WooCommerce order desk\nEach morning it updates an order sheet from WooCommerce and lists payments, late orders and refunds to check, each with a Notion page.\n\n### You need\n- A read-only WooCommerce key\n- A Notion database for follow-ups\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 **Woo desk settings**: store address (https), sheet ID, Notion data source ID and title field.\n2. 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 **Review orders now** picked.\n- The Woo Orders tab fills in. Orders to check get a Notion page.",
        "height": 728,
        "width": 560,
        "color": 4
      }
    },
    {
      "id": "2fb4da93-6d9e-5a7e-bdc9-bfd8c75d3c45",
      "name": "Refresh the store ledger",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1300,
        -340
      ],
      "parameters": {
        "content": "## Refresh the store ledger\n\nRead recently changed orders and recheck earlier rows still open. Record payment and order status, known refunds and the next action. The first run imports the chosen lookback.",
        "width": 1650,
        "height": 145,
        "color": 7
      }
    },
    {
      "id": "f3ed83e8-bd98-5ddc-b779-e92fed1f230b",
      "name": "Close the loop in Notion",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        3050,
        -340
      ],
      "parameters": {
        "content": "## Close the loop in Notion\n\nKeep one follow-up page per order. A cleared issue updates its existing page. Enter Yes under Reviewed to clear an unchanged issue; a new status or refund reopens it. Refund decisions stay in WooCommerce.",
        "width": 2220,
        "height": 150,
        "color": 6
      }
    },
    {
      "id": "e7fbbce5-319f-5e27-a011-dd6883ffabde",
      "name": "Woo desk settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        150,
        45
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "ec60e626-a693-591e-972f-db86fad1f891",
              "name": "Store URL",
              "type": "string",
              "value": ""
            },
            {
              "id": "f3041f31-1dc6-5d3d-b3d3-23d73a7dd594",
              "name": "Spreadsheet ID",
              "type": "string",
              "value": ""
            },
            {
              "id": "1aa7dcd7-ea68-5560-9877-32cccc9876e5",
              "name": "Notion data source ID",
              "type": "string",
              "value": ""
            },
            {
              "id": "759f4493-69e5-5a6b-a888-6da2c5b2d8dc",
              "name": "Notion title property",
              "type": "string",
              "value": "Name"
            },
            {
              "id": "4ebb1270-adfa-5025-9c5e-353cd3b5b66e",
              "name": "Lookback days",
              "type": "number",
              "value": 7
            },
            {
              "id": "4099b796-a20f-58ac-9358-61ce56ff00f1",
              "name": "Review processing after days",
              "type": "number",
              "value": 2
            },
            {
              "id": "c949634f-4f70-533e-93a6-93a653038f0a",
              "name": "Digest recipient",
              "type": "string",
              "value": ""
            }
          ]
        },
        "options": {}
      },
      "executeOnce": true
    },
    {
      "id": "f7a32efb-2b1b-51c8-b606-9b2e904d83a9",
      "name": "Review orders every morning",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -85,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "days",
              "daysInterval": 1,
              "triggerAtHour": 8,
              "triggerAtMinute": 0
            }
          ]
        }
      }
    },
    {
      "id": "419bb107-4a77-5e11-970b-dea2c0fe6861",
      "name": "Review orders now",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -85,
        170
      ],
      "parameters": {}
    },
    {
      "id": "74928b5b-8af0-594f-9798-694b0d2810a8",
      "name": "Validate the Woo desk settings",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        390,
        45
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const c=$input.first().json;\nconst url=c['Store URL'].trim().replace(/\\/+$/,'');\nif(!/^https:\\/\\/[a-z0-9.-]+(?:\\/[a-z0-9._-]+)*$/i.test(url)) throw new Error('Set the HTTPS WooCommerce store URL.');\nfor(const k of ['Spreadsheet ID','Notion data source ID']) if(!/^[A-Za-z0-9_-]+$/.test(c[k].trim())) throw new Error('Set '+k+' in Woo desk settings.');\nif(!c['Notion title property'].trim()) throw new Error('Set the Notion title property.');\nif(!Number.isInteger(c['Lookback days'])||c['Lookback days']<1||c['Lookback days']>31||\n !Number.isInteger(c['Review processing after days'])||c['Review processing after days']<1) throw new Error('Use positive whole numbers for lookback and processing review days.');\nreturn [{json:{...c,root:url,ordersUrl:url+'/wp-json/wc/v3/orders',\n  since:$now.toUTC().minus({days:c['Lookback days']}).toISO({suppressMilliseconds:true}),checked:$now.toISO()}}];"
      }
    },
    {
      "id": "54cd622d-f37b-591f-a436-da194781d4b8",
      "name": "Ensure Woo Orders tab",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        620,
        45
      ],
      "parameters": {
        "resource": "sheet",
        "operation": "create",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $(\"Woo desk settings\").first().json[\"Spreadsheet ID\"].trim() }}"
        },
        "options": {},
        "title": "Woo Orders"
      },
      "alwaysOutputData": true
    },
    {
      "id": "685307b8-c317-58eb-a4de-5ca0ef5d26d3",
      "name": "Read the saved order ledger",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        850,
        45
      ],
      "parameters": {
        "resource": "sheet",
        "operation": "read",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $(\"Woo desk settings\").first().json[\"Spreadsheet ID\"].trim() }}"
        },
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Woo Orders"
        }
      },
      "alwaysOutputData": true
    },
    {
      "id": "0451b2fc-7adf-539f-9041-06c38e72fc79",
      "name": "Read recently updated Woo orders",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1080,
        45
      ],
      "parameters": {
        "url": "={{ $(\"Validate the Woo desk settings\").first().json[\"ordersUrl\"] }}",
        "method": "GET",
        "options": {
          "timeout": 45000,
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": false
            }
          },
          "pagination": {
            "pagination": {
              "paginationMode": "updateAParameterInEachRequest",
              "parameters": {
                "parameters": [
                  {
                    "type": "qs",
                    "name": "page",
                    "value": "={{ $pageCount+1 }}"
                  }
                ]
              },
              "paginationCompleteWhen": "other",
              "completeExpression": "={{ $pageCount >= Number($response.headers['x-wp-totalpages'] || $response.headers['X-WP-TotalPages'] || ($response.body.length < 50 ? $pageCount : 20)) }}",
              "limitPagesFetched": true,
              "maxRequests": 20,
              "requestInterval": 400
            }
          }
        },
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "wooCommerceApi",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "modified_after",
              "value": "={{ $(\"Validate the Woo desk settings\").first().json[\"since\"] }}"
            },
            {
              "name": "dates_are_gmt",
              "value": "true"
            },
            {
              "name": "per_page",
              "value": "50"
            },
            {
              "name": "page",
              "value": "1"
            },
            {
              "name": "orderby",
              "value": "modified"
            },
            {
              "name": "order",
              "value": "asc"
            },
            {
              "name": "_fields",
              "value": "id,number,status,currency,total,date_created_gmt,date_modified_gmt,refunds"
            }
          ]
        }
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "executeOnce": true
    },
    {
      "id": "d4a20f0b-5e48-5f00-804c-be49e1ba9fd0",
      "name": "Find older orders that still matter",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1310,
        45
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const pages=$input.all().map(({json})=>json);\nif(!pages.length||pages.some(p=>!Array.isArray(p.body))) throw new Error('WooCommerce order list did not return a usable batch.');\nconst last=pages.at(-1), expected=Number(last.headers?.['x-wp-totalpages']||last.headers?.['X-WP-TotalPages']||0);\nif(expected>pages.length || (!expected&&last.body.length>=50)) throw new Error('WooCommerce pages are incomplete. Reduce the lookback or check pagination headers.');\nconst recent=new Set(pages.flatMap(p=>p.body.map(o=>String(o.id))));\nconst known=new Map($('Read the saved order ledger').all().filter(({json:r})=>r['Woo Order ID']).map(({json:r})=>[String(r['Woo Order ID']),r]));\nconst pending=[...known.entries()].filter(([id,r])=>/^\\d+$/.test(id)&&!recent.has(id)&&\n  (r['Check Again']==='Yes'||(r['Notion Target Key']&&r['Notion Synced Key']!==r['Notion Target Key'])))\n .sort((a,b)=>String(a[1]['Last Checked']||'').localeCompare(String(b[1]['Last Checked']||'')));\nconst ids=pending.slice(0,60).map(([id])=>({json:{id,queued:Math.max(0,pending.length-60)}}));\nreturn ids.length?ids:[{json:{empty:true,queued:0}}];"
      }
    },
    {
      "id": "1a611110-c060-5976-a89f-d9d0438ff462",
      "name": "Older orders to recheck",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1540,
        45
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "c58ca5ca-fc9f-5661-8cfa-9ea6836eef86",
              "leftValue": "={{ !$json.empty }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "3d403f60-f41d-59b7-a108-636c6f1438f7",
      "name": "Recheck an earlier Woo order",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1770,
        -20
      ],
      "parameters": {
        "url": "={{ $(\"Validate the Woo desk settings\").first().json[\"ordersUrl\"]+'/'+encodeURIComponent($json.id) }}",
        "method": "GET",
        "options": {
          "timeout": 45000,
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true
            }
          },
          "batching": {
            "batch": {
              "batchSize": 5,
              "batchInterval": 750
            }
          }
        },
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "wooCommerceApi",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "_fields",
              "value": "id,number,status,currency,total,date_created_gmt,date_modified_gmt,refunds"
            }
          ]
        }
      }
    },
    {
      "id": "b8d4f0cc-05f7-5020-8e87-a5aac5984689",
      "name": "Classify what the owner needs to see",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2000,
        45
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const c=$('Validate the Woo desk settings').first().json;\nconst old=new Map($('Read the saved order ledger').all().filter(({json:r})=>r['Woo Order ID']).map(({json:r})=>[String(r['Woo Order ID']),r]));\nconst recent=$('Read recently updated Woo orders').all().flatMap(({json})=>json.body);\nconst responses=$('Recheck an earlier Woo order').isExecuted?$('Recheck an earlier Woo order').all().map(({json})=>json):[];\nif(responses.some(x=>[401,403].includes(x.statusCode))) throw new Error('WooCommerce denied access. The ledger was left as it was.');\nconst missing=responses.filter(x=>x.statusCode>=400||!x.body?.id).length;\nconst incoming=[...recent,...responses.filter(x=>x.statusCode>=200&&x.statusCode<300&&x.body?.id).map(x=>x.body)];\nconst orders=new Map();for(const o of incoming) if(/^\\d+$/.test(String(o.id||''))) orders.set(String(o.id),o);\nconst cutoff=Date.parse(c.checked)-c['Review processing after days']*86400000;\nconst rows=[], changes=[], actionList=[];\nlet newOrders=0;\nfor(const [id,o] of orders){\n  const w=old.get(id)||{};\n  if(!w['Woo Order ID'])newOrders++;\n  const status=String(o.status||'unknown');\n  const refunds=Array.isArray(o.refunds)?o.refunds:[];\n  const refundIds=refunds.map(x=>String(x.id)).sort();\n  const created=Date.parse(String(o.date_created_gmt||'').replace(/Z?$/,'Z'));\n  const reasons=[];\n  if(status==='failed') reasons.push('Payment failed');\n  if(status==='on-hold') reasons.push('Order on hold');\n  if(status==='processing'&&created<cutoff) reasons.push('Still processing beyond review window');\n  if(status==='refunded'||refundIds.length) reasons.push('Review recorded refund activity');\n  const key=reasons.length?[status,...refundIds,...reasons].join('|'):'';\n  const reviewed=key&&w['Exception Key']===key&&/^yes$/i.test(String(w.Reviewed||'').trim());\n  const needs=Boolean(key)&&!reviewed;\n  const notionState=needs?'Open':key?'Reviewed':'Cleared';\n  const syncedKey=notionState+'|'+key;\n  const marker='[Woo '+id+']';\n  const row={'Woo Order ID':id,Order:String(o.number||id),Status:status,'Created (UTC)':o.date_created_gmt||'',\n   'Updated (UTC)':o.date_modified_gmt||'',Total:o.total||'',Currency:o.currency||'','Refund Count':refundIds.length,\n   'Exception Key':key,Action:needs?reasons.join(' · '):'',Reviewed:reviewed?'Yes':'','Check Again':\n   ['pending','processing','on-hold','failed','unknown'].includes(status)||needs?'Yes':'No',\n   'Last Checked':c.checked,'Notion Page ID':w['Notion Page ID']||'','Notion URL':w['Notion URL']||'',\n   'Notion Target Key':(needs||w['Notion Page ID'])?syncedKey:'','Notion Synced Key':w['Notion Synced Key']||''};\n  rows.push(row);\n  if(needs) actionList.push('#'+row.Order+': '+row.Action);\n  if((needs||row['Notion Page ID'])&&row['Notion Synced Key']!==syncedKey){\n    const title=marker+' '+notionState+' · #'+row.Order+(needs?' · '+row.Action:'');\n    changes.push({id,marker,title:title.slice(0,180),syncedKey,storedId:row['Notion Page ID'],storedUrl:row['Notion URL']});\n  }\n}\nconst queued=$('Find older orders that still matter').first().json.queued||0;\nconst body=[newOrders+' new to the ledger · '+rows.length+' checked · '+actionList.length+' need review',...actionList.slice(0,20),\n  actionList.length>20?'See Woo Orders for the remaining items.':'',\n  missing?missing+' older orders were unavailable; their rows were kept.':'',queued?queued+' older open orders are queued for subsequent runs.':'',\n  'https://docs.google.com/spreadsheets/d/'+encodeURIComponent(c['Spreadsheet ID'])].filter(Boolean).join('\\n');\nreturn [{json:{rows,changes,body}}];"
      },
      "executeOnce": true
    },
    {
      "id": "8b0a959a-97c8-5826-9cd8-dd1a0be3ae7b",
      "name": "Any order snapshots",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        2230,
        45
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "66b43233-1136-5e4e-892f-3556852b1d49",
              "leftValue": "={{ $json.rows.length > 0 }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "4f76be98-ac14-5fbb-b5a4-d6ff3db98676",
      "name": "Expand the Woo ledger rows",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2460,
        -20
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return $input.first().json.rows.map(json=>({json}));"
      }
    },
    {
      "id": "4c931a47-2e99-5371-bd3f-fc07c94b681e",
      "name": "Upsert Woo order IDs",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        2690,
        -20
      ],
      "parameters": {
        "resource": "sheet",
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $(\"Woo desk settings\").first().json[\"Spreadsheet ID\"].trim() }}"
        },
        "options": {
          "cellFormat": "RAW",
          "handlingExtraData": "insertInNewColumn",
          "useAppend": true
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Woo Orders"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "matchingColumns": [
            "Woo Order ID"
          ],
          "schema": []
        }
      }
    },
    {
      "id": "f83a412c-24e0-5b5b-8c56-381ebb6c4bdb",
      "name": "Notion follow-ups to sync",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        2920,
        45
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "50dd72ef-4c33-56dd-bfe8-2ef9e9192a9f",
              "leftValue": "={{ $(\"Classify what the owner needs to see\").first().json.changes.length > 0 }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "executeOnce": true
    },
    {
      "id": "1035fb6f-700a-5314-a033-e1fd141e39d5",
      "name": "Expand each Notion follow-up",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        3150,
        -20
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return $(\"Classify what the owner needs to see\").first().json.changes.map(json=>({json}));"
      }
    },
    {
      "id": "3b821de8-8f73-5926-95ec-62d2aa21f6bb",
      "name": "Find the Notion page by order marker",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        3380,
        -20
      ],
      "parameters": {
        "url": "={{ 'https://api.notion.com/v1/data_sources/'+$(\"Woo desk settings\").first().json[\"Notion data source ID\"].trim()+'/query' }}",
        "method": "POST",
        "options": {
          "timeout": 45000
        },
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "notionApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ {page_size:2,filter:{property:$(\"Woo desk settings\").first().json[\"Notion title property\"],title:{starts_with:$json.marker}}} }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Notion-Version",
              "value": "2025-09-03"
            }
          ]
        }
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000
    },
    {
      "id": "33b1e65d-30b2-5673-80a0-9757ad5b6fa1",
      "name": "Prepare a Notion create or update",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        3610,
        -20
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const c=$('Woo desk settings').first().json;\nreturn $input.all().map(({json:q},index)=>{\n const w=$('Expand each Notion follow-up').itemMatching(index).json;\n if(!Array.isArray(q.results)||q.results.length>1||q.has_more) throw new Error('Resolve duplicate Notion pages for '+w.marker);\n const p=q.results[0];\n const id=p?.id||w.storedId;\n const properties={[c['Notion title property']]:{title:[{text:{content:w.title}}]}};\n const body=id?{properties}:{parent:{type:'data_source_id',data_source_id:c['Notion data source ID'].trim()},properties};\n return {json:{...w,method:id?'PATCH':'POST',url:'https://api.notion.com/v1/pages'+(id?'/'+encodeURIComponent(id):''),body},pairedItem:index};\n});"
      }
    },
    {
      "id": "81142b1d-58b2-5985-b493-bba446bce6f7",
      "name": "Sync the order follow-up in Notion",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        3840,
        -20
      ],
      "parameters": {
        "url": "={{ $json.url }}",
        "method": "={{ $json.method }}",
        "options": {
          "timeout": 45000
        },
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "notionApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json.body }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Notion-Version",
              "value": "2025-09-03"
            }
          ]
        }
      }
    },
    {
      "id": "4411993b-ddf9-53ab-9afd-cf16ffa48416",
      "name": "Record the Notion page and review state",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        4070,
        -20
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return $input.all().map(({json:p},index)=>{\n const w=$('Prepare a Notion create or update').itemMatching(index).json;\n if(!p.id||!p.url) throw new Error('Notion did not confirm '+w.marker);\n return {json:{'Woo Order ID':w.id,'Notion Page ID':p.id,'Notion URL':p.url,'Notion Synced Key':w.syncedKey},pairedItem:index};\n});"
      }
    },
    {
      "id": "a3f61df5-03ff-53cc-95e3-4d8b1523de3e",
      "name": "Save Notion links back to the ledger",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        4300,
        -20
      ],
      "parameters": {
        "resource": "sheet",
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $(\"Woo desk settings\").first().json[\"Spreadsheet ID\"].trim() }}"
        },
        "options": {
          "cellFormat": "RAW",
          "handlingExtraData": "insertInNewColumn",
          "useAppend": true
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Woo Orders"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "matchingColumns": [
            "Woo Order ID"
          ],
          "schema": []
        }
      }
    },
    {
      "id": "f9f814e9-2940-5973-accd-f1feb74117dd",
      "name": "Send the Woo digest",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        4530,
        45
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "49ec3c54-c3a3-57c4-afc5-a5fc853569bb",
              "leftValue": "={{ $(\"Woo desk settings\").first().json[\"Digest recipient\"].trim().length > 0 }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "executeOnce": true
    },
    {
      "id": "9f58a04f-79bf-5a90-a60a-26ccc8b77495",
      "name": "Email today’s order review",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        4760,
        0
      ],
      "parameters": {
        "resource": "message",
        "operation": "send",
        "sendTo": "={{ $(\"Woo desk settings\").first().json[\"Digest recipient\"] }}",
        "subject": "={{ 'WooCommerce order desk · '+$now.toISODate() }}",
        "emailType": "text",
        "message": "={{ $(\"Classify what the owner needs to see\").first().json.body }}",
        "options": {
          "appendAttribution": false
        }
      }
    },
    {
      "id": "f6f429f4-7b7b-428b-91b3-2294338ea102",
      "name": "When this workflow fails",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        -685,
        468
      ],
      "parameters": {}
    },
    {
      "id": "216e2bb1-ecc5-43db-ac51-79ed98fb9105",
      "name": "Write the failure alert",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -465,
        468
      ],
      "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": "7d81f8f4-1dd4-4c0a-9d07-6cdfdaf49961",
      "name": "Send the failure alert",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -245,
        468
      ],
      "parameters": {
        "chatId": "={{ $json.telegramChatId }}",
        "text": "={{ $json.message }}",
        "additionalFields": {
          "appendAttribution": false
        }
      }
    }
  ],
  "connections": {
    "Review orders every morning": {
      "main": [
        [
          {
            "node": "Woo desk settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Review orders now": {
      "main": [
        [
          {
            "node": "Woo desk settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Woo desk settings": {
      "main": [
        [
          {
            "node": "Validate the Woo desk settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate the Woo desk settings": {
      "main": [
        [
          {
            "node": "Ensure Woo Orders tab",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ensure Woo Orders tab": {
      "main": [
        [
          {
            "node": "Read the saved order ledger",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read the saved order ledger": {
      "main": [
        [
          {
            "node": "Read recently updated Woo orders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read recently updated Woo orders": {
      "main": [
        [
          {
            "node": "Find older orders that still matter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find older orders that still matter": {
      "main": [
        [
          {
            "node": "Older orders to recheck",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Older orders to recheck": {
      "main": [
        [
          {
            "node": "Recheck an earlier Woo order",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Classify what the owner needs to see",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Recheck an earlier Woo order": {
      "main": [
        [
          {
            "node": "Classify what the owner needs to see",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Classify what the owner needs to see": {
      "main": [
        [
          {
            "node": "Any order snapshots",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Any order snapshots": {
      "main": [
        [
          {
            "node": "Expand the Woo ledger rows",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Notion follow-ups to sync",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Expand the Woo ledger rows": {
      "main": [
        [
          {
            "node": "Upsert Woo order IDs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upsert Woo order IDs": {
      "main": [
        [
          {
            "node": "Notion follow-ups to sync",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notion follow-ups to sync": {
      "main": [
        [
          {
            "node": "Expand each Notion follow-up",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send the Woo digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Expand each Notion follow-up": {
      "main": [
        [
          {
            "node": "Find the Notion page by order marker",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find the Notion page by order marker": {
      "main": [
        [
          {
            "node": "Prepare a Notion create or update",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare a Notion create or update": {
      "main": [
        [
          {
            "node": "Sync the order follow-up in Notion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sync the order follow-up in Notion": {
      "main": [
        [
          {
            "node": "Record the Notion page and review state",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Record the Notion page and review state": {
      "main": [
        [
          {
            "node": "Save Notion links back to the ledger",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Notion links back to the ledger": {
      "main": [
        [
          {
            "node": "Send the Woo digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send the Woo digest": {
      "main": [
        [
          {
            "node": "Email today’s order review",
            "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": {}
}
