Class: TwoCaptchaClient

TwoCaptchaClient(key, paramsopt) → {TwoCaptchaClient}

new TwoCaptchaClient(key, paramsopt) → {TwoCaptchaClient}

Constructor for the 2Captcha client object
Parameters:
Name Type Attributes Description
key string Your 2Captcha API key
params Object <optional>
Params for the client
Properties
Name Type Attributes Description
timeout number <optional>
milliseconds before giving up on an captcha
polling number <optional>
milliseconds between polling for answer
throwErrors Boolean <optional>
Whether the client should throw errors or just log the errors
Source:
Returns:
The client object
Type
TwoCaptchaClient

Methods

(async) _loadCaptcha(options) → {Promise.<string>}

Loads a captcha image and converts to base64
Parameters:
Name Type Description
options Object The source of the image
Properties
Name Type Attributes Description
base64 string <optional>
An already base64-coded image
buffer Buffer <optional>
A buffer object of a binary image
path string <optional>
The path for a system-stored image
url string <optional>
Url for a web-located image
Source:
Returns:
Promise for a base64 string representation of an image
Type
Promise.<string>

(async) _request(action, method, payload) → {Promise.<string>}

Makes a HTTP request for the 2Captcha API
Parameters:
Name Type Default Description
action string Path used in the 2Captcha api URL
method string get HTTP verb to be used
payload string Body of the requisition
Source:
Returns:
Promise for the response body
Type
Promise.<string>

(async) _sleep(ms) → {Promise.<undefined>}

Blocks the code for the specified amount of time
Parameters:
Name Type Description
ms number The time in milliseconds to block the code
Source:
Returns:
Promise for undefined that resolves after ms milliseconds
Type
Promise.<undefined>

_throwError(message) → {undefined|Boolean}

Throws an Error if this.throwErrors is true. If this.throwErrors is false, a warn is logged in the console.
Parameters:
Name Type Description
message string Message of the error
Source:
Returns:
If an error wasn't thrown, returns false.
Type
undefined | Boolean

(async) _upload(options) → {Promise.<Captcha>}

Uploads a captcha for the 2Captcha API
Parameters:
Name Type Description
options Object Parametes for the controlling the requistion
Properties
Name Type Description
base64 string The base64 encoded image
method string 2Captcha method of image sending. Can be either base64 or multipart
Source:
Returns:
Promise for Captcha object containing the captcha ID
Type
Promise.<Captcha>

_validateResponse(body) → {undefined|Boolean}

Checks if the response from 2Captcha is an Error. It may throw an error if the class parameter throwExceptions is true. If it is false, only a warning will be logged.
Parameters:
Name Type Description
body string Body from the 2Captcha response
Source:
Returns:
Returns true if response is valid
Type
undefined | Boolean

(async) balance() → {Promise.<float>}

Get balance from your account
Source:
Returns:
Account balance in USD
Type
Promise.<float>

(async) captcha(captchaId) → {Promis.<Captcha>}

Gets the response from a solved captcha
Parameters:
Name Type Description
captchaId string The id of the desired captcha
Source:
Returns:
A promise for the captcha
Type
Promis.<Captcha>

(async) decode(options) → {Promise.<Captcha>}

Sends an image captcha and polls for its response
Parameters:
Name Type Description
options Object Parameters for the requests
Properties
Name Type Attributes Description
base64 string <optional>
An already base64-coded image
buffer Buffer <optional>
A buffer object of a binary image
path string <optional>
The path for a system-stored image
url string <optional>
Url for a web-located image
method string <optional>
2Captcha method of image sending. Can be either base64 or multipart
Source:
Returns:
Promise for a Captcha object
Type
Promise.<Captcha>

(async) decodeHCaptcha(options) → {Promise.<Captcha>}

Sends a hCaptcha and polls for its response
Parameters:
Name Type Description
options Object Parameters for the request
Properties
Name Type Description
sitekey string The site key of the hCaptcha
pageurl string The URL where the hCaptcha is
invisible boolean Invisible hCaptcha
Source:
Returns:
Promise for a Captcha object
Type
Promise.<Captcha>

(async) decodeRecaptchaV2(options) → {Promise.<Captcha>}

Sends a ReCaptcha v2 and polls for its response
Parameters:
Name Type Description
options Object Parameters for the request
Properties
Name Type Description
googlekey string The google key from the ReCaptcha
pageurl string The URL where the ReCaptcha is
invisible boolean Invisible ReCaptcha switch
enterprise boolean Enterprise ReCaptcha switch
Source:
Returns:
Promise for a Captcha object
Type
Promise.<Captcha>

(async) decodeRecaptchaV3(options) → {Promise.<Captcha>}

Sends a ReCaptcha v3 and polls for its response
Parameters:
Name Type Description
options Object Parameters for the request
Properties
Name Type Description
googlekey string The google key from the ReCaptcha
pageurl string The URL where the ReCaptcha is
action string Action value for ReCaptcha
enterprise boolean Enterprise ReCaptcha switch
Source:
Returns:
Promise for a Captcha object
Type
Promise.<Captcha>

(async) load() → {Promise.<string>}

Deprecated:
  • /load.php route is returning error 500 Get current load from 2Captcha service
Source:
Returns:
Promise for an XML containing current load from 2Captcha service
Type
Promise.<string>

(async) report(captchaId, bad) → {Promise.<Boolean>}

Report incorrectly solved captcha for refund
Parameters:
Name Type Default Description
captchaId string The id of the incorrectly solved captcha
bad boolean true If reporting an incorrectly solved captcha. Default is true.
Source:
Returns:
Promise for a boolean informing if the report was received
Type
Promise.<Boolean>

(async) stats(date) → {Promise.<string>}

Get usage statistics from your account
Parameters:
Name Type Description
date Date Date for the target day
Source:
Returns:
Promise for an XML containing statistics about target day
Type
Promise.<string>