UNLOCK API
createTask

createTask

Creates a task and returns its id. The price of the task type is taken from the balance when the task is accepted, and returned if the task fails.
POSThttps://unlock-api.com/createTask
Send POST with Content-Type: application/json. The task fields depend on the task type; see Task types.

Request parameters

clientKey
StringRequired
Your API key, 32 characters, from the account page.
task
ObjectRequired
Task object. Its type field sets which other fields are needed. Task types
callbackUrl
StringOptional
Public http(s) address. When the task is done or failed, the result is sent there by POST as JSON.
softId
IntegerOptional
Your application id, saved with the task. appId is accepted as the same field.

Request

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

Response

{
  "errorId": 0,
  "taskId": 1001
}

Response fields

errorId
Integer
0 when the request worked, 1 when it did not.
taskId
Integer
Task id.
errorCode
String
Error name when errorId is 1.
errorDescription
String
Short explanation of the error in English.

Code samples

import time, requests

API = "https://unlock-api.com"
KEY = "YOUR_API_KEY"

task = requests.post(f"{API}/createTask", json={
    "clientKey": KEY,
    "task": {
      "type": "TurnstileTaskProxyless",
      "websiteURL": "https://example.com/login",
      "websiteKey": "0x4AAAAAAAC3DHQFLr1GavRN"
    }
}).json()
if task["errorId"]:
    raise SystemExit(task["errorCode"])

for _ in range(60):   # 60 x 5 s = the 5 minute task limit
    time.sleep(5)
    r = requests.post(f"{API}/getTaskResult", json={"clientKey": KEY, "taskId": task["taskId"]}).json()
    if r["errorId"]:
        raise SystemExit(f"{r['errorCode']}: {r.get('errorDescription', '')}")   # failed tasks are refunded
    if r["status"] == "ready":
        print(r["solution"]["token"])
        break
else:
    raise SystemExit("timed out")

Errors this method can return