Sadly, it’s not possible to set the response code dynamically.
However, you can response with the response code and depending on that, do what it’s needed. Check the example workflow below.
{
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
250,
300
]
},
{
"parameters": {
"functionCode": "if (items[0].json.body.data === 1) {\n return [{ json: { code: 200 } }]\n} else {\n return [{ json: { code: 400 } }]\n}"
},
"name": "Function",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
940,
300
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "f438cd21-c88c-4268-bdc3-5d8aa8904357",
"responseMode": "lastNode",
"options": {}
},
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [
540,
300
],
"webhookId": "f438cd21-c88c-4268-bdc3-5d8aa8904357"
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "Function",
"type": "main",
"index": 0
}
]
]
}
}
}