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

**URL:** <https://discourse.nodered.org/t/kafka-error-argument-must-be-of-type-string-or-instance-of-buffer-ot-arraybuffer/99145>\
**Category:** General\
**Tags:** http-request, function-node, kafka\
**Created:** [23 September 2025 16:41 UTC](https://discourse.nodered.org/t/kafka-error-argument-must-be-of-type-string-or-instance-of-buffer-ot-arraybuffer/99145 "2025-09-23T16:41:09Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrStark](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@mrStark](https://discourse.nodered.org/u/mrStark)\
**Post date:** [23 September 2025 16:41 UTC](https://discourse.nodered.org/t/kafka-error-argument-must-be-of-type-string-or-instance-of-buffer-ot-arraybuffer/99145/1 "2025-09-23T16:41:09Z")

</div>

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?

```auto
{
  "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
}

```

---

<div class="post-metadata">

**Author:** ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)\
**Post date:** [23 September 2025 17:26 UTC](https://discourse.nodered.org/t/kafka-error-argument-must-be-of-type-string-or-instance-of-buffer-ot-arraybuffer/99145/2 "2025-09-23T17:26:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mrStark](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@mrStark](https://discourse.nodered.org/u/mrStark)\
**Post date:** [23 September 2025 17:51 UTC](https://discourse.nodered.org/t/kafka-error-argument-must-be-of-type-string-or-instance-of-buffer-ot-arraybuffer/99145/3 "2025-09-23T17:51:57Z")

</div>

This is it :

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

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 September 2025 18:02 UTC](https://discourse.nodered.org/t/kafka-error-argument-must-be-of-type-string-or-instance-of-buffer-ot-arraybuffer/99145/4 "2025-09-23T18:02:14Z")

</div>

Please identify exactly which kafka node you are using: [list of nodes containing kafkajs](https://flows.nodered.org/search?term=kafkajs)

> [@mrStark](#):
>
> I'm using a json node before sending the data

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)

---

<div class="post-metadata">

**Author:** ![mrStark](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@mrStark](https://discourse.nodered.org/u/mrStark)\
**Post date:** [23 September 2025 18:13 UTC](https://discourse.nodered.org/t/kafka-error-argument-must-be-of-type-string-or-instance-of-buffer-ot-arraybuffer/99145/5 "2025-09-23T18:13:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 September 2025 18:18 UTC](https://discourse.nodered.org/t/kafka-error-argument-must-be-of-type-string-or-instance-of-buffer-ot-arraybuffer/99145/6 "2025-09-23T18:18:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mrStark](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@mrStark](https://discourse.nodered.org/u/mrStark)\
**Post date:** [23 September 2025 18:39 UTC](https://discourse.nodered.org/t/kafka-error-argument-must-be-of-type-string-or-instance-of-buffer-ot-arraybuffer/99145/7 "2025-09-23T18:39:27Z")

</div>

This is a flow snippet :

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/3/032d3a5574bf030d02002ff6274eb608b6224445.png)

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/67e70dd7deca8b703886a728951e1655acfd76c5.png)

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

```auto
{"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"}

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 September 2025 18:44 UTC](https://discourse.nodered.org/t/kafka-error-argument-must-be-of-type-string-or-instance-of-buffer-ot-arraybuffer/99145/8 "2025-09-23T18:44:19Z")

</div>

> [@mrStark](#):
>
> This is the output i'm getting from json node (debug 22)

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

> [@Steve-Mcl](#):
>
> Please verify by way of debug nodes what goes into the kafka node. Screenshot it (you can sanitise/blur out sensitive parts)

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

Again a screenshot would help.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [23 September 2025 18:56 UTC](https://discourse.nodered.org/t/kafka-error-argument-must-be-of-type-string-or-instance-of-buffer-ot-arraybuffer/99145/9 "2025-09-23T18:56:00Z")

</div>

> [@mrStark](#):
>
> `argument must be of type string or an instance of Buffer or ArrayBuffer. Received an instance of Array`

Isn't this the issue ?

---

<div class="post-metadata">

**Author:** ![mrStark](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@mrStark](https://discourse.nodered.org/u/mrStark)\
**Post date:** [23 September 2025 19:00 UTC](https://discourse.nodered.org/t/kafka-error-argument-must-be-of-type-string-or-instance-of-buffer-ot-arraybuffer/99145/10 "2025-09-23T19:00:23Z")

</div>

yes the json data directly goes to the kafka node :

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/9/594a90f3a814b333388092ef6b720c7824bc6f67.png)

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/c/bccc37db1758de6c6535bd2f6d264cde0d565fe2.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 September 2025 20:34 UTC](https://discourse.nodered.org/t/kafka-error-argument-must-be-of-type-string-or-instance-of-buffer-ot-arraybuffer/99145/11 "2025-09-23T20:34:37Z")

</div>

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](https://github.com/oriolrius/node-red-contrib-kafka/blob/main/js/kafka-producer.js#L251) - 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](https://github.com/oriolrius/node-red-contrib-kafka/blob/main/js/utils.js#L24) which is called like so: input `msg` -\> [get message values](https://github.com/oriolrius/node-red-contrib-kafka/blob/main/js/kafka-producer.js#L298) -\> [getMsgValues](https://github.com/oriolrius/node-red-contrib-kafka/blob/main/js/utils.js#L48) -\> [genRecord](https://github.com/oriolrius/node-red-contrib-kafka/blob/main/js/utils.js#L24C41-L24C45) (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](https://github.com/oriolrius/node-red-contrib-kafka/issues)

---

<div class="post-metadata">

**Author:** ![mrStark](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@mrStark](https://discourse.nodered.org/u/mrStark)\
**Post date:** [24 September 2025 05:53 UTC](https://discourse.nodered.org/t/kafka-error-argument-must-be-of-type-string-or-instance-of-buffer-ot-arraybuffer/99145/12 "2025-09-24T05:53:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mrStark](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@mrStark](https://discourse.nodered.org/u/mrStark)\
**Post date:** [24 September 2025 08:38 UTC](https://discourse.nodered.org/t/kafka-error-argument-must-be-of-type-string-or-instance-of-buffer-ot-arraybuffer/99145/13 "2025-09-24T08:38:09Z")

</div>

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:

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

```

The other nodes kept as it is.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [8 October 2025 08:39 UTC](https://discourse.nodered.org/t/kafka-error-argument-must-be-of-type-string-or-instance-of-buffer-ot-arraybuffer/99145/14 "2025-10-08T08:39:06Z")

</div>

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