For my workflow i need to make a multipart/form-data request. I found some examples on the forum and put together the snippets. However the last function node always returns: “ERROR: Cannot read properties of undefined (reading ‘split’)” and i have no clue why.
What is the error message (if any)?
ERROR: Cannot read properties of undefined (reading ‘split’)
TypeError: Cannot read properties of undefined (reading 'split')
at Object.execute (/app/code/node_modules/n8n-nodes-base/dist/nodes/Function/Function.node.js:127:91)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Workflow.runNode (/app/code/node_modules/n8n-workflow/dist/src/Workflow.js:594:28)
at async /app/code/node_modules/n8n-core/dist/src/WorkflowExecute.js:557:53
Please share the workflow
Information on your n8n setup
n8n version: 0.167.2
Database you’re using (default: SQLite): Postgresql
Running n8n with the execution process [own(default), main]: own
Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker/Cloudron
Hi @JUVOJustin,
you are not doing any split in your function node, so the error may happen outside of your code. In your function node you do not return any data. Can you try adding return items; to the end?
Sadly the same result. Same error. Ideally, i would like to return the response result later to check if the submit worked. However right now the request fails in the first place.
Also tried the dummy file you used with the exact same http node to w3. Replaced the functions to functionItem to use getBinaryData() in case there is something going on i am not aware of. As you said when returning items/item the node executes but with for the request i still get an error 500 no matter which file it submits.
If no file is provided, the file upload endpoint returns HTTP status 500
I sadly cannot try out lexoffice’s api. Can you try out not setting the Content-Type header, the request helper should set it automatically if you use FormData.
I know it is a lot to ask, but do you maybe have an idea why the lexoffice endpoint fails? My understanding of the binary stuff is not that great and i am wondering if it is correct to only sending the “data” without the other file info to lexoffice. Coming from integromat/make i was used to creating the form entries via the ui, and formatting was done automagically.
Thank you very much. I solved it. Here is my working code in case anyone needs the same thing. Definitely looking forward to an integrated way to mix form requests
var axios = require('axios');
var FormData = require('form-data');
// Get all currently existing binary data
const binaryData = getBinaryData().data
var data = new FormData();
data.append('file', Buffer.from(binaryData.data, 'base64'), item.filename);
data.append('type', 'voucher');
var config = {
url: 'https://api.lexoffice.io/v1/files',
headers: {
'Authorization': 'Bearer *****',
...data.getHeaders()
},
method: 'POST',
body: data,
};
try {
await this.helpers.httpRequest(config);
return item;
} catch(ex) {
return ex;
}
I dont know why put passing the filename from “data” caused error 400. Passing the “real” filename from zammad works for whatever reason. Don’t know what on earth lexoffice is checking there
However it works and i have to thank you very much.