How to add arbitrary data to a blank Sheet in an Excel file?

Hello,

I have a workflow where the workflow emitter seems to be some kind of buggy. I do receive the webhook that contains the following JSON

[
  {
    "headers": {
      "host": "example.app.n8n.cloud",
      "user-agent": "Zapier",
      "content-length": "488",
      "accept": "*/*",
      "accept-encoding": "gzip, br",
      "cdn-loop": "cloudflare; loops=1; subreqs=1",
      "cf-connecting-ip": "0.0.0.0",
      "cf-ew-via": "15",
      "cf-ipcountry": "XX",
      "cf-ray": "xxxxxxxxxxxxxxxx-XXX",
      "cf-visitor": "{\"scheme\":\"https\"}",
      "cf-worker": "n8n.cloud",
      "traceparent": "00-00000000000000000000000000000000-0000000000000000-00",
      "tracestate": "dd=s:0;t.dm:-0",
      "x-datadog-parent-id": "0000000000000000000",
      "x-datadog-sampling-priority": "0",
      "x-datadog-tags": "_dd.p.dm=-0",
      "x-datadog-trace-id": "0000000000000000000",
      "x-forwarded-for": "0.0.0.0, 0.0.0.0",
      "x-forwarded-host": "example.app.n8n.cloud",
      "x-forwarded-port": "443",
      "x-forwarded-proto": "https",
      "x-forwarded-server": "example-server",
      "x-is-trusted": "yes",
      "x-real-ip": "0.0.0.0"
    },
    "params": {},
    "query": {
      "mode": "lead_status_changed"
    },
    "body": {},
    "webhookUrl": "https://example.app.n8n.cloud/webhook/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "executionMode": "production"
  }
]

The binary content of the Webhook is defined as a binary file (File Extension: bin/Mime Type: application/octet-stream):

image

But when I download the file and open it, it contains regular JSON (no binary content):

{
  "leadID": "xxxxxxxxxxxxxxxxxxxxxx",
  "campaignID": "xxxxxxxxxxxxxxxxxxxxxx",
  "campaignName": "Kampagne XYZ",
  "customerID": "xxxxxxxxxxxxxxxxxxxxxx",
  "customerName": "Beispiel GmbH",
  "oldStatus": "Alter Status",
  "newStatus": "Neuer Status",
  "leadEmail": "[email protected]",
  "leadPhone": "+00 0000 000000",
  "leadName": "Max Muster",
  "responsible": "xxxxxxxxxxxxxxxxxxxxxx",
  "message": "Beispielnachricht",
  "querystring": {}
}

And this is what I guess could be the bug, that it comes as JSON, not as binary.

However, I cannot seem to find a way to extract the JSON out of this file. All I did so far was to try to access the binary file content but all approaches fail. This is my Code node code:

// Fetch the binary data from the Webhook node
const webhookNode = $('Webhook').first();
if (!webhookNode) {
  throw new Error('Webhook node did not provide any data.');
}

// Retrieve the binary data
const binaryData = webhookNode.binary?.data;
if (!binaryData || !binaryData.id) {
  throw new Error('No valid binary data found or file ID is missing.');
}

// Fetch the file using the file ID
const fileData = await this.helpers.getBinaryDataBuffer(binaryData.id);

// Check if the file was successfully loaded
if (!fileData) {
  throw new Error('The file could not be loaded from the file system.');
}

// Convert the binary data to a readable string
const fileContent = fileData.toString('utf-8');

// Attempt to parse the string as JSON
try {
  const jsonData = JSON.parse(fileContent);
  return {
    json: jsonData
  };
} catch (error) {
  throw new Error(`Error parsing JSON data: ${error.message}. File content: ${fileContent}`);
}

Do you have any idea what I could do in order to fetch the JSON out of the “binary” file? Any help appreciated.

Thanks in advance, kind regards!
Moritz

P.S. Using an “Extract from File” node with Operation “Move File to Base64 String” returns no output data…

P.P.S. Edit:

I forgot to add the following information

  • n8n version: 1.67.1
  • Database (default: SQLite): n8n cloud default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): n8n cloud default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud
  • Operating system: n8n cloud default

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Welcome to the community @morrez !

Tip for sharing information

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

That implies to any JSON output you would like to share with us.

Make sure that you have removed any sensitive information from your workflow and include dummy or pinned data with it!


You do not need Code node to produce JSON from binary file. Her’s how to do it.

That is, use Extract from File and Split Out nodes to achieve that.