Reading a Google Sheet on a cron job. How can I handle column headers with spaces?

Describe the problem/error/question

I am successful in pulling data from Google Sheets, but only if the column header I’m looking at has no spaces.

What is the error message (if any)?

Please share your workflow

Here is the Javascript code. If you look at the timestamp code, it works. Timestamp is the name of the actual spreadsheet’s column. If you look at name code, it does not work. ‘Your Business Name’ is the name of the actual spreadsheet’s column

// if new data then add it to an array
    new_items.push({
      json: {
        timestamp: items[i].json.Timestamp,
        name: items[i].json.Your Business Name
      },
    });
  }
}

Share the output returned by the last node

/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Function:17
        name: items[i].json.Your Business Name
                                 ^^^^^^^^

SyntaxError: Unexpected identifier
    at makeNiceSyntaxError (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/transformer.js:41:16)
    at transformer (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/transformer.js:80:8)
    at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/nodevm.js:413:17)
    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Function/Function.node.js:96:31)
    at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/src/Workflow.js:594:51)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/WorkflowExecute.js:537:64
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Information on your n8n setup

I’m not sure where to find this sorry. It’s installed on my private server via docker at the moment.

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

aaaand solved!

It was my javascript

// if new data then add it to an array
    new_items.push({
      json: {
        timestamp: items[i].json.Timestamp,
        name: items[i].json["Your Business Name"]
      },
    });
  }
}
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.