How to pass entire body of request / response as parameters to another node?

Hi all,

I’ve got a typical webhook request schema that looks like this:

[
{
"headers": {
"host": "n8n.blahblah.com",
"content-length": "909",
"accept": "*/*",
"content-type": "application/json",
"x-forwarded-for": "123.123.123.123",
"x-forwarded-host": "n8n.blahblah.com",
"x-forwarded-port": "443",
"x-forwarded-proto": "https",
"x-forwarded-server": "skukhksdjhf3",
"x-real-ip": "123.123.123.123",
"accept-encoding": "gzip"
},
"params": {
},
"query": {
},
"body": {
"webhook_event": "new_email_open",
"email": "[email protected]",
"score": 10,
"first_name": "blah",
"greeting": "blahblahblahblahblahblahblah",
"icebreaker": "blahblahblahblahblahblahblah",
"last_name": "blahblah",
"personalsubject": "So this is a test?",
"title": "Mr.",
"job_title": "blahblah",
"phone": "123123123",
"middle_name": "blah",
"other_email": "blah",
"city": "blah",
"country": "blah",
"region": "blah",
"postal_code": "blah",
"company_name": "blah",
"company_phone": "blah",
"company_domain": "blah",
"company_size": "blah",
"company_industry": "blah",
"company_website": "blahblahblah.com",
"company_address": "blahblahblahblahblahblahblahblahblah",
"company_type": "blah",
"linkedin_url": "blahblahblahblahblahblah.com",
"campaign_name": "blahblahblahblah"
}
}

]

Is there a way to just chuck everything in the body as a parameter to, say, an Airtable node?

Hey @chrisgereina!

Do you want all the incoming data under the Body parameter from the Webhook node to be added to Airtable? For something like this, you can use the Set node to map these values. Checkout the Airtable node documentation to learn more: Airtable | Docs

1 Like

Hi @harshil1712 thanks for your quick response - I ended up solving it with a custom function that works quite well

// Extract body of HTTP request objects
const mappedResponses = items.map(item => item.json.body)

let values = []
for(res of mappedResponses) {
  // Automate n8n "Set" node functionality
  values = values.concat(Object.keys(res).map(function(key, index) {
    // Map to n8n expected structure for values
    return { json: { [key]: res[key] } }
  }))
}

return values;

This basically makes it so that you don’t need to use a Set node to map values from an HTTP response object one by one and instead you can just grab them all and output the same format as if you did it by hand (it also works for an arbitrary amount of requests)

I think it would be good if something like this was a standard transformation node with configurable options, could save a lot of manual work when piping data to a data warehouse

This is the output of the data when you hit the execute node button

[
  {
    "webhook_event": "new_email_open"
  },
  {
    "email": "[email protected]"
  },
  {
    "score": 123
  },
  {
    "first_name": "BLAH"
  },
  {
    "greeting": "BLAH"
  },
  {
    "icebreaker": "BLAH"
  },
  {
    "last_name": "BLAH"
  },
  {
    "personalsubject": "BLAH"
  },
  {
    "title": "BLAH"
  },
  {
    "job_title": "BLAH"
  },
  {
    "phone": "BLAH"
  },
  {
    "middle_name": "BLAH"
  },
  {
    "other_email": "[email protected]"
  },
  {
    "city": "BLAH"
  },
  {
    "country": "BLAH"
  },
  {
    "region": "BLAH"
  },
  {
    "postal_code": "12345"
  },
  {
    "company_name": "BLAH"
  },
  {
    "company_phone": "123456789"
  },
  {
    "company_domain": "https://BLAH.com"
  },
  {
    "company_size": "123"
  },
  {
    "company_industry": "BLAH"
  },
  {
    "company_website": "https://BLAH.com"
  },
  {
    "company_address": "123 FAKE STREET BLAH, BLAH 12345"
  },
  {
    "company_type": "BLAH"
  }
]

I’m not sure if there was a way to achieve the same thing with the Set node on its own already?

Yeah, there is no way to do that with the Set node. I thought (Probably @harshil1712 as well) that you wanted to work with the whole body instead of the individual properties in the body.

With regards to adding this as a native transformation node. We are gathering requirements to develop such a node in n8n.

1 Like

Great! Is there an RFP or something that community members might be able to contribute to?

Update:

The code above ended up achieving something else, this is the code that ended up finally working for the Airtable use case (just in case anyone ends up stumbling on this)

items.map(item => ({ "json": item.json.body }))

Ahhh that why I feared. I did not think you were going to use Airtable since you said: “for example Airtable”. But that you can do with a set node instead of a function node.

Thanks @RicardoE105 how would you accomplish the function just using the Set node?

items.map(item => ({ "json": item.json.body }))

Sadly you cannot do that with the set node.