# getTaskResult

Returns the state of a task. While it is being solved, status is processing. When it is done, status is ready and solution holds the answer. A failed task returns errorId 1 with the reason, and its charge is already back on the balance.

`POST https://unlock-api.com/getTaskResult`

> Wait about 5 seconds after creating the task, then check every 5 seconds. A task not solved within 5 minutes fails with ERROR_CAPTCHA_UNSOLVABLE.

## Request parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `clientKey` | String | Yes | Your API key, 32 characters, from the account page. |
| `taskId` | Integer | Yes | The id returned by createTask. |

## Request

```json
{
  "clientKey": "YOUR_API_KEY",
  "taskId": 1001
}
```

## Response

### Still solving

```json
{
  "errorId": 0,
  "status": "processing",
  "taskId": 1001
}
```

### Solved

```json
{
  "errorId": 0,
  "taskId": 1001,
  "status": "ready",
  "solution": {
    "token": "0.zrSnRHO7h0HwSjSCU8oyzbjEtD8p..."
  },
  "cost": "0.00055",
  "createTime": 1791640000,
  "endTime": 1791640011,
  "solveCount": 1
}
```

### Failed

```json
{
  "errorId": 1,
  "errorCode": "ERROR_CAPTCHA_UNSOLVABLE",
  "errorDescription": "The task could not be solved. Its cost was returned to your balance.",
  "taskId": 1001
}
```

## Response fields

| Name | Type | Description |
|---|---|---|
| `errorId` | Integer | 0 when the request worked, 1 when it did not. |
| `taskId` | Integer | Task id. |
| `status` | String | processing while the task is being solved, ready when it is done. |
| `solution` | Object | The answer. Its fields depend on the task type. |
| `cost` | String | Price of this task in US dollars. |
| `createTime` | Integer | Unix time when the task was created. |
| `endTime` | Integer | Unix time when the task was solved. |
| `solveCount` | Integer | How many times the task was solved. Always 1. |
| `errorCode` | String | Error name when errorId is 1. |
| `errorDescription` | String | Short explanation of the error in English. |

## Code samples

### cURL

```bash
curl -s https://unlock-api.com/getTaskResult \
  -H "Content-Type: application/json" \
  -d '{"clientKey":"YOUR_API_KEY","taskId":1001}'
```

### Python

```python
import requests

r = requests.post("https://unlock-api.com/getTaskResult", json={
    "clientKey": "YOUR_API_KEY",
    "taskId": 1001
}).json()
print(r)
```

### Node.js

```javascript
const r = await fetch("https://unlock-api.com/getTaskResult", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({
    "clientKey": "YOUR_API_KEY",
    "taskId": 1001
  }),
}).then((res) => res.json());
console.log(r);
```

## Errors this method can return

- `ERROR_KEY_DOES_NOT_EXIST`: The key is wrong. Copy it again from the account page. (in.php and res.php: ERROR_WRONG_USER_KEY)
- `ERROR_IP_NOT_ALLOWED`: The request came from an IP that is not on the account's allow list. Add the IP on the account page.
- `ERROR_IP_BANNED`: This account is blocked. Contact support from the account page.
- `ERROR_TOO_MANY_REQUESTS`: Too many requests. Slow down result checks to every 5 seconds.
- `ERROR_WRONG_CAPTCHA_ID`: There is no task with this id on your account.
- `ERROR_CAPTCHA_UNSOLVABLE`: The task could not be solved in time. Its charge is back on your balance.
