For the life of me I cannot figure out how to pass the entire data through a Switch node. For some reason, I’m only passing the first item in the entire data.
How does one go about passing all 434 items in my screenshot below to the MySQL node?
Hi @anon3028993, how is your Switch node configured? Are you perhaps using an expression that only works for the first item?
Here is an example of the Switch node running for every single input item for reference.
You can copy the JSON data below right in your n8n canvas to try it out.
Example Workflow
My initial request only covered a portion of the workflow because I thought this might be a simple question, but in hindsight I may have more going on here than initially thought.
The end goal is to have a webhook trigger that reads the CSV file then dumps the data into a MySQL DB, or returns the CSV file in JSON format based upon the request coming into the webhook. I also cannot get the webhook response to return more than one record when the second switch node sees the “action” set to “returnjson”
The HTTP requests should look like:
http://{n8nhost}/webhook-test/parklane-testing?get=allcontacts&action=dumptodb
OR:
http://{n8nhost}/webhook-test/parklane-testing?get=allcontacts&action=returnjson
Sample data and workflow below…
Sample data
First Name,Last Name,Created
Benita,Sloan,04/14/21
Abby,Wiles,03/01/21
Adrienne,Suits,08/25/20
Adrienne,White,09/21/20
Alaire,Wood,03/02/21
Alexis,Grant,04/22/20
Alicia,Morse,11/10/20
Alicia,Tidwell,10/27/21
Alicia,Belanger,12/08/21
Alissa,Grazulis,07/23/20
Allison,Wooden,06/09/21
Allison,Lightfoot,03/02/21
Allison,Mann,05/27/20
Amanda,Audas,01/05/22
Amanda,Audas,08/31/20
Amanda,Audas,10/30/20
Amanda,Ballard,09/14/20
Amanda,Holley,05/19/21
Amanda,Shillings,09/01/20
Amber,ORourke,06/29/20
Amy,White,07/29/20
Amy,Gates,08/11/21
Amy,Pugh,06/15/21
My Workflow
{
“name”: “Testing”,
“nodes”: [
{
“parameters”: {},
“name”: “Start”,
“type”: “n8n-nodes-base.start”,
“typeVersion”: 1,
“position”: [
-840,
260
]
},
{
“parameters”: {
“operation”: “executeQuery”,
“query”: “=INSERT INTO contacts (first_name,last_name,date_created,address,city,state,zip,email,phone)\nVALUES (\n’{{$node[“RenameKeys”].json[“first_name”]}}’,\n’{{$node[“RenameKeys”].json[“last_name”]}}’,\nSTR_TO_DATE(’{{$node[“RenameKeys”].json[“date_created”]}}’,”%m/%d/%y"),\n’{{$node[“RenameKeys”].json[“address”]}}’,\n’{{$node[“RenameKeys”].json[“city”]}}’,\n’{{$node[“RenameKeys”].json[“state”]}}’,\n’{{$node[“RenameKeys”].json[“zip”]}}’,\n’{{$node[“RenameKeys”].json[“email”]}}’,\n’{{$node[“RenameKeys”].json[“phone”]}}’\n);"
},
“name”: “Insert Contacts”,
“type”: “n8n-nodes-base.mySql”,
“typeVersion”: 1,
“position”: [
460,
460
],
“credentials”: {
“mySql”: {
“id”: “1”,
“name”: “blingshop-rogue”
}
}
},
{
“parameters”: {
“dataType”: “string”,
“value1”: “={{$node[”/parklane-testing"].json[“query”][“action”]}}",
“rules”: {
“rules”: [
{
“value2”: “dumptodb”
},
{
“value2”: “returnjson”
}
]
}
},
“name”: “action?”,
“type”: “n8n-nodes-base.switch”,
“typeVersion”: 1,
“position”: [
180,
620
],
“alwaysOutputData”: false
},
{
“parameters”: {
“dataType”: “string”,
“value1”: “={{$json[“query”][“get”]}}”,
“rules”: {
“rules”: [
{
“value2”: “allcontacts”
}
]
}
},
“name”: “get?”,
“type”: “n8n-nodes-base.switch”,
“typeVersion”: 1,
“position”: [
-780,
660
]
},
{
“parameters”: {
“respondWith”: “text”,
“responseBody”: “={{$node[“RenameKeys”].json}}”,
“options”: {
“responseCode”: 200
}
},
“name”: “Respond to Webhook”,
“type”: “n8n-nodes-base.respondToWebhook”,
“typeVersion”: 1,
“position”: [
960,
620
]
},
{
“parameters”: {
“keepOnlySet”: true,
“values”: {
“string”: [
{
“name”: “={{$node[“Respond to Webhook”].parameter[“options”][“responseCode”]}}”,
“value”: “200”
}
]
},
“options”: {}
},
“name”: “Set Response Code”,
“type”: “n8n-nodes-base.set”,
“typeVersion”: 1,
“position”: [
620,
460
]
},
{
“parameters”: {
“options”: {
“headerRow”: true,
“includeEmptyCells”: true,
“rawData”: true,
“readAsString”: true
}
},
“name”: “Spreadsheet File”,
“type”: “n8n-nodes-base.spreadsheetFile”,
“typeVersion”: 1,
“position”: [
-260,
620
]
},
{
“parameters”: {
“filePath”: “/home/node/.n8n/contacts_redacted.csv”
},
“name”: “Read Binary File”,
“type”: “n8n-nodes-base.readBinaryFile”,
“typeVersion”: 1,
“position”: [
-480,
620
]
},
{
“parameters”: {
“keys”: {
“key”: [
{
“currentKey”: “First Name”,
“newKey”: “first_name”
},
{
“currentKey”: “=Last Name”,
“newKey”: “last_name”
},
{
“currentKey”: “Created”,
“newKey”: “date_created”
},
{
“currentKey”: “E-mail”,
“newKey”: “email”
},
{
“currentKey”: “City”,
“newKey”: “city”
},
{
“currentKey”: “State”,
“newKey”: “state”
},
{
“currentKey”: “Zip”,
“newKey”: “zip”
},
{
“currentKey”: “Phone”,
“newKey”: “phone”
},
{
“currentKey”: “Address”,
“newKey”: “address”
}
]
}
},
“name”: “RenameKeys”,
“type”: “n8n-nodes-base.renameKeys”,
“typeVersion”: 1,
“position”: [
-60,
620
]
},
{
“parameters”: {
“path”: “parklane-testing”,
“responseMode”: “responseNode”,
“options”: {}
},
“name”: “/parklane-testing”,
“type”: “n8n-nodes-base.webhook”,
“typeVersion”: 1,
“position”: [
-960,
660
],
“webhookId”: “970160b4-3d34-4cc9-8ef8-bed909079395”
}
],
“connections”: {
“action?”: {
“main”: [
[
{
“node”: “Insert Contacts”,
“type”: “main”,
“index”: 0
}
],
[
{
“node”: “Respond to Webhook”,
“type”: “main”,
“index”: 0
}
]
]
},
“Set Response Code”: {
“main”: [
[
{
“node”: “Respond to Webhook”,
“type”: “main”,
“index”: 0
}
]
]
},
“Read Binary File”: {
“main”: [
[
{
“node”: “Spreadsheet File”,
“type”: “main”,
“index”: 0
}
]
]
},
“Spreadsheet File”: {
“main”: [
[
{
“node”: “RenameKeys”,
“type”: “main”,
“index”: 0
}
]
]
},
“RenameKeys”: {
“main”: [
[
{
“node”: “action?”,
“type”: “main”,
“index”: 0
}
]
]
},
“Start”: {
“main”: [
[]
]
},
“/parklane-testing”: {
“main”: [
[
{
“node”: “get?”,
“type”: “main”,
“index”: 0
}
]
]
},
“get?”: {
“main”: [
[
{
“node”: “Read Binary File”,
“type”: “main”,
“index”: 0
}
]
]
},
“Insert Contacts”: {
“main”: [
[
{
“node”: “Set Response Code”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“active”: false,
“settings”: {},
“id”: 2
}