Sure.
First of all, I did not explain myself correctly.
The last node does contain the result, but it’s just not output to the webhook response. All I get is
{ "message": "Workflow did execute sucessfully but the last node did not return any data." }
instead of
{ "id": 1, name": "ZXS", ...}
Here’s the non-working version (no Set in the middle):
{
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
250,
300
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "user",
"responseMode": "lastNode",
"options": {}
},
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [
250,
470
],
"notesInFlow": false
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{!!Object.keys($node[\"Get User\"].data).length}}",
"value2": true
}
]
}
},
"name": "IF",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
650,
400
],
"retryOnFail": false
},
{
"parameters": {
"functionCode": "item.error = true;\nitem.message = \"No access\";\nreturn item;"
},
"name": "Response Error",
"type": "n8n-nodes-base.functionItem",
"typeVersion": 1,
"position": [
850,
500
]
},
{
"parameters": {
"functionCode": "items[0].json.id = 1;\nitems[0].json.name = \"ZXS\";\nitems[0].json.secret = \"ABC123\"\n\nvar item = [];\nitem.push({json: {id: items[0].json.id, name: items[0].json.name, secret: items[0].json.secret}});\nreturn item;"
},
"name": "Get User",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
490,
400
]
},
{
"parameters": {
"functionCode": "return items;"
},
"name": "Response OK",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
1060,
330
]
},
{
"parameters": {
"options": {}
},
"name": "Set",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
840,
280
]
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "Get User",
"type": "main",
"index": 0
}
]
]
},
"IF": {
"main": [
[
{
"node": "Response OK",
"type": "main",
"index": 0
}
],
[
{
"node": "Response Error",
"type": "main",
"index": 0
}
]
]
},
"Get User": {
"main": [
[
{
"node": "IF",
"type": "main",
"index": 0
}
]
]
}
}
}
And the working version (with Set):
{
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
250,
300
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "user",
"responseMode": "lastNode",
"options": {}
},
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [
250,
470
],
"notesInFlow": false
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{!!Object.keys($node[\"Get User\"].data).length}}",
"value2": true
}
]
}
},
"name": "IF",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
650,
400
],
"retryOnFail": false
},
{
"parameters": {
"functionCode": "item.error = true;\nitem.message = \"No access\";\nreturn item;"
},
"name": "Response Error",
"type": "n8n-nodes-base.functionItem",
"typeVersion": 1,
"position": [
850,
500
]
},
{
"parameters": {
"functionCode": "items[0].json.id = 1;\nitems[0].json.name = \"ZXS\";\nitems[0].json.secret = \"ABC123\"\n\nvar item = [];\nitem.push({json: {id: items[0].json.id, name: items[0].json.name, secret: items[0].json.secret}});\nreturn item;"
},
"name": "Get User",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
490,
400
]
},
{
"parameters": {
"functionCode": "return items;"
},
"name": "Response OK",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
1060,
330
]
},
{
"parameters": {
"options": {}
},
"name": "Set",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
840,
280
]
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "Get User",
"type": "main",
"index": 0
}
]
]
},
"IF": {
"main": [
[
{
"node": "Set",
"type": "main",
"index": 0
}
],
[
{
"node": "Response Error",
"type": "main",
"index": 0
}
]
]
},
"Get User": {
"main": [
[
{
"node": "IF",
"type": "main",
"index": 0
}
]
]
},
"Set": {
"main": [
[
{
"node": "Response OK",
"type": "main",
"index": 0
}
]
]
}
}
}
I hope this is good example.