{
  "name": "wf_normalize_location",
  "nodes": [
    {
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "location"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        0,
        0
      ],
      "id": "f2b34493-bf4d-455b-a03b-c0adfa75ece3",
      "name": "workflow_trigger"
    },
    {
      "parameters": {
        "url": "https://api.geoapify.com/v1/geocode/search",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpQueryAuth",
        "sendQuery": true,
        "specifyQuery": "json",
        "jsonQuery": "={\n  \"format\": \"json\",\n  \"limit\": 1,\n  \"text\": \"{{ $json.location }}\"\n}",
        "options": {
          "timeout": 10000
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        208,
        0
      ],
      "id": "c3d31939-7021-43fd-9bf2-448e48e4599b",
      "name": "call_geoapify_search",
      "credentials": {
        "httpQueryAuth": {
          "name": "<your credential>"
        }
      },
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "wRCvCmRGcILIoLjy",
          "mode": "list",
          "cachedResultName": "Underfoot \u2014 wf_error_notifications"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {
            "json": "={{ $json }}",
            "callingWorkflow": "={{ $workflow }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "json",
              "displayName": "json",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "object"
            },
            {
              "id": "callingWorkflow",
              "displayName": "callingWorkflow",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "object"
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "options": {}
      },
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.2,
      "position": [
        416,
        96
      ],
      "id": "07029db1-dcd4-4aee-af82-ee7512cfedbb",
      "name": "call_discord_notifier",
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const response = $json.map(item => {\n  return {\n    \"country_code\": item.country_code,\n    \"name\": item.name,\n    \"country\": item.country,\n    \"state\": item.state,\n    \"state_code\": item.state_code,\n    \"latitude\": item.lat,\n    \"longitude\": item.lon,\n    \"result_type\": item.result_type,\n    \"bbox\": item.bbox\n  }\n})[0];\n\n  const bestResult = response.results.reduce((best, curr) => {\n    const currConfidence =\n      curr.rank && typeof curr.rank.confidence === \"number\"\n        ? curr.rank.confidence\n        : 0;\n    const bestConfidence =\n      best.rank && typeof best.rank.confidence === \"number\"\n        ? best.rank.confidence\n        : 0;\n    return currConfidence > bestConfidence ? curr : best;\n  });\n\n  return {\n    country_code: bestResult.country_code || null,\n    country: bestResult.country || null,\n    state: bestResult.state || null,\n    city: bestResult.city || null,\n    latitude: typeof bestResult.lat === \"number\" ? bestResult.lat : null,\n    longitude: typeof bestResult.lon === \"number\" ? bestResult.lon : null,\n    name:\n      bestResult.name ||\n      bestResult.formatted ||\n      bestResult.address_line1 ||\n      null,\n  };\n}\n\nreturn normalizeLocation(response);\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        416,
        -96
      ],
      "id": "b35ffa9e-4012-485d-9813-7498e6f741a4",
      "name": "pick_best_match"
    }
  ],
  "connections": {
    "workflow_trigger": {
      "main": [
        [
          {
            "node": "call_geoapify_search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "call_geoapify_search": {
      "main": [
        [
          {
            "node": "pick_best_match",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "call_discord_notifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6c11acad-0c98-435d-b7ea-41a3b62bc533",
  "id": "97gX5INNSKK3MdYS",
  "tags": []
}