diff --git a/agent.md b/agent.md index a2bd01d..754eceb 100644 --- a/agent.md +++ b/agent.md @@ -43,16 +43,16 @@ GET Authorization: Basic ``` -Response — n8n may return a JSON array, a single object, or NDJSON. -All three formats are handled by `parseJson()` (see below). +**Actual response shape** (confirmed via console): ```json -[ - { "Name": "Oliver", "id": 1, "createdAt": "...", "updatedAt": "..." }, - { "Name": "Luka", "id": 2, ... }, - { "Name": "Benni", "id": 3, ... } -] +{ "Name": ["Oliver", "Luka", "Benni"] } ``` +`buildDropdown()` handles all three shapes n8n may return: +1. `{ Name: ["Oliver", "Luka", "Benni"] }` — single object, Name is an array (current) +2. `[ { Name: "Oliver" }, ... ]` — array of objects +3. `{ Name: "Oliver" }` — single object, Name is a string + ### POST — submit scan Called when the user presses Enter in the scan input. diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..b1655e7 Binary files /dev/null and b/favicon.ico differ diff --git a/index.html b/index.html index a2a3d0a..ef9c137 100644 --- a/index.html +++ b/index.html @@ -1280,6 +1280,7 @@ } const data = await parseJson(res); + console.log("[HR] Users response:", data); buildDropdown(data); hideBanner(); } catch (err) { @@ -1296,15 +1297,25 @@ function buildDropdown(users) { userSelect.innerHTML = ''; - // Normalise: webhook may return a single object or an array - const list = Array.isArray(users) - ? users - : users - ? [users] - : []; - list.forEach((u) => { - const opt = new Option(u.Name, u.Name); - userSelect.appendChild(opt); + + // Normalise all shapes n8n may return: + // { Name: ["Oliver", "Luka", "Benni"] } ← actual format + // [ { Name: "Oliver" }, ... ] ← standard array + // { Name: "Oliver" } ← single object + let names = []; + if (Array.isArray(users)) { + // Array of objects: pull .Name from each + names = users.map((u) => u.Name).filter(Boolean); + } else if (users && Array.isArray(users.Name)) { + // Single object with a Name array + names = users.Name.filter(Boolean); + } else if (users && users.Name) { + // Single object with a single Name string + names = [users.Name]; + } + + names.forEach((name) => { + userSelect.appendChild(new Option(name, name)); }); }