{
  "name": "New companies in Estonia this week",
  "nodes": [
    {
      "parameters": {
        "content": "## New companies in Estonia this week\nEvery Monday at 08:00 (or press **Execute workflow**) this asks Ahel for the companies the Estonian business register entered in the last 7 days, newest first, and keeps them in the data table **ee_new_companies** (one row per registry code, so a re-run never duplicates).\n\nEach row is what the register says: name, registry code, date, legal form, filed activity (EMTAK), city and status.\n\n**Cost per run: $0.** `companies.register.new` is Ahel's own register data and is free.",
        "height": 300,
        "width": 520,
        "color": 4
      },
      "id": "c8a2ec80-8786-5cd2-98fa-71927d8c4852",
      "name": "Note: what it does",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -80,
        -340
      ]
    },
    {
      "parameters": {
        "content": "### What to change\n- **Country**: EE, FI, NO, LV, GB or CZ.\n- **Days back**: 7 by default.\n- **Max Results** on the Ahel node (25 here, up to 100). The register answers newest first.\n- Want only one trade? Add `query` to the arguments, e.g. words in the name.",
        "height": 300,
        "width": 420
      },
      "id": "535891d9-d4d3-515d-aed7-639bc9fe673c",
      "name": "Note: what to change",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        480,
        -340
      ]
    },
    {
      "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": "0659624b-9025-5597-a30b-589a8611bcc0",
              "name": "country",
              "value": "EE",
              "type": "string"
            },
            {
              "id": "157e812f-aef3-5990-9b15-42fd4a397c51",
              "name": "since",
              "value": "={{ $now.minus({days: 7}).toISODate() }}",
              "type": "string"
            },
            {
              "id": "67f848ee-a6af-54e7-a13b-c430a7aaaf03",
              "name": "until",
              "value": "={{ $now.toISODate() }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "a79d229a-90a5-56d4-a560-f291b46be332",
      "name": "Country and dates",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        100
      ]
    },
    {
      "parameters": {
        "resource": "action",
        "operation": "runTask",
        "task": {
          "__rl": true,
          "mode": "id",
          "value": "companies.register.new"
        },
        "argumentsMode": "json",
        "argumentsJson": "={\n  \"country\": \"{{ $json.country }}\",\n  \"since\": \"{{ $json.since }}\",\n  \"until\": \"{{ $json.until }}\"\n}",
        "options": {
          "maxResults": 25,
          "maxCostUsd": 0.01,
          "tag": "n8n-new-companies"
        }
      },
      "id": "21d10d13-a9e2-5ae1-8de4-291fe7982f07",
      "name": "Ahel: new companies",
      "type": "n8n-nodes-ahel.ahel",
      "typeVersion": 1,
      "position": [
        480,
        100
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "results",
        "options": {}
      },
      "id": "fe16d0dd-8f06-50e2-b35c-d179da56a8eb",
      "name": "One item per company",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        720,
        100
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "2316597c-bfa9-5917-8216-46566e3d9dca",
              "name": "registry_code",
              "value": "={{ $json.registry_code }}",
              "type": "string"
            },
            {
              "id": "d1496042-08e8-546c-826b-51a7b5ef3cf6",
              "name": "name",
              "value": "={{ $json.name }}",
              "type": "string"
            },
            {
              "id": "6945adc5-13b9-5f5f-beb8-2020f71ccd17",
              "name": "registered_date",
              "value": "={{ $json.registered_date }}",
              "type": "string"
            },
            {
              "id": "d14629d0-682f-5ffe-ae9b-d741964664fa",
              "name": "legal_form",
              "value": "={{ $json.legal_form_label }}",
              "type": "string"
            },
            {
              "id": "2229f21a-3745-5995-a82a-6bafe8ec850c",
              "name": "activity",
              "value": "={{ $json.activity }}",
              "type": "string"
            },
            {
              "id": "0567e6b0-c28f-5bcb-95b4-d286da6e7fdf",
              "name": "activity_code",
              "value": "={{ $json.activity_code }}",
              "type": "string"
            },
            {
              "id": "9fc8f773-c7db-5f9a-b7a4-380475736f86",
              "name": "city",
              "value": "={{ $json.city }}",
              "type": "string"
            },
            {
              "id": "b753d893-23d0-5cbc-81a9-52f821fbd394",
              "name": "status",
              "value": "={{ $json.status_label }}",
              "type": "string"
            },
            {
              "id": "d3e71b47-1efe-5619-ad32-5601aae45925",
              "name": "date_basis",
              "value": "={{ $json.date_basis }}",
              "type": "string"
            },
            {
              "id": "712a507e-7e56-5327-ba2e-1e829a0885ae",
              "name": "found_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": [
        960,
        100
      ]
    },
    {
      "parameters": {
        "resource": "row",
        "operation": "upsert",
        "dataTableId": {
          "__rl": true,
          "mode": "name",
          "value": "ee_new_companies"
        },
        "filters": {
          "conditions": [
            {
              "keyName": "registry_code",
              "condition": "eq",
              "keyValue": "={{ $json.registry_code }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "d8147400-fc4a-567c-b046-8032cccbd1b8",
      "name": "Save to ee_new_companies",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1200,
        100
      ]
    }
  ],
  "connections": {
    "Run now": {
      "main": [
        [
          {
            "node": "Country and dates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Every Monday 08:00": {
      "main": [
        [
          {
            "node": "Country and dates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Country and dates": {
      "main": [
        [
          {
            "node": "Ahel: new companies",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ahel: new companies": {
      "main": [
        [
          {
            "node": "One item per company",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "One item per company": {
      "main": [
        [
          {
            "node": "Shape the row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Shape the row": {
      "main": [
        [
          {
            "node": "Save to ee_new_companies",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
