UNLOCK API

Drag and drop solving API

Send a Drag and drop task to the API and get back the answer your code submits to the page. The images and where pieces must go. You get: Moves to perform (from and to points).

At a glance

Price per 1,000
$0.60 ($0.0006 per task)
createTask type
DragAndDropTask
in.php method
You send
The images and where pieces must go
You get
Moves to perform (from and to points)

Where to find the values

Send the background and pieces with the instruction as comment.

createTask and getTaskResult

Create the task, wait about 5 seconds, then check the result every 5 seconds until the status is ready. If the task fails, the API returns an error and the charge goes back to your credit.

import time, requests

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

task = requests.post(f"{API}/createTask", json={
    "clientKey": KEY,
    "task": {
      "type": "DragAndDropTask",
      "body": "/9j/4AAQSkZJRgABAQ...",
      "comment": "Move each piece to its matching place"
    }
}).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"])
        break
else:
    raise SystemExit("timed out")

Full API reference: every parameter and the solution object