Hi all, hopefully this is me being stupid. I really do NOT get this is supposed to work. I am using an HTTP request node to query the Okta API to get a list of users. Okta will return a simple array with user objects like this:
[
{ "id": "id0",
"profile": {
"firstName": "hey",
"lastName": "ho silver"
}
},
# etc. pp
]
I connected the REST node to an iteration node, because I am only interested in the value of a single property (“id”). Now it get’s funny. It seems that the REST node is putting the whole array returned from Okta into another array, which looks like this if you open it:
[
[
{
"id": "XXXXxxxxxxx.......",
"status": "ACTIVE",
"created": "2018-07-23T15:25:00.000Z",
"activated": "2018-07-23T15:25:01.000Z",
// etc. etc.
Which does not make sense to me, but okay.
Now I thought “okay, let’s remove the outer array” with a function node doing this: return items[0];
(cause this should do the trick, right?!) I get this result:
Error: Always an Array of items has to be returned!
at Object.execute (/Users/tm/.npm/_npx/a8a7eec953f1f314/node_modules/n8n-nodes-base/dist/nodes/Function.node.js:74:19)
at processTicksAndRejections (node:internal/process/task_queues:93:5)
at async /Users/tm/.npm/_npx/a8a7eec953f1f314/node_modules/n8n-core/dist/src/WorkflowExecute.js:395:47
Since we have an array which contains only another array this should not be an issue, right?! But no.
Also when I switch to the “table” view - all the elements are displayed correctly!! So the node does somehow recognize that there are multiple elements.
Thinking maybe this is just normal I try to extract the “profile” sub-object using a FunctionItem node (return item["profile"]
as single code line), but now I get this:
Error: No data got returned. Always an object has to be returned!
at Object.executeSingle (/Users/tm/.npm/_npx/a8a7eec953f1f314/node_modules/n8n-nodes-base/dist/nodes/FunctionItem.node.js:78:19)
at processTicksAndRejections (node:internal/process/task_queues:93:5)
at async Promise.all (index 0)
at async Workflow.runNode (/Users/tm/.npm/_npx/a8a7eec953f1f314/node_modules/n8n-workflow/dist/src/Workflow.js:481:34)
at async /Users/tm/.npm/_npx/a8a7eec953f1f314/node_modules/n8n-core/dist/src/WorkflowExecute.js:395:47
When I (just for testing) replace this with return item;
- it works and returns everything.
I just don’t get it. Can somebody elaborate maybe?