{
  "id": "htr54f4e9edbcf75",
  "name": "HowToRomania · Enrich a CRM lead by CUI (webhook)",
  "nodes": [
    {
      "parameters": {
        "content": "# Enrich a CRM lead with Romanian company data\nPOST `{\"cui\":\"RO12345678\",\"leadId\":\"...\"}` to this webhook (from HubSpot, Pipedrive, a form, or another workflow). It calls `GET /v1/company/{cui}` (1 credit) and returns name, VAT and e-Factura status, active status, CAEN code and fiscal address as JSON. Connect the output to your CRM node to update the lead.\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. Activate the workflow and use the production webhook URL.\n\nIf `cui` is missing or empty, the workflow answers HTTP 400 `{\"error\":\"missing_cui\"}` without calling the API (no credit used). Answers are cached up to 6 h. Invalid CUIs and not-found are not billed.",
        "height": 420,
        "width": 520
      },
      "id": "a118e158-fbae-5e41-9367-c5f64ab0f985",
      "name": "About",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -460,
        -160
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "howtoromania-enrich-lead",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "8909e908-a3a8-5c66-a9e5-bb51fe7d087d",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        100,
        100
      ],
      "webhookId": "7a3f1022-925e-586b-b61d-00304ff0052e"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "1ebbd413-1030-547b-a30b-37b307d72f24",
              "leftValue": "={{ String($json.body?.cui ?? '').trim() }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "8a68f404-6fed-5391-a073-68255fcea6ce",
      "name": "Has CUI?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        320,
        100
      ]
    },
    {
      "parameters": {
        "url": "=https://api.howtoromania.io/v1/company/{{ encodeURIComponent(String($json.body.cui ?? '').trim()) }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true
            }
          }
        }
      },
      "id": "ac13f9ab-4822-5a2a-b78b-4773039b48f2",
      "name": "HowToRomania: company lookup",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        540,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "REPLACE_WITH_YOUR_CREDENTIAL",
          "name": "HowToRomania API key"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Build a compact, CRM-friendly record. Errors (400/404) are not billed.\nconst r = $input.first().json; const d = r.body && r.body.data;\nconst input = $('Webhook').first().json.body || {};\nif (r.statusCode !== 200 || !d) {\n  return [{ json: { ok: false, cui: input.cui, error: (r.body && r.body.error) || { code: 'http_' + r.statusCode } } }];\n}\nreturn [{ json: {\n  ok: true,\n  cui: d.cui, vatId: d.vatId, name: d.name,\n  registrationNumber: d.registrationNumber, registrationDate: d.registrationDate, caenCode: d.caenCode,\n  active: d.status.active, inactiveSince: d.status.inactiveSince,\n  vatRegistered: d.vat.registered, eFacturaRegistered: d.eFactura.registered,\n  address: d.address && d.address.fiscal ? d.address.fiscal.formatted : null,\n  county: d.address && d.address.fiscal ? d.address.fiscal.county : null,\n  source: d.source, creditsRemaining: r.headers && r.headers['x-credits-remaining'],\n  leadId: input.leadId ?? null,\n} }];"
      },
      "id": "20207ab4-ace6-556f-bc0a-415f0f46760e",
      "name": "Lead record",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        760,
        0
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify($json) }}",
        "options": {}
      },
      "id": "48a7685e-7079-55f1-8a9b-6efa892f0759",
      "name": "Respond",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        980,
        0
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ ok: false, error: 'missing_cui', message: 'Send a JSON body with a non-empty \"cui\" field, e.g. {\"cui\":\"RO12345678\"}. No API call was made.', leadId: $json.body?.leadId ?? null }) }}",
        "options": {
          "responseCode": 400
        }
      },
      "id": "ad46bd24-108f-5678-853e-a7dfa00fd490",
      "name": "Respond 400: missing cui",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        540,
        220
      ]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Has CUI?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has CUI?": {
      "main": [
        [
          {
            "node": "HowToRomania: company lookup",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond 400: missing cui",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HowToRomania: company lookup": {
      "main": [
        [
          {
            "node": "Lead record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lead record": {
      "main": [
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}