Was this helpful?
How to solve captcha in Postman
Technical engineer
Introduction
Postman is one of the most popular tools for working with APIs. Developers and QA engineers use it every day to send requests, check responses, and automate routine tasks.
But what if the API you are testing is protected by a captcha? Without a valid token or text from an image, the server will simply reject your request. Fortunately, you can solve this right inside Postman using the 2Captcha API.
In this guide, we will show a simple way to solve captchas in Postman without writing complex scripts. You will learn how to create a request collection, solve standard text captchas and recaptcha v2, use the solutions in your main requests, and send feedback reports.
What You Will Need
Before we start, make sure you have the following:
- Postman installed on your computer. You can download it from the official website.
- An account at 2Captcha. Just register on the website.
- Your API key, which you can find in your dashboard after logging in.
- A small balance on your account to pay for the test solutions.
How It Works: The General Idea
Solving a captcha through the API comes down to three simple steps.
Step one is sending the captcha to be solved. You make a POST request to the createTask endpoint and send the captcha image or the recaptcha parameters. In return, you get a taskId, which is a unique identifier for your task.
Step two is waiting for the solution. You make POST requests to the getTaskResult endpoint, passing your taskId. The API replies with the task status. When the status becomes ready, the response will contain the solution.
Step three is using the solution. You take the text or token you received and insert it into your main request to the target website.
In Postman, we will create separate requests for these steps and use environment variables to pass data between them.
Step 1: Setting Up the Postman Environment
Environment variables are a very convenient way to store data that is used across multiple requests. We will use them to store your API key and the captcha solutions.
Creating the Environment
In the top left corner of Postman, click on the Environments section. Click the Add button to create a new environment. Name it something like captcha Solver.
Add the following variables:
| Переменная | Initial Value | Current Value |
|---|---|---|
| api_key | api key | api key |
| task_id | ||
| captcha_solution | ||
| api_hostname | api.2captcha.com | api.2captcha.com |
Click Save to save the environment. In the top right corner of Postman, make sure to select your newly created environment from the dropdown menu.
Now, in all our requests, we can use these variables by wrapping them in double curly braces, like {{api_key}}.
Step 2: Creating a Request Collection
A collection is simply a group of related requests. Let us create a new collection to keep our captcha requests organized.
In the left panel, click on Collections, then Create Collection. Name it captcha Solving. We will add our requests inside this collection.
Step 3: Solving a Text captcha
A text captcha is an image with distorted letters and numbers. To solve it, we use the ImageToTextTask type.
Request 1: Sending the captcha
In your collection, click the plus icon to add a new request. Name it 1. Create Task (Image). Set the method to POST. Enter the URL: https://api.2captcha.com/createTask
Go to the Body tab. Select raw and choose JSON from the dropdown. Paste the following code:
json
{
"clientKey": "{{api_key}}",
"task": {
"type": "ImageToTextTask",
"body": "YOUR_BASE64_IMAGE"
}
}
Important note: in the body field, you need to pass the captcha image in Base64 format. This is a long string of text.
How to get Base64 from an image? You can use any online converter. Just upload your captcha image and copy the result.
Alternatively, if the captcha is loaded on a webpage, you can open the browser console (F12) and run this quick script:
javascript
fetch(document.querySelector('.captcha-image').src)
.then(r => r.blob())
.then(blob => {
const reader = new FileReader();
reader.onload = () => console.log(reader.result.split(',')[1]);
reader.readAsDataURL(blob);
});
Copy the resulting string and paste it into the body field instead of YOUR_BASE64_IMAGE.
Click Send. You will get a response that looks like this:
json
{
"errorId": 0,
"taskId": "1234567890",
"status": "processing"
}
Copy the taskId value and paste it into the task_id variable in your Postman environment.
Request 2: Getting the Result
Create a new request in your collection and name it 2. Get Result. Set the method to POST. The URL is: https://api.2captcha.com/getTaskResult
In the Body tab, select raw and JSON, then paste this:
json
{
"clientKey": "{{api_key}}",
"taskId": "{{task_id}}"
}
Click Send. You will get one of two responses.
If the task is still being solved:
json
{
"errorId": 0,
"status": "processing"
}
Just wait a few seconds and click Send again.
If the task is solved:
json
{
"errorId": 0,
"status": "ready",
"solution": {
"text": "aB3dEf"
},
"cost": "0.0005",
"createTime": 1692808229,
"endTime": 1692808234
}
Copy the value from solution.text (in this example, it is aB3dEf). Paste it into the captcha_solution variable in your environment.
Using the Solution
Now, in your main request to the target website, simply use the {{captcha_solution}} variable:
json
{
"username": "test_user",
"password": "secret",
"captcha": "{{captcha_solution}}"
}
Step 4: Solving recaptcha v2
recaptcha v2 is the familiar checkbox that says I am not a robot. You do not need to download images for this one. You just need to pass the page URL and the sitekey.
How to Find the Sitekey
Open the page with the captcha in your browser. Press F12 and go to the Elements tab. Look for a div with the class g-recaptcha. The value in the data-sitekey attribute is what you need.
Here is an example:
html
<div class="g-recaptcha" data-sitekey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-"></div>
In this case, the sitekey is 6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-.
Request 1: Creating the Task
Create a new request named 1. Create Task (recaptcha v2). Set it to POST. The URL is: https://api.2captcha.com/createTask
In the Body, raw, JSON, paste this:
json
{
"clientKey": "{{api_key}}",
"task": {
"type": "RecaptchaV2TaskProxyless",
"websiteURL": "https://example.com/login",
"websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-"
}
}
Make sure to replace websiteURL with the actual URL of the page with the captcha, and websiteKey with the sitekey you found.
Click Send. Copy the taskId from the response and save it to your task_id environment variable.
Request 2: Getting the Result
Use the exact same 2. Get Result request you created for the text captcha. Just make sure the task_id variable has the new value.
When the status becomes ready, the response will look like this:
json
{
"errorId": 0,
"status": "ready",
"solution": {
"gRecaptchaResponse": "03AGdBq26...long_token_string..."
}
}
Copy the solution.gRecaptchaResponse value and save it to the captcha_solution variable.
Using the Solution
In your request to the target site, pass the token like this:
json
{
"email": "user@example.com",
"password": "secret",
"g-recaptcha-response": "{{captcha_solution}}"
}
Step 5: Sending Feedback Reports
To help 2Captcha improve the quality of solutions, it is important to report the results. If the token worked, send a reportCorrect. If it failed, send reportIncorrect.
Reporting an Incorrect Solution
Create a request named Report Incorrect. Set it to POST. The URL is: https://api.2captcha.com/reportIncorrect
The body is:
json
{
"clientKey": "{{api_key}}",
"taskId": "{{task_id}}"
}
Reporting a Correct Solution
Create a request named Report Correct. Set it to POST. The URL is: https://api.2captcha.com/reportCorrect
The body is exactly the same:
json
{
"clientKey": "{{api_key}}",
"taskId": "{{task_id}}"
}
Just run the appropriate request after you check if your main request to the target site succeeded.
Helpful Tips for Beginners
Keep Things Organized
Group your requests logically. Put the task creation first, then the result polling, then the reports. This makes your workflow much easier to follow.
Check Your Variables
Before sending a request, make sure your environment variables have the correct values. This is especially true for the task_id, which changes every time you solve a new captcha.
Save Your Examples
Create a folder inside your collection called Examples and save working requests there. It will help you remember how everything works if you take a break.
Watch Your Balance
You can check your remaining balance with a simple POST request to https://api.2captcha.com/getBalance, passing only your clientKey in the body.
Do Not Delay
recaptcha tokens usually live for about two minutes. Text captchas expire even faster. As soon as you get a solution, use it in your main request immediately.
Troubleshooting Common Issues
ERROR_WRONG_USER_KEY
This means your API key is incorrect. Check that the api_key variable contains the right key from your 2Captcha dashboard.
ERROR_ZERO_BALANCE
You do not have enough funds. Top up your account balance in the dashboard.
ERROR_captcha_UNSOLVABLE
The captcha is too complex or the parameters are wrong. For text captchas, make sure the image is clear. For recaptcha, double-check that your websiteURL and websiteKey are correct.
The Status Stays on Processing
The task is just taking a little longer. Wait about 5 to 10 seconds and send the Get Result request again. It usually takes up to 20 seconds.
The Target Site Rejects the Solution
There are a few reasons for this. The token might have expired, so use it right away. The URL might be wrong; for recaptcha, the websiteURL must exactly match the page address. Or the site might require a proxy; if it strictly checks IPs, you will need to use the RecaptchaV2Task type with proxy parameters instead of the proxyless version.
Useful Links
- 2Captcha API Documentation: https://2captcha.com/api-docs
- Solving Text captchas: https://2captcha.com/api-docs/normal-captcha
- Solving recaptcha v2: https://2captcha.com/api-docs/recaptcha-v2
- Code Examples on GitHub: https://github.com/2captcha
- Support Center: https://2captcha.com/support/tickets/new
- How to Submit Reports: https://2captcha.com/h/how-to-submit-reports
Conclusion
Solving captchas in Postman is a straightforward process that boils down to three steps: creating a task, getting the result, and using the solution. You do not need to write complex scripts to get started. Understanding basic HTTP requests and environment variables is more than enough.
We covered how to set up your Postman environment, solve text captchas using ImageToTextTask, solve recaptcha v2 using RecaptchaV2TaskProxyless, find the sitekey on a webpage, use the solutions in your main requests, and send feedback reports.
With this basic knowledge, you can test any API protected by captchas. And when you are ready to fully automate the process, you can always look into Pre-request Scripts later on.