Klaviyo API Request Works but N8N Node Errors Out

So, I am using the hosted version of N8N and have a very frustrating issue.

I am attempting to post email templates to Klaviyo via the API. I am using the HTTP Request node to do this, and have all settings/auth setup correctly.

I am using JSON body setup like so, using expression:

This is the expression:

{
“data”: {
“type”: “template”,
“attributes”: {
“name”: “{{ $json[‘finalCampaignData.emails’].subject_line }}”,
“editor_type”: “CODE”,
“html”: {{ JSON.stringify($json[‘finalCampaignData.emails’].html_content) }}
}
}
}

This is working, as the email templates get added correctly to Klaviyo, so what I am sending is correct. But, the flow breaks because N8N errors out with this:

NodeOperationError: JSON parameter needs to be valid JSON at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/HttpRequest/V3/HttpRequestV3.node.js:256:23) at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:681:27) at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:915:51 at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:1246:20

This is so frustrating, as I cannot figure out what the issue is? I mean, it works, so not sure why N8N is erroring here? Is this a bug, or am I being really stupid and doing something wrong?

maybe try this one?

{
	"data": {
		"type": "template",
		"attributes": {
			"name": {{ $json.finalCampaignData.emails.subject_line.toJsonString() }},
			"editor_type": "CODE",
			"html": {{ $json.finalCampaignData.emails.html_content.toJsonString() }}
		}
	}
}

And make sure all the expression has value.

Hi,

I have figured the issue out. This actually had nothing to do with the JSON code itself it turns out.

For anyone else reading this, JSON.stringify is your friend with JSON data, and I do in fact stringify the data I want to send to the API before the HTTP request to keep things clean.

The issue wasn’t this though, it was the fact I had a merge node that outputted 3 items before the API request. 2 of those items had all of the required data, but the 3rd item (which wasn’t needed) didn’t. So, of course N8N HTTP request node ran all 3, which caused an error on the 3rd item.

Everything else was good to go.

So, for anyone reading that is still having an issue with this error, and you have done everything mentioned with no luck, double check your inputs.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.