Parse data from Webhook issue

i have got data in the body in webhook, now I want each JSON output to send an email, now which nodes shall I use so that it can send an email, email will go to all JSON output one by one, when I tried then email went to only to first JSON output but I want to sent to all one by one how its possible, Webhook will have multiple JSON Output
“body”: [

{

“name”: “name of client1”,

“email”: “emailid of client 1”,

“phone”: phone no of client 1,

“Live class on 28 Dec at 11 AM by Chandan sir Launch Meeting - Zoom Meeting ID: 82606406292 Passcode: soiim”: “Live class on 28 Dec at 11 AM by Chandan sir Launch Meeting - Zoom Meeting ID: 82606406292 Passcode: soiim”

},

{

“Name”: “client2”,

“email”: “client2email”,

“phone”: clientphone2,

“Live class on 28 Dec at 11 AM by Chandan sir Launch Meeting - Zoom Meeting ID: 82606406292 Passcode: soiim”: “Live class on 28 Dec at 11 AM by Chandan sir Launch Meeting - Zoom Meeting ID: 82606406292 Passcode: soiim”

},

{

“name”: “client 3”,

“email”: “client 3 email”,

“phone”: client 3 phone,

“Live class on 28 Dec at 11 AM by Chandan sir Launch Meeting - Zoom Meeting ID: 82606406292 Passcode: soiim”: “Live class on 28 Dec at 11 AM by Chandan sir Launch Meeting - Zoom Meeting ID: 82606406292 Passcode: soiim”

},

{

“name”: “client 4”,

“email”: “client 4 email”,

“phone”: client 4 phone,

“Live class on 28 Dec at 11 AM by Chandan sir Launch Meeting - Zoom Meeting ID: 82606406292 Passcode: soiim”: “Live class on 28 Dec at 11 AM by Chandan sir Launch Meeting - Zoom Meeting ID: 82606406292 Passcode: soiim”

}

]

Hi @chandan988, I assume the email addresses are dummy ones? If not, you might want to redact them.

Assuming the body array field from your example is a top level field (and not nested in other fields), you could use a workflow like this to transform the single array field into individual n8n items and send out an email for each item:

Example Workflow
{
  "nodes": [
    {
      "parameters": {
        "fromEmail": "[email protected]",
        "toEmail": "={{$json[\"email\"]}}",
        "subject": "Test",
        "text": "Hello, World",
        "options": {}
      },
      "name": "Send Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        900,
        300
      ],
      "credentials": {
        "smtp": {
          "id": "14",
          "name": "SMTP Account"
        }
      }
    },
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [{\n  json: {\n    body: [{\n      name: \"foo\",\n      email: \"[email protected]\"\n    }, {\n      name: \"bar\",\n      email: \"[email protected]\"\n    }, {\n      name: \"baz\",\n      email: \"[email protected]\"\n    }]\n  }\n}]"
      },
      "name": "Set Example Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "body",
        "options": {}
      },
      "name": "Item Lists",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {
        "fromEmail": "[email protected]",
        "toEmail": "={{$json[\"email\"]}}",
        "subject": "Test",
        "text": "Hello, World",
        "options": {}
      },
      "name": "Send Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        900,
        300
      ],
      "credentials": {
        "smtp": {
          "id": "14",
          "name": "SMTP Account"
        }
      }
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set Example Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Example Data": {
      "main": [
        [
          {
            "node": "Item Lists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Item Lists": {
      "main": [
        [
          {
            "node": "Send Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

So, i want to add all JSON output to append google sheet so after list item node I can use spreadsheet append node and it will append all values , correct me if I am not wrong


i get error when i do

From the screenshot it looks like you have added an expression in the Fields To Split Out field. Can you try resetting that value (by clicking on the little gears icon next to it) and enter the field name of your array (I think it’s body)?

Like so:
image

1 Like

Yes i am able to do and data is in format as i wanted, But it sends to other node in single shot, can we control this speed to avoid issue ( ie sending too many request in single time ) for sending whatsapp or any any other httpsapi

if data output json in this format which node to be used for parse data into correct format

“body”: {

“{“name":“chandan”,“EmailID”:"[email protected]”,“PhoneNo”:“7838808080”,“Batch Schedule”:“Live class on 28 Dec at 11 AM by Chandan sir Launch Meeting - Zoom”: “OEhEbUgrblNzdWd5RDdrTVcwRm9zZz09 Meeting ID: 82606406292 Passcode: soiim”,“status”:“send”,“SpreadsheetName”:“Live Class Notifcation for Class”,“SpreadsheetID”:“1WVndpiWw5cLjiHo3PAYk9m9B0YB7ehsv2UzyRieFAng”,“SheetName”:“Sheet1”,“SheetID”:0,“TriggerColumn”:“E”,“RowIndex”:2}”

}

in this i am getting error this is not an array so any node I can use

So this looks like a very different data structure from what you have originally shared. It also doesn’t seem like valid JSON. Could you share a screenshot of the JSON data in n8n?

Woah, this looks like the body object has a stringified (but seemingly incomplete) JSON object as the first key. That’s absolutely wild and I can’t think of a good way of parsing it tbh. Any chance you can revert back to the previous format including a valid array? That was much more suitable for processing in n8n.

ok noted, thank you. will try with array format

1 Like