ERROR: A valid JSON must be provided

Describe the issue/error/question

I’m following this tutorial from appsmith that includes a part in n8n

I’m using this code in the JSON properties:

{         "items": {{(JSON.stringify($node["Webhook"].json["body"]["items"]))}} }

And this is the JSON that is passing from the webhook node to the APItemplate node

[
{
"headers": {
"x-real-ip": "18.223.74.85",
"x-forwarded-for": "18.223.74.85",
"host": "elhtuonamumm8b0jewywvmk2.hooks.n8n.cloud",
"x-forwarded-proto": "https",
"x-nginx-proxy": "true",
"connection": "close",
"content-length": "2877",
"user-agent": "ReactorNetty/1.0.15",
"accept": "*/*",
"content-type": "application/json"
},
"params": {
},
"query": {
},
"body": {
"items": [
{
"image": "https://randomuser.me/api/portraits/med/women/6.jpg",
"country": "Netherlands",
"dgf": null,
"ttoto": null,
"gender": "male",
"phone": "(456)-174-6938",
"dob": "1987-04-23T20:44:58.921Z",
"latitude": "42.9756",
"name": "Alies",
"id": 2,
"email": "[email protected]",
"longitude": "105.8589"
},
{
"image": "https://randomuser.me/api/portraits/med/women/88.jpg",
"country": "Norway",
"dgf": null,
"ttoto": null,
"gender": "female",
"phone": "29700140",
"dob": "1980-05-14T12:00:46.973Z",
"latitude": "-14.0884",
"name": "Sofia",
"id": 3,
"email": "[email protected]",
"longitude": "27.0428"
},
{
"image": "https://randomuser.me/api/portraits/med/men/52.jpg",
"country": "Canada",
"dgf": null,
"ttoto": null,
"gender": "male",
"phone": "594-620-3202",
"dob": "1984-02-25T07:31:12.723Z",
"latitude": "-88.0169",
"name": "Jack",
"id": 4,
"email": "[email protected]",
"longitude": "-118.7708"
},
{
"image": "https://randomuser.me/api/portraits/med/women/91.jpg",
"country": "United Kingdom",
"dgf": null,
"ttoto": null,
"gender": "female",
"phone": "016973 12222",
"dob": "1995-11-22T02:25:20.419Z",
"latitude": "73.6320",
"name": "Caroline Daniels",
"id": 5,
"email": "[email protected]",
"longitude": "-167.3976"
},
{
"image": "https://randomuser.me/api/portraits/med/men/58.jpg",
"country": "Norway",
"dgf": null,
"ttoto": null,
"gender": "male",
"phone": "61521059",
"dob": "1959-02-20T02:42:20.579Z",
"latitude": "86.1891",
"name": "Mohamad Persson",
"id": 6,
"email": "[email protected]",
"longitude": "-56.8442"
},
{
"image": "https://randomuser.me/api/portraits/med/men/30.jpg",
"country": "Norway",
"dgf": null,
"ttoto": null,
"gender": "male",
"phone": "33668847",
"dob": "1952-02-05T07:30:11.466Z",
"latitude": "4.5623",
"name": "John Haugsvær",
"id": 9,
"email": "[email protected]",
"longitude": "9.0901"
},
{
"image": "https://randomuser.me/api/portraits/med/men/73.jpg",
"country": "Canada",
"dgf": null,
"ttoto": null,
"gender": "male",
"phone": "212-355-8035",
"dob": "1977-03-27T02:12:01.151Z",
"latitude": "-49.4156",
"name": "David Mackay",
"id": 10,
"email": "[email protected]",
"longitude": "-132.3755"
},
{
"image": "https://randomuser.me/api/portraits/med/men/26.jpg",
"country": "Norway",
"dgf": null,
"ttoto": null,
"gender": "male",
"phone": "59232739",
"dob": "1995-03-14T15:34:26.913Z",
"latitude": "16.7320",
"name": "Johan Kaupang",
"id": 11,
"email": "[email protected]",
"longitude": "-92.4578"
},
{
"image": "https://randomuser.me/api/portraits/med/men/32.jpg",
"country": "Australia",
"dgf": null,
"ttoto": null,
"gender": "male",
"phone": "03-9225-6031",
"dob": "1992-07-04T16:08:07.804Z",
"latitude": "-4.8661",
"name": "Logan Newman",
"id": 12,
"email": "[email protected]",
"longitude": "179.0295"
},
{
"image": "https://randomuser.me/api/portraits/med/women/77.jpg",
"country": "Australia",
"dgf": null,
"ttoto": null,
"gender": "female",
"phone": "05-9569-7428",
"dob": "1974-09-20T22:40:48.642Z",
"latitude": "26.3703",
"name": "Heather Diaz",
"id": 13,
"email": "[email protected]",
"longitude": "6.4839"
}
]
}
}
]

