CSV from API without header

Hi! I am consuming an API and get a CSV file from it, but the file does not have a header, then n8n assumes first row as its header. I´ve already solved the problem (or think so), because one of its columns is a DATEVALUE excel format and n8n is breaking its code:

image

(Format dd/mm/yyyy). The original value is 44047.40417824070 and I would like to keep it.

This is my workflow structure:

Http Request -> Spreadsheet (read from file) -> function -> Postgres (insert)

Is there a way to add the spreadsheet header between http request and the read from file steps?

Welcome to the community @bruno.pellanda!

You can do the following:

{
  "nodes": [
    {
      "parameters": {
        "url": "https://support.staffbase.com/hc/en-us/article_attachments/360009197031/username.csv",
        "responseFormat": "string",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "name": "Spreadsheet File",
      "type": "n8n-nodes-base.spreadsheetFile",
      "typeVersion": 1,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "items[0].json.data = 'header1;header2;header3;header4\\n' + items[0].json.data;\nreturn items;"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        600,
        300
      ]
    },
    {
      "parameters": {
        "mode": "jsonToBinary",
        "convertAllData": false,
        "options": {
          "useRawData": true
        }
      },
      "name": "Move Binary Data",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        750,
        300
      ]
    }
  ],
  "connections": {
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function1": {
      "main": [
        [
          {
            "node": "Move Binary Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Move Binary Data": {
      "main": [
        [
          {
            "node": "Spreadsheet File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
2 Likes

Hi Jan!

Thank you very much for your time and help! It worked but now I have to change the charset because of my language:

image

and before it was right. Before this wasn´t happening. Is there any way to do this?

You can try to set “Read As String” and/or “RAW Data” on the Spreadsheet File-Node.

1 Like

Adding encoding latin1 plus read as string solved my problem.

Thank you again !

2 Likes

Ah great to hear! Then have fun!

1 Like