# getToken

Creates a task and waits for the answer in the same request, up to 50 seconds. If the task is not done by then, the reply is status processing with the taskId; keep checking it with getTaskResult. Result callbacks are not sent for getToken tasks.

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

> Set your HTTP client timeout above 60 seconds for this method.

## Request parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `clientKey` | String | Yes | Your API key, 32 characters, from the account page. |
| `task` | Object | Yes | Task object. Its type field sets which other fields are needed. |
| `softId` | Integer | No | Your application id, saved with the task. appId is accepted as the same field. |

## Request

```json
{
  "clientKey": "YOUR_API_KEY",
  "task": {
    "type": "TurnstileTaskProxyless",
    "websiteURL": "https://example.com/login",
    "websiteKey": "0x4AAAAAAAC3DHQFLr1GavRN"
  }
}
```

## Response

### Solved

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

### Still solving

```json
{
  "errorId": 0,
  "status": "processing",
  "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. |

## Code samples

### cURL

```bash
curl -s https://unlock-api.com/getToken \
  -H "Content-Type: application/json" \
  -d '{"clientKey":"YOUR_API_KEY","task":{"type":"TurnstileTaskProxyless","websiteURL":"https://example.com/login","websiteKey":"0x4AAAAAAAC3DHQFLr1GavRN"}}'
```

### Python

```python
import requests

r = requests.post("https://unlock-api.com/getToken", json={
    "clientKey": "YOUR_API_KEY",
    "task": {
        "type": "TurnstileTaskProxyless",
        "websiteURL": "https://example.com/login",
        "websiteKey": "0x4AAAAAAAC3DHQFLr1GavRN"
    }
}).json()
print(r)
```

### Node.js

```javascript
const r = await fetch("https://unlock-api.com/getToken", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({
    "clientKey": "YOUR_API_KEY",
    "task": {
      "type": "TurnstileTaskProxyless",
      "websiteURL": "https://example.com/login",
      "websiteKey": "0x4AAAAAAAC3DHQFLr1GavRN"
    }
  }),
}).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_ZERO_BALANCE`: The balance does not cover the task. Add funds; nothing was charged.
- `ERROR_NO_SLOT_AVAILABLE`: Too many requests right now, so the task could not be accepted. Try again in a few seconds; nothing was charged.
- `ERROR_TASK_NOT_SUPPORTED`: The task type is unknown or turned off. Check the type name.
- `ERROR_BAD_PARAMETERS`: A required field is missing or has the wrong format.
- `ERROR_PAGEURL`: websiteURL or pageurl is missing or is not a full http(s) address.
- `ERROR_CAPTCHA_UNSOLVABLE`: The task could not be solved in time. Its charge is back on your balance.
