he "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type object


New member
I have been trying to send this request through the 2captcha API, but the issue is everytime I send it VIA code it gives me the error: [ERR_INVALID_ARG_TYPE]: The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type object

Any help would be greatly apricated, I keep trying diffrent things but can't seem to get this request to send.
var FormData = require('form-data');
var fs = require('fs');
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

const data = new FormData();
data.append("key", "96000001977a12e50ca4eb45f104fe1");
data.append("file", "file");
data.append("submit", "00000W0UAAAAAA-ouoKHOnWuQDNymSwDFYeGP300");

const xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {

xhr.open("POST", "http://2captcha.com/in.php?key=962800000a12e50ca4eb45f104fe1&method=userrecaptcha&googlekey=000000UAAAAAA-ouoKHOnWuQDNymSwDFYeG00000&pageurl=https://www.google.com/recaptcha/api2/demo");
xhr.send(data); //problem area


New member
It looks like the particular XMLHttpRequest library you're using does not support the FormData object. See this bug report. In general, it looks like this library hasn't been updated in a while. If it's not too difficult (I don't know how deeply rooted this old library is within your project) but I would recommend switching to a more modern solution, like node-fetch, which uses the newer, easier to use fetch API. This node-fetch package would provide that support for node.

One solution to fix your current problem is to use URLSearchParams which will let you encode data in the same format that you need, shares a similar API to FormData, but also has a toString function. Your error message says that this library supports strings, so you can just pass in a stringified value.

const data = new URLSearchParams();
data.append("key", "xxx");
data.append("file", "file");
data.append("submit", "yyy");