{
  "name": "Enrich new signups with country, currency and timezone (IPWho)",
  "nodes": [
    {
      "parameters": {
        "content": "## Enrich new signups with country, currency and timezone\n\n### How it works\n1. A signup arrives at the **Webhook** as JSON with `email` and `ip`. To test without a webhook, click **Execute workflow**; the manual trigger sends a sample signup.\n2. **Normalise signup** reads `email` and `ip` from either trigger.\n3. **Look up IP with IPWho** calls the IPWho IP geolocation API (`GET /ip/{ip}`) through n8n's HTTP Request node.\n4. **Add location fields** returns the signup with country, region, city, EU flag, currency, timezone and connection type. Failed lookups and signups without an IP are flagged, not dropped.\n\n### Setup\n1. Get a free IPWho API key (2,000 lookups/day, no card): https://www.ipwho.org/free-plan?utm_source=n8n&utm_medium=template&utm_campaign=ip-geolocation-n8n\n2. Open **Look up IP with IPWho** and create a **Header Auth** credential: Name `X-API-Key`, Value = your key. Never paste the key into the URL or a node field.\n3. Run it once with **Execute workflow** to check the output, then activate it and POST signups to the production webhook URL.\n\n### Customization\nSend the result to your CRM or database by adding a node after **Add location fields**. Region and city can be empty for some IPs; country is the most reliable level. Field reference: https://www.ipwho.org/docs",
        "height": 820,
        "width": 520
      },
      "id": "0b6f3a51-6c1e-4f43-9a51-6a0b3a0c0001",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -620,
        -260
      ]
    },
    {
      "parameters": {
        "content": "## Receive the signup\nWebhook for live signups, manual trigger plus sample data for testing. Both end up as one item with `email` and `ip`.",
        "height": 520,
        "width": 700,
        "color": 7
      },
      "id": "0b6f3a51-6c1e-4f43-9a51-6a0b3a0c0002",
      "name": "Section: receive",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -60,
        -260
      ]
    },
    {
      "parameters": {
        "content": "## Look up the IP\nSkips signups with no IP, then calls IPWho with your Header Auth credential. Errors go to the lower output instead of stopping the run.",
        "height": 520,
        "width": 520,
        "color": 7
      },
      "id": "0b6f3a51-6c1e-4f43-9a51-6a0b3a0c0003",
      "name": "Section: lookup",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        680,
        -260
      ]
    },
    {
      "parameters": {
        "content": "## Shape the result\nFlattens the IPWho response into plain fields. Every field can be null, so the record always has the same columns.",
        "height": 620,
        "width": 360,
        "color": 7
      },
      "id": "0b6f3a51-6c1e-4f43-9a51-6a0b3a0c0004",
      "name": "Section: result",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1240,
        -260
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "ipwho-enrich-signup",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "0b6f3a51-6c1e-4f43-9a51-6a0b3a0c0010",
      "name": "New signup (webhook)",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        -80
      ],
      "webhookId": "5f0c2d7e-2b8a-4a5e-9d1c-7e1a3b9c4d10"
    },
    {
      "parameters": {},
      "id": "0b6f3a51-6c1e-4f43-9a51-6a0b3a0c0011",
      "name": "Test with a sample signup",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        120
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a1",
              "name": "email",
              "value": "jane@example.com",
              "type": "string"
            },
            {
              "id": "a2",
              "name": "ip",
              "value": "76.102.11.203",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "0b6f3a51-6c1e-4f43-9a51-6a0b3a0c0012",
      "name": "Sample signup",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        120
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "b1",
              "name": "email",
              "value": "={{ $json.body?.email ?? $json.email ?? null }}",
              "type": "string"
            },
            {
              "id": "b2",
              "name": "ip",
              "value": "={{ String($json.body?.ip ?? $json.ip ?? '').trim() }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "0b6f3a51-6c1e-4f43-9a51-6a0b3a0c0013",
      "name": "Normalise signup",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        440,
        20
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.ip }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "0b6f3a51-6c1e-4f43-9a51-6a0b3a0c0020",
      "name": "Has an IP?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        720,
        20
      ]
    },
    {
      "parameters": {
        "url": "=https://api.ipwho.org/ip/{{ encodeURIComponent($json.ip) }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "n8n-ipwho-template/1.0"
            }
          ]
        },
        "options": {
          "timeout": 10000
        }
      },
      "id": "0b6f3a51-6c1e-4f43-9a51-6a0b3a0c0021",
      "name": "Look up IP with IPWho",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        960,
        -60
      ],
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "d1",
              "name": "email",
              "value": "={{ $('Normalise signup').item.json.email }}",
              "type": "string"
            },
            {
              "id": "d2",
              "name": "ip",
              "value": "={{ $('Normalise signup').item.json.ip }}",
              "type": "string"
            },
            {
              "id": "d3",
              "name": "country",
              "value": "={{ $json.data?.geoLocation?.country ?? null }}",
              "type": "string"
            },
            {
              "id": "d4",
              "name": "countryCode",
              "value": "={{ $json.data?.geoLocation?.countryCode ?? null }}",
              "type": "string"
            },
            {
              "id": "d5",
              "name": "region",
              "value": "={{ $json.data?.geoLocation?.region ?? null }}",
              "type": "string"
            },
            {
              "id": "d6",
              "name": "regionCode",
              "value": "={{ $json.data?.geoLocation?.regionCode ?? null }}",
              "type": "string"
            },
            {
              "id": "d7",
              "name": "city",
              "value": "={{ $json.data?.geoLocation?.city ?? null }}",
              "type": "string"
            },
            {
              "id": "d8",
              "name": "is_in_eu",
              "value": "={{ $json.data?.geoLocation?.is_in_eu ?? null }}",
              "type": "boolean"
            },
            {
              "id": "d9",
              "name": "currency",
              "value": "={{ $json.data?.currency?.code ?? null }}",
              "type": "string"
            },
            {
              "id": "d10",
              "name": "time_zone",
              "value": "={{ $json.data?.timezone?.time_zone ?? null }}",
              "type": "string"
            },
            {
              "id": "d11",
              "name": "connection_type",
              "value": "={{ $json.data?.connection?.connection_type ?? null }}",
              "type": "string"
            },
            {
              "id": "d12",
              "name": "ipwho_status",
              "value": "={{ $json.success === true ? 'ok' : 'no_data' }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "0b6f3a51-6c1e-4f43-9a51-6a0b3a0c0030",
      "name": "Add location fields",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1300,
        -120
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "e1",
              "name": "email",
              "value": "={{ $('Normalise signup').item.json.email }}",
              "type": "string"
            },
            {
              "id": "e2",
              "name": "ip",
              "value": "={{ $('Normalise signup').item.json.ip }}",
              "type": "string"
            },
            {
              "id": "e3",
              "name": "ipwho_status",
              "value": "lookup_failed",
              "type": "string"
            },
            {
              "id": "e4",
              "name": "ipwho_error",
              "value": "={{ typeof $json.error === 'string' ? $json.error : ($json.error?.message ?? 'IPWho lookup failed') }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "0b6f3a51-6c1e-4f43-9a51-6a0b3a0c0031",
      "name": "Flag failed lookup",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1300,
        80
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f1",
              "name": "email",
              "value": "={{ $json.email }}",
              "type": "string"
            },
            {
              "id": "f2",
              "name": "ip",
              "value": "={{ $json.ip }}",
              "type": "string"
            },
            {
              "id": "f3",
              "name": "ipwho_status",
              "value": "no_ip",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "0b6f3a51-6c1e-4f43-9a51-6a0b3a0c0032",
      "name": "Flag missing IP",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1300,
        260
      ]
    }
  ],
  "pinData": {},
  "connections": {
    "New signup (webhook)": {
      "main": [
        [
          {
            "node": "Normalise signup",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Test with a sample signup": {
      "main": [
        [
          {
            "node": "Sample signup",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sample signup": {
      "main": [
        [
          {
            "node": "Normalise signup",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalise signup": {
      "main": [
        [
          {
            "node": "Has an IP?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has an IP?": {
      "main": [
        [
          {
            "node": "Look up IP with IPWho",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Flag missing IP",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Look up IP with IPWho": {
      "main": [
        [
          {
            "node": "Add location fields",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Flag failed lookup",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
