{
  "name": "Weekly tender watch: only what is new",
  "nodes": [
    {
      "parameters": {
        "content": "## Weekly tender watch: only what is new\nEvery Monday at 08:00 (or press **Execute workflow**) this asks Ahel for public tenders published in the last 14 days (EU Tenders Electronic Daily) that match your keyword in your country. **Only notices this workflow has not seen in an earlier run** go on: they are added to the data table **tender_watch**, and the last node reports how many are new. A week with nothing new reports 0.\n\n**Cost per run: $0.004**, one call to `procurement.tenders.search`, however many notices come back. No match is free.",
        "height": 340,
        "width": 600,
        "color": 4
      },
      "id": "c8a2ec80-8786-5cd2-98fa-71927d8c4852",
      "name": "Note: what it does",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -80,
        -420
      ]
    },
    {
      "parameters": {
        "content": "### What to change\n- **keyword** (English works: titles are in English) and **country** (any EU/EEA two-letter code).\n- **Max Results** on the Ahel node (25 here). The price stays one call.\n- To start over, run **Remove Duplicates** once with *Clear Deduplication History*.\n- The 14-day window overlaps on purpose: a late notice is still caught, and never counted twice.",
        "height": 340,
        "width": 460
      },
      "id": "535891d9-d4d3-515d-aed7-639bc9fe673c",
      "name": "Note: what to change",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        560,
        -420
      ]
    },
    {
      "parameters": {},
      "id": "e63a4a47-ff2a-51ef-8d70-d3ee6a6df8a7",
      "name": "Run now",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "weeksInterval": 1,
              "triggerAtDay": [
                1
              ],
              "triggerAtHour": 8
            }
          ]
        }
      },
      "id": "e54fd9a4-7b68-538f-9ff6-a2d857cedb9d",
      "name": "Every Monday 08:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        200
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "259d10bd-e363-5e07-91a0-22339ca4c108",
              "name": "country",
              "value": "EE",
              "type": "string"
            },
            {
              "id": "f68b1321-2291-5887-a967-85cb1a5dece6",
              "name": "keyword",
              "value": "software",
              "type": "string"
            },
            {
              "id": "735329c9-db90-5b79-9166-87cd05fd4791",
              "name": "published_after",
              "value": "={{ $now.minus({days: 14}).toISODate() }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "621a140e-06e2-5b16-9a4c-feea068e6755",
      "name": "Keyword and country",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        100
      ]
    },
    {
      "parameters": {
        "resource": "action",
        "operation": "runTask",
        "task": {
          "__rl": true,
          "mode": "id",
          "value": "procurement.tenders.search"
        },
        "argumentsMode": "json",
        "argumentsJson": "={\n  \"country\": \"{{ $json.country }}\",\n  \"query\": \"{{ $json.keyword }}\",\n  \"published_after\": \"{{ $json.published_after }}\"\n}",
        "options": {
          "maxResults": 25,
          "maxCostUsd": 0.01,
          "tag": "n8n-tender-watch"
        }
      },
      "id": "e1bb4f0f-4521-5f4a-99aa-928e72a25401",
      "name": "Ahel: tenders",
      "type": "n8n-nodes-ahel.ahel",
      "typeVersion": 1,
      "position": [
        480,
        100
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "results",
        "options": {}
      },
      "id": "934c75ce-edbf-5b83-a9c1-28574978d1f2",
      "name": "One item per notice",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        720,
        100
      ]
    },
    {
      "parameters": {
        "operation": "removeItemsSeenInPreviousExecutions",
        "dedupeValue": "={{ $json.notice_id }}",
        "options": {
          "historySize": 10000
        }
      },
      "id": "2211f56d-2aca-5e2b-8601-1b5cb8a0da08",
      "name": "Only notices not seen before",
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [
        960,
        100
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "e3e9ea0e-4b02-50c8-8c6f-9575e04716dc",
              "leftValue": "={{ $json.notice_id }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "d4b5d78c-45f9-5df1-a115-7391b9fc9f7c",
      "name": "Drop the empty item",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        1200,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "3e899a89-ea7c-5452-8224-d1870b8b3c4a",
              "name": "notice_id",
              "value": "={{ $json.notice_id }}",
              "type": "string"
            },
            {
              "id": "245c783a-1754-5480-ac07-b31fc59adfbd",
              "name": "title",
              "value": "={{ $json.title }}",
              "type": "string"
            },
            {
              "id": "6f2cc0d7-bf39-56e2-af3d-85b391b12636",
              "name": "buyer",
              "value": "={{ ($json.buyer_name || []).join('; ') }}",
              "type": "string"
            },
            {
              "id": "b1b3174d-6a0b-5619-a588-24af6a1717c5",
              "name": "buyer_country",
              "value": "={{ ($json.buyer_country || []).join(', ') }}",
              "type": "string"
            },
            {
              "id": "711a346c-73a3-5b19-bf8a-090239cc4494",
              "name": "published",
              "value": "={{ $json.publication_date }}",
              "type": "string"
            },
            {
              "id": "127e0a06-c8f1-51fd-a6b0-8a1f7747504f",
              "name": "deadline",
              "value": "={{ ($json.tender_deadline || [])[0] || '' }}",
              "type": "string"
            },
            {
              "id": "9324cfab-76ea-518b-9a8a-44c66bceca1f",
              "name": "value",
              "value": "={{ $json.published_total_value }}",
              "type": "number"
            },
            {
              "id": "2998c9fa-909a-5b12-a5b4-4b740cb25b23",
              "name": "cpv",
              "value": "={{ ($json.cpv || []).join(', ') }}",
              "type": "string"
            },
            {
              "id": "d60bb7be-f46e-554a-a535-44ffcd56da10",
              "name": "notice_type",
              "value": "={{ $json.notice_type }}",
              "type": "string"
            },
            {
              "id": "f816f209-045c-5be9-9274-337409646313",
              "name": "link",
              "value": "=https://ted.europa.eu/en/notice/-/detail/{{ $json.notice_id }}",
              "type": "string"
            },
            {
              "id": "87174add-1d25-5011-a353-53f752424835",
              "name": "keyword",
              "value": "={{ $('Keyword and country').first().json.keyword }}",
              "type": "string"
            },
            {
              "id": "fff78729-3b2c-5783-a715-69f0639e3d29",
              "name": "first_seen_on",
              "value": "={{ $now.toISODate() }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "53b3ebf7-2839-5b72-b32a-52bc217e1da0",
      "name": "Shape the row",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1440,
        0
      ]
    },
    {
      "parameters": {
        "resource": "row",
        "operation": "insert",
        "dataTableId": {
          "__rl": true,
          "mode": "name",
          "value": "tender_watch"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "c3221390-2ff0-55e6-98c8-de6ed525d40f",
      "name": "Add to tender_watch",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1680,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "// Everything that reached this node is new since the last run.\nconst fresh = $input.all().filter((item) => item.json.notice_id);\nreturn [{ json: {\n  checked_on: $now.toISODate(),\n  keyword: $('Keyword and country').first().json.keyword,\n  looked_at: $('One item per notice').all().length,\n  new_since_last_run: fresh.length,\n  new_notice_ids: fresh.map((item) => item.json.notice_id),\n} }];"
      },
      "id": "1bcd97c7-7fd3-5028-bbbd-9b66f55b2945",
      "name": "Report what changed",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1200,
        220
      ]
    }
  ],
  "connections": {
    "Run now": {
      "main": [
        [
          {
            "node": "Keyword and country",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Every Monday 08:00": {
      "main": [
        [
          {
            "node": "Keyword and country",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keyword and country": {
      "main": [
        [
          {
            "node": "Ahel: tenders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ahel: tenders": {
      "main": [
        [
          {
            "node": "One item per notice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "One item per notice": {
      "main": [
        [
          {
            "node": "Only notices not seen before",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Only notices not seen before": {
      "main": [
        [
          {
            "node": "Drop the empty item",
            "type": "main",
            "index": 0
          },
          {
            "node": "Report what changed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Drop the empty item": {
      "main": [
        [
          {
            "node": "Shape the row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Shape the row": {
      "main": [
        [
          {
            "node": "Add to tender_watch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