What is the error message (if any)?

Please share the workflow

(Select the nodes and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow respectively)

{
“nodes”: [
{
“parameters”: {},
“name”: “Start”,
“type”: “n8n-nodes-base.start”,
“typeVersion”: 1,
“position”: [
240,
300
]
},
{
“parameters”: {
“httpMethod”: “POST”,
“path”: “e52a0fd8-1330-4d11-93b3-969a1be14b33”,
“responseMode”: “responseNode”,
“options”: {}
},
“name”: “Webhook”,
“type”: “n8n-nodes-base.webhook”,
“typeVersion”: 1,
“position”: [
460,
300
],
“webhookId”: “e52a0fd8-1330-4d11-93b3-969a1be14b33”
},
{
“parameters”: {
“resource”: “pdf”,
“pdfTemplateId”: “33977b2b29de3a86”,
“jsonParameters”: true,
“propertiesJson”: “{ “items”: {{(JSON.stringify($node[“Webhook”].json[“body”][“items”]))}} }”
},
“name”: “APITemplate.io”,
“type”: “n8n-nodes-base.apiTemplateIo”,
“typeVersion”: 1,
“position”: [
680,
300
],
“alwaysOutputData”: false,
“credentials”: {
“apiTemplateIoApi”: {
“id”: “1”,
“name”: “APITemplate.io account”
}
}
},
{
“parameters”: {
“options”: {}
},
“name”: “Respond to Webhook”,
“type”: “n8n-nodes-base.respondToWebhook”,
“typeVersion”: 1,
“position”: [
900,
300
]
}
],
“connections”: {
“Webhook”: {
“main”: [
[
{
“node”: “APITemplate.io”,
“type”: “main”,
“index”: 0
}
]
]
},
APITemplate.io”: {
“main”: [
[
{
“node”: “Respond to Webhook”,
“type”: “main”,
“index”: 0
}
]
]
}
}
}

Share the output returned by the last node

NodeOperationError: A valid JSON must be provided.
    at Object.execute (C:\Users\Administrator\AppData\Local\Programs\n8n\resources\app\node_modules\n8n-nodes-base\dist\nodes\ApiTemplateIo\ApiTemplateIo.node.js:494:39)
    at Workflow.runNode (C:\Users\Administrator\AppData\Local\Programs\n8n\resources\app\node_modules\n8n-workflow\dist\src\Workflow.js:526:37)
    at C:\Users\Administrator\AppData\Local\Programs\n8n\resources\app\node_modules\n8n-core\dist\src\WorkflowExecute.js:451:62

Information on your n8n setup

  • n8n version:
  • Database you’re using (default: PostgreSQL):
  • Running n8n with the execution process [own(default), main]:
  • Running n8n via [desktop app]:

Hey @rodmontgt, welcome to the community!

I am sorry to hear you’re having trouble here. From the looks of it you are trying to use an expression but are sending plain text instead. Can you try converting your text into an expression like so?

Afterwards, the APITemplate.io node should no longer send over gibberish but the JSON data coming from your webhook node :slight_smile:

2 Likes

Thanks a lot @MutedJam You rocks! :muscle: It worked as expected, I was struggling with this part for an entire day but I didn’t found this in the docs or maybe I missed it.

1 Like

Glad to hear this helped, thanks for confirming!

Expressions would be explained in more detail here btw if you want to read more about them.