Kafka Error "argument must be of type string or instance of Buffer ot ArrayBuffer"

I'm getting below error when i'm passing some payload to the kafkajs node. I'm using a json node before sending the data to the kafkajs node but still getting the error. Can anyone help here?

{
  "level":"ERROR",
  "timestamp":"2025-09-23T14:29:37.134Z",
  "logger":"kafkajs",
  "message":"[Producer] The \"string\" argument must be of type string or an instance of Buffer or ArrayBuffer. Received an instance of Array",
  "retryCount":0,
  "retryTime":314
}

Can you attach a debug node (set it to complete message mode) to what ever is feeding the kafka node and share the output.

This is it :

{
	"ID": "xyz",
	"Name": "_CV",
	"MyType": "String",
	"Value": {
		"Status": 200,
		"Headers": {
			"Content-Type": "application/json; charset=utf-8"
		},
		"Content": {
			"Items": []
		}
	}
}

Please identify exactly which kafka node you are using: list of nodes containing kafkajs

Is that to convert to an object or to convert to a string (i.e. what goes into the JSON node and what comes out of it? - show us before and after payloads)

I'm using node-red-contrib-kafkajs,

Basically the flow is like this:

Function node (forwards array of items) -> split node (separating each payload from the array ) -> json node (to change it from array to json: here the msg.paylaod looks like above) -> kafkajs (here i'm getting the error)

Unfortunately i cannot share the complete msg due to some restriction, should i share any specific part out of it?

It is unclear to me what is happening.

You say "Function node (forwards array of items) -> split node (separating each payload from the array ) ->" then you say "json node (to change it from array to json" - so is the original data an array of arrays?

Please verify by way of debug nodes what goes into the kafka node. Screenshot it (you can sanitise/blur out sensitive parts)

A screenshot of your flow (with annotations) would be handy too.

This is a flow snippet :

This is the output i'm getting from function node (debug mapme)

This is the output i'm getting from json node (debug 22) and i'm passing msg.paylod outof it to the kafkajs

{"currenttime":1758650522124,"filename":"/test/lastrun.csv","payload":"{"ID": "xyz","Name": "_CV","MyType": "String","Value": {"Status": 200,"Headers": {"Content-Type": "application/json;charset=utf-8"},"Content": {"Items": []}}}","statusCode":207,"headers":{"transfer-encoding":"chunked","content-type":"application/json","server":"Microsoft-HTTPAPI/2.0","x-frame-options":"SAMEORIGIN","content-security-policy":"default-src 'self'; object-src 'none'","x-content-type-options":"nosniff","strict-transport-security":"max-age=86400","date":"Tue, 23 Sep 2025 18:02:02 GMT","connection":"close","set-cookie":["xyz.com_tcp_443_pool=1937919754.47873.0000; path=/; Httponly; Secure"],"x-node-red-request-node":"b1e31acc"},"responseUrl":"https:xyz.com","redirectList":[],"retry":0,"responseCookies":{"xyz_tcp_443_pool":{"path":"/","value":"1937919754.47873.0000"}},"parts":{"id":"15d94c3b98c3957c","type":"array","count":14475,"len":1,"index":14474},"_msgid":"acccb3f3415eac10"}

That data is neither valid JSON nor Object e.g.

"payload":"{"ID": "xyz","Name": "_CV","M

^ not valid JSON - difficult to tell what is actually coming out of JSON node from the text

Can you please do a screenshot of what comes out of the debug node

Assuming it IS a string, does that feed directly into the kafka node?

Again a screenshot would help.

Isn't this the issue ?

yes the json data directly goes to the kafka node :

Out of below complete msg, msg.payload goes to the kafka node directly

Ok, so you are definitely sending a string payload.

A quick browse of the nodes source code suggests to me if you are using schema validation (useSchemaValidation is true) the string payload WILL get parsed to an object see here - all good!

However, the logic flow suggests that when not using schema validation that the payload should be an object as required by this line of code which is called like so: input msg -> get message values -> getMsgValues -> genRecord (see how it access a sub property from the data as if it were an object?).

If you remove the JSON node, what happens?

If that doesnt work, then I suggest you raise an issue on the repository here: GitHub · Where software is built

Sure, I'll check it then. Thank you!

I got the solution, actually there was some issue with the split node so instead of using that i wrote a function with same functionality and its working for me.

Just used this function instead of in built split node:

let arr = msg.payload;
let msgs = arr.map(item => {
    return {payload: item};
});
return [msgs];

The other nodes kept as it is.

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