{
  "info": {
    "name": "SolveHub authorized testing quick start",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "description": "Set apiKey, websiteURL and websiteKey for a site you are authorized to test. Set a unique idempotencyKey for each logical task, preserve it and the exact body for retries. Keep taskId to resume polling. Run requests individually; do not loop the entire collection. A client timeout or uncertain task is not a reason to create a new task. Keys and proxy credentials must stay private."
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{apiKey}}",
        "type": "string"
      }
    ]
  },
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://www.tiam.codes",
      "type": "string"
    },
    {
      "key": "apiKey",
      "value": "",
      "type": "string"
    },
    {
      "key": "websiteURL",
      "value": "https://example.com/login",
      "type": "string"
    },
    {
      "key": "websiteKey",
      "value": "REPLACE_WITH_AUTHORIZED_SITE_KEY",
      "type": "string"
    },
    {
      "key": "idempotencyKey",
      "value": "",
      "type": "string"
    },
    {
      "key": "taskId",
      "value": "",
      "type": "string"
    }
  ],
  "item": [
    {
      "name": "1. Live prices",
      "request": {
        "auth": {
          "type": "noauth"
        },
        "method": "GET",
        "header": [],
        "url": "{{baseUrl}}/v1/prices"
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test(\"Prices are available\", () => pm.response.to.have.status(200));"
            ]
          }
        }
      ]
    },
    {
      "name": "2. Create an authorized Turnstile task",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Idempotency-Key",
            "value": "{{idempotencyKey}}"
          }
        ],
        "url": "{{baseUrl}}/v1/tasks",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"type\": \"turnstile\",\n  \"task\": {\n    \"websiteURL\": \"{{websiteURL}}\",\n    \"websiteKey\": \"{{websiteKey}}\"\n  }\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const key = pm.variables.get(\"idempotencyKey\");",
              "if (!key || key.length < 8 || key.length > 128) throw new Error(\"Set and persist an 8–128 character idempotencyKey. Keep it unchanged for retries.\");"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test(\"Task accepted\", () => pm.response.to.have.status(202));",
              "if (pm.response.code === 202) {",
              "  const task = pm.response.json();",
              "  pm.test(\"taskId exists\", () => pm.expect(task.taskId).to.be.a(\"string\"));",
              "  if (typeof task.taskId === \"string\") pm.collectionVariables.set(\"taskId\", task.taskId);",
              "}"
            ]
          }
        }
      ]
    },
    {
      "name": "3. Read the same task (repeat manually every 2–3 seconds)",
      "request": {
        "method": "GET",
        "header": [],
        "url": "{{baseUrl}}/v1/tasks/{{taskId}}"
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test(\"Task fetched\", () => pm.response.to.have.status(200));",
              "if (pm.response.code === 200) {",
              "  const task = pm.response.json();",
              "  pm.test(\"Known status\", () => pm.expect([\"queued\", \"dispatching\", \"processing\", \"uncertain\", \"completed\", \"failed\", \"cancelled\"]).to.include(task.status));",
              "}"
            ]
          }
        }
      ]
    },
    {
      "name": "Build DataDome challenge URL (free)",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"websiteURL\": \"{{websiteURL}}\",\n  \"captchaUrl\": \"https://geo.captcha-delivery.com/captcha/?cid=EXAMPLE\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": "{{baseUrl}}/v1/datadome/build-url",
        "description": "Synchronous, no charge and no solving task. Supply a fresh captured body, location or captchaUrl for an authorized session; pass the returned captchaUrl unchanged to a DataDome task."
      }
    }
  ]
}
