Hello. I am a new user of n8n. First off, thanks for the great tool, I am enjoying working with it!
Onto the problem:
I am trying to setup a workflow where I retrieve a set of calendar events through a HTTP node and create events in my Google Calendar.
The HTTP API call returns JSON data which is itself an array. This is the output when I use cURL on my terminal:
[
{}, // Event 1
{} // Event 2
]
Unfortunately in the workflow this shows up at the input of Split In Batches (after HTTP node) like this:
[
[
{}, // Event 1
{} // Event 2
]
]
I think Split in Batches is considering this as one item (my batch size is 1) so my Google Calendar event fires only once. I tried adding a Function node, but that still outputs as a nested list.
No matter what I do I am unable to transform the data to a format that Split in Batches can understand. Could you help please? Thanks.
Here is a workflow showing reproduction of the error:
"name": "Nested-Array",
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
250,
300
]
},
{
"parameters": {
"functionCode": "const item = \n[{\n \"json\": [\n {\"subject\": \"Lecture A\", \"startTime\": \"X\"},\n {\"subject\": \"Lecture B\", \"startTime\": \"Y\"},\n {\"subject\": \"Lecture C\", \"startTime\": \"Z\"}\n ]\n}];\n\nreturn item;\n"
},
"name": "API Output",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
490,
290
]
},
{
"parameters": {
"functionCode": "return item;"
},
"name": "return item",
"type": "n8n-nodes-base.functionItem",
"typeVersion": 1,
"position": [
780,
320
]
},
{
"parameters": {
"functionCode": "return item[0];"
},
"name": "return item[0]",
"type": "n8n-nodes-base.functionItem",
"typeVersion": 1,
"position": [
780,
140
]
},
{
"parameters": {
"functionCode": "const newItems = [];\nsubArray = items[0]\nfor (let i=0;i<subArray.length;i++) {\n newItems.push({\n json: {\n startTime: subArray.startTime,\n subject: subArray.subject \n }\n });\n}\n\nreturn items;\n"
},
"name": "Function",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
780,
690
]
},
{
"parameters": {
"functionCode": "newItems = [];\n\nfor (let i=0;i<item.length;i++) {\n newItems.push({\n json: {\n startTime: item[i].startTime,\n subject: item[i].subject \n }\n });\n}\n\nreturn newItems;\n"
},
"name": "Populate New Array",
"type": "n8n-nodes-base.functionItem",
"typeVersion": 1,
"position": [
780,
510
]
}
],
"connections": {
"API Output": {
"main": [
[
{
"node": "return item[0]",
"type": "main",
"index": 0
},
{
"node": "return item",
"type": "main",
"index": 0
},
{
"node": "Populate New Array",
"type": "main",
"index": 0
},
{
"node": "Function",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {},
"id": "2"
}