Describe the problem/error/question
I am attempting to sync contacts from Monica CRM to Nextcloud via an HTTP Request node, but the core data transformation step is failing due to an internal bug in the Code execution context.
The issue is that the Code node cannot correctly read the list of contact objects output by the Monica CRM node, resulting in an empty file upload.
What is the error message (if any)?
Please share your workflow
{
"nodes": [
{
"parameters": {
"operation": "getAll",
"returnAll": true,
"filters": {}
},
"type": "n8n-nodes-base.monicaCrm",
"typeVersion": 1,
"position": [
96,
-160
],
"id": "0104ce57-7209-4f89-aee0-26feba35e7cc",
"name": "Get many contacts",
"credentials": {
"monicaCrmApi": {
"id": "ddml7GlTEBOJ9zXn",
"name": "Monica CRM account"
}
}
}
],
"connections": {
"Get many contacts": {
"main": [
[]
]
}
},
"pinData": {},
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "038c9307478b79e50b6edb10898af03ea475201efa7b561785052bc2383ba957"
}
}
{
"nodes": [
{
"parameters": {
"jsCode": "// 1. Get the array of all incoming items and combine them into one array.\n// This is the array of your 5 contact objects.\nconst contactsArray = $input.all().map(item => item.json);\n\n// 2. Create the JSON string for the file content\nconst fileContentString = JSON.stringify(contactsArray, null, 2); \n\n// 3. Create a unique filename\nconst timestamp = new Date().toISOString().replace(/[:.]/g, '-');\nconst fileName = `monica_contacts_export_${timestamp}.json`;\n\n// 4. Convert the string to a Buffer (Node.js global standard)\nconst buffer = new Buffer.from(fileContentString, 'utf8');\n\n// 5. Return a single item with the file data attached\nreturn [{\n json: {\n fileName: fileName \n },\n binary: {\n fileData: { // This key is referenced in the HTTP Request node\n data: buffer,\n mimeType: 'application/json',\n fileName: fileName\n }\n }\n}];"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
304,
-160
],
"id": "784e6e53-1c2a-4533-8395-029b2c6de2fb",
"name": "Code in JavaScript"
}
],
"connections": {},
"pinData": {},
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "038c9307478b79e50b6edb10898af03ea475201efa7b561785052bc2383ba957"
}
}
Share the output returned by the last nodehe Problem
-
The Monica CRM node successfully outputs a list of 5 separate items, with the raw JSON being an array of contact objects (
[{contact 1}, {contact 2}, ...]). -
The Code node is supposed to combine these 5 items into a single array for the file, using the standard, logically correct code:
const contactsArray = $input.all().map(item => item.json);. -
The Code node consistently fails to populate the
contactsArrayvariable, leading to an empty array being stringified and an empty file being uploaded. -
All standard workarounds (
Functionnode,Aggregatenode, different variable access methods likeitemsand$json.items) have been tested and also failed, indicating an internal sandbox bug in this environment.
Request
Could you please advise on the specific Code node variable path required for my environment to correctly map this multi-item Monica output?
Information on your n8n setup
- n8n version:
- Database (default: SQLite):
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker, npm, n8n cloud, desktop app):
- Operating system:
PS. I am a noob on n8n. Gemini, ChatGPT and Perplexity have been tasked to make me an interface Monica <> Nextcloud but failed for hours trying. The above is the final verdict from Gemini.