{
  "id": "htr3e25edc48af6c",
  "name": "HowToRomania · Court case monitor for a CUI watchlist (Sheets + Slack)",
  "nodes": [
    {
      "parameters": {
        "content": "# Court case monitor for a list of CUIs\nOnce a day, reads a watchlist from Google Sheets, calls `GET /v1/company/{cui}/court-cases` (15 credits per company) and posts to Slack when the number of cases, active cases or insolvency cases changes. The new counts are written back to the sheet.\n\n## Setup\n1. Credentials → New → **Header Auth**: Name `x-api-key`, Value = your HowToRomania key (free key with 100 credits: https://api.howtoromania.io/docs#quickstart).\n2. Select that credential in every *HowToRomania* HTTP node.\n3. Sheet tab `Watchlist`, columns: `cui`, `company`, `total_cases`, `active_cases`, `insolvency_cases`, `checked_at`, `check_status`.\n4. Set the Slack channel.\n\nCost: 15 credits × companies × runs. 20 companies daily ≈ 9,000 credits/month. Court data is cached up to 24 h, so more than one run per day adds cost without new data. Natural persons are masked.",
        "height": 460,
        "width": 520
      },
      "id": "3dbcae79-aab2-5d0d-aef3-c1bb5d1f7cc3",
      "name": "About",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -460,
        -160
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 8
            }
          ]
        }
      },
      "id": "54e10816-a5b8-5971-b1fb-3357cb1f01e1",
      "name": "Daily 08:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        100,
        100
      ]
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "REPLACE_WITH_YOUR_SPREADSHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Watchlist"
        },
        "options": {}
      },
      "id": "e19f5506-0a68-5538-b986-3dd4665ddb6a",
      "name": "Read watchlist",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        320,
        100
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "REPLACE_WITH_YOUR_CREDENTIAL",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "29b35a37-6426-5154-81e6-26a332152aa8",
              "leftValue": "={{ String($json.cui ?? '').trim() }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "863fbd07-8491-56a3-87c7-1c4460817b55",
      "name": "Has CUI",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        540,
        100
      ]
    },
    {
      "parameters": {
        "url": "=https://api.howtoromania.io/v1/company/{{ encodeURIComponent(String($json.cui).trim()) }}/court-cases",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true
            }
          }
        },
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "since",
              "value": "={{ $now.minus({ years: 3 }).toFormat('yyyy-MM-dd') }}"
            },
            {
              "name": "limit",
              "value": "20"
            }
          ]
        }
      },
      "id": "a74632fc-0b50-555d-8a87-0731fb80741c",
      "name": "HowToRomania: court cases",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        760,
        100
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "REPLACE_WITH_YOUR_CREDENTIAL",
          "name": "HowToRomania API key"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Compare today's court-case summary with the values stored in the sheet.\nreturn $input.all().map((item, i) => {\n  const row = $('Has CUI').all()[i].json;\n  const r = item.json; const d = r.body && r.body.data;\n  if (r.statusCode !== 200 || !d) return { json: { row_number: row.row_number, cui: row.cui, check_status: `error ${r.statusCode}`, changed: false } };\n  const s = d.summary;\n  const prevActive = Number(row.active_cases || 0), prevIns = Number(row.insolvency_cases || 0), prevTotal = Number(row.total_cases || 0);\n  const first = row.total_cases === '' || row.total_cases === undefined;\n  const newest = (d.cases || []).slice(0, 3).map(c => `${c.number} · ${c.court} · ${c.category} · ${c.companyRole}${c.insolvency ? ' · INSOLVENCY' : ''}`);\n  return { json: {\n    row_number: row.row_number, cui: row.cui, company: d.companyName,\n    total_cases: s.total, active_cases: s.active, insolvency_cases: s.insolvency,\n    checked_at: new Date().toISOString(), check_status: 'ok',\n    changed: !first && (s.total !== prevTotal || s.active !== prevActive || s.insolvency !== prevIns),\n    new_insolvency: !first && s.insolvency > prevIns,\n    delta: `total ${prevTotal}→${s.total}, active ${prevActive}→${s.active}, insolvency ${prevIns}→${s.insolvency}`,\n    newest: newest.join('\\n'),\n  } };\n});"
      },
      "id": "d8c69c21-b2d4-5e53-ad99-6b6e148ed114",
      "name": "Compare with sheet",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        980,
        100
      ]
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "REPLACE_WITH_YOUR_SPREADSHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Watchlist"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "row_number": "={{ $json.row_number }}",
            "company": "={{ $json.company }}",
            "total_cases": "={{ $json.total_cases }}",
            "active_cases": "={{ $json.active_cases }}",
            "insolvency_cases": "={{ $json.insolvency_cases }}",
            "checked_at": "={{ $json.checked_at }}",
            "check_status": "={{ $json.check_status }}"
          },
          "matchingColumns": [
            "row_number"
          ],
          "schema": []
        },
        "options": {}
      },
      "id": "df65d237-2ff7-5902-b3e9-9b012c2d1885",
      "name": "Save counts",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1200,
        0
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "REPLACE_WITH_YOUR_CREDENTIAL",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "1ebbd413-1030-547b-a30b-37b307d72f24",
              "leftValue": "={{ $json.changed }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "1cdf2a3f-c3be-589e-a381-2cfb6a11188f",
      "name": "Changed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1200,
        200
      ]
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "name",
          "value": "#supplier-alerts"
        },
        "text": "={{ $json.new_insolvency ? ':rotating_light: New insolvency case' : ':scales: Court cases changed' }} for {{ $json.company }} (CUI {{ $json.cui }})\n{{ $json.delta }}\nNewest:\n{{ $json.newest }}",
        "otherOptions": {}
      },
      "id": "826b6fd8-eeb9-5853-acab-db5e6ea06f5e",
      "name": "Alert in Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        1420,
        180
      ],
      "credentials": {
        "slackApi": {
          "id": "REPLACE_WITH_YOUR_CREDENTIAL",
          "name": "Slack account"
        }
      }
    }
  ],
  "connections": {
    "Daily 08:00": {
      "main": [
        [
          {
            "node": "Read watchlist",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read watchlist": {
      "main": [
        [
          {
            "node": "Has CUI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has CUI": {
      "main": [
        [
          {
            "node": "HowToRomania: court cases",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HowToRomania: court cases": {
      "main": [
        [
          {
            "node": "Compare with sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compare with sheet": {
      "main": [
        [
          {
            "node": "Save counts",
            "type": "main",
            "index": 0
          },
          {
            "node": "Changed?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Changed?": {
      "main": [
        [
          {
            "node": "Alert in Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}