Issue preparing json payload in HTTP Request node

Hi,

So, i’m trying to form a json payload int the HTTP Request node using information from a previous node like below

You can see that even though the value is picked properly, the HTTP Request node complains that it is not a valid JSON.

Because of this, i’m having to add a function node in front of every HTTP Request node where I need to form a payload similar to above.

and I put the exact same thing in function node i.e., payload formation just like above and when I read this data from function node inside HTTP request node, it doesn’t complain anymore.

Can you guys tell me if i’m doing something wrong here?

Just trying to reduce the number of nodes.

Edit: Adding image of configuration in my HTTP Request Node

Also, when I follow the error message and set the body content-type to “RAW/Custom”, it throws a different error, something like “cannot read accept on string”

Hey @need4eat,

Can you share the workflow, or another URL that I can use to replicate the issue? Can you also share the output of the Function node, and the result in the expression editor of the body when you don’t use the Function node?

Hi @harshil1712, sorry for the delay, you can find the details below

below is the output of the function node


[
{
"name": "Luke Skywalker",
"height": "172",
"mass": "77",
"hair_color": "blond",
"skin_color": "fair",
"eye_color": "blue",
"birth_year": "19BBY",
"gender": "male",
"homeworld": "https://swapi.dev/api/planets/1/",
"films": [
"https://swapi.dev/api/films/1/",
"https://swapi.dev/api/films/2/",
"https://swapi.dev/api/films/3/",
"https://swapi.dev/api/films/6/"
],
"species": [
],
"vehicles": [
"https://swapi.dev/api/vehicles/14/",
"https://swapi.dev/api/vehicles/30/"
],
"starships": [
"https://swapi.dev/api/starships/12/",
"https://swapi.dev/api/starships/22/"
],
"created": "2014-12-09T13:50:51.644000Z",
"edited": "2014-12-20T21:17:56.891000Z",
"url": "https://swapi.dev/api/people/1/",
"sample": {
"id": "0001",
"type": "donut",
"name": "Cake",
"resp": {
"name": "Luke Skywalker",
"height": "172",
"mass": "77",
"hair_color": "blond",
"skin_color": "fair",
"eye_color": "blue",
"birth_year": "19BBY",
"gender": "male",
"homeworld": "https://swapi.dev/api/planets/1/",
"films": [
"https://swapi.dev/api/films/1/",
"https://swapi.dev/api/films/2/",
"https://swapi.dev/api/films/3/",
"https://swapi.dev/api/films/6/"
],
"species": [
],
"vehicles": [
"https://swapi.dev/api/vehicles/14/",
"https://swapi.dev/api/vehicles/30/"
],
"starships": [
"https://swapi.dev/api/starships/12/",
"https://swapi.dev/api/starships/22/"
],
"created": "2014-12-09T13:50:51.644000Z",
"edited": "2014-12-20T21:17:56.891000Z",
"url": "https://swapi.dev/api/people/1/"
},
"ppu": 0.55,
"batters": {
"batter": [
{
"id": "1001",
"type": "Regular"
},
{
"id": "1002",
"type": "Chocolate"
},
{
"id": "1003",
"type": "Blueberry"
},
{
"id": "1004",
"type": "Devil's Food"
}
]
},
"topping": [
{
"id": "5001",
"type": "None"
},
{
"id": "5002",
"type": "Glazed"
},
{
"id": "5005",
"type": "Sugar"
},
{
"id": "5007",
"type": "Powdered Sugar"
},
{
"id": "5006",
"type": "Chocolate with Sprinkles"
},
{
"id": "5003",
"type": "Chocolate"
},
{
"id": "5004",
"type": "Maple"
}
]
}
}
] 

and result in expression editor of the body when I don’t use the function node

{
	"id": "0001",
	"type": "donut",
	"name": "Cake",
"resp": [Object: {"name":"Luke Skywalker","height":"172","mass":"77","hair_color":"blond","skin_color":"fair","eye_color":"blue","birth_year":"19BBY","gender":"male","homeworld":"https://swapi.dev/api/planets/1/","films":["https://swapi.dev/api/films/1/","https://swapi.dev/api/films/2/","https://swapi.dev/api/films/3/","https://swapi.dev/api/films/6/"],"species":[],"vehicles":["https://swapi.dev/api/vehicles/14/","https://swapi.dev/api/vehicles/30/"],"starships":["https://swapi.dev/api/starships/12/","https://swapi.dev/api/starships/22/"],"created":"2014-12-09T13:50:51.644000Z","edited":"2014-12-20T21:17:56.891000Z","url":"https://swapi.dev/api/people/1/"}],
	"ppu": 0.55,
	"batters":
		{
			"batter":
				[
					{ "id": "1001", "type": "Regular" },
					{ "id": "1002", "type": "Chocolate" },
					{ "id": "1003", "type": "Blueberry" },
					{ "id": "1004", "type": "Devil's Food" }
				]
		},
	"topping":
		[
			{ "id": "5001", "type": "None" },
			{ "id": "5002", "type": "Glazed" },
			{ "id": "5005", "type": "Sugar" },
			{ "id": "5007", "type": "Powdered Sugar" },
			{ "id": "5006", "type": "Chocolate with Sprinkles" },
			{ "id": "5003", "type": "Chocolate" },
			{ "id": "5004", "type": "Maple" }
		]
}

you can see above the HTTP Request node when routed / payload formed in function node, goes through fine… but when I directly form the payload in ‘HTTP Request1’, it fails…

I can see it adds something like [Object: {}] in the payload. I should be able to stitch things directly in the HTTP Request node too right?

I think I figured out the solution myself…

doing a JSON.stringify($json) removed the Object[{}] part and now it doesn’t complain about the json not being valid.

Request goes through fine without function node too…

Thanks @harshil1712

2 Likes

Perfect! I was just going to share the same solution. I am glad you found it!

Have fun :tada:

1 Like