curl and PowerShell
Call the Quin Local API without an SDK — complete curl and PowerShell examples for status, profiles, opening a browser, actions, files, events and closing.
The Local API is plain HTTP and JSON, so any HTTP client on the same computer can use it. These
examples work in PowerShell 5.1 or 7 and in a POSIX shell such as Git Bash, with curl (and
optionally jq).
Setup
Generate a token in Settings → Local API, then make it and the base URL available to your shell session (not in a shared file):
$env:QUIN_API_TOKEN = "qlk_xxxxxxxxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$env:QUIN_API_URL = "http://127.0.0.1:50380" # your portexport QUIN_API_TOKEN=qlk_xxxxxxxxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
BASE="${QUIN_API_URL:-http://127.0.0.1:50380}/api/v1"Rules every client must follow:
- Call
127.0.0.1:<port>orlocalhost:<port>— other host names are refused (421). - Do not send an
Originheader (403). - Send bodies with
Content-Length(curl--dataandInvoke-RestMethod -Bodydo); neverTransfer-Encoding: chunked(411). Bodies are limited to 1 MB.
curl
q() { # q METHOD PATH [JSON-BODY [extra curl args...]]
local args=(-sS --fail-with-body -X "$1" "$BASE$2" -H "Authorization: Bearer $QUIN_API_TOKEN" --max-time 930)
[[ $# -ge 3 ]] && args+=(-H "Content-Type: application/json" --data "$3" "${@:4}")
curl "${args[@]}"; echo
}
q GET /status
q GET "/profiles?page=1&page_size=10"
# Open (waits until RUNNING). The Idempotency-Key makes a retried open safe.
SESSION=$(q POST /browsers/open '{"profile_id":"AbCd1234","wait":true,"timeout_s":300}' \
-H "Idempotency-Key: curl-$(date +%s)-$$")
SID=$(echo "$SESSION" | jq -r .session_id)
q POST "/browsers/$SID/actions" '{"action":"navigate","params":{"url":"https://example.com","wait_until":"load"}}'
q POST "/browsers/$SID/actions" '{"action":"title"}'
q POST "/browsers/$SID/actions" '{"action":"text","locator":{"css":"h1"},"timeout_ms":5000}'
q POST "/browsers/$SID/actions" '{"action":"count","locator":{"role":"link"}}'
SHOT=$(q POST "/browsers/$SID/actions" '{"action":"screenshot","params":{"full_page":true,"name":"curl.png"}}')
# Download the screenshot from the automation workspace
curl -sS "$BASE/files/$(echo "$SHOT" | jq -r .result.file)" \
-H "Authorization: Bearer $QUIN_API_TOKEN" -o curl.png
# Close; for a Quin Cloud profile this returns once the profile is SYNCED
q POST "/browsers/$SID/close" '{"sync":true,"wait":true}'--fail-with-body makes curl exit non-zero on HTTP errors and still print the error envelope. An action
that fails still returns 200; check .outcome:
R=$(q POST "/browsers/$SID/actions" '{"action":"click","locator":{"text":"Accept"}}')
[ "$(echo "$R" | jq -r .outcome)" = ok ] || echo "failed: $(echo "$R" | jq -r .error.code)"PowerShell
$ErrorActionPreference = "Stop"
$base = "$($env:QUIN_API_URL.TrimEnd('/'))/api/v1"
$headers = @{ Authorization = "Bearer $env:QUIN_API_TOKEN" }
function Invoke-Quin([string]$Method, [string]$Path, $Body = $null, [int]$TimeoutSec = 60, [hashtable]$Extra = @{}) {
$p = @{ Method = $Method; Uri = "$base$Path"; Headers = ($headers + $Extra); TimeoutSec = $TimeoutSec }
if ($null -ne $Body) {
$p.Body = [Text.Encoding]::UTF8.GetBytes(($Body | ConvertTo-Json -Depth 10 -Compress))
$p.ContentType = "application/json; charset=utf-8"
}
try { Invoke-RestMethod @p }
catch { throw "Quin API $Method $Path failed: $($_.ErrorDetails.Message)" } # the error envelope
}
$status = Invoke-Quin GET "/status"
"Quin $($status.quin_version), account $($status.account.email)"
$profiles = Invoke-Quin GET "/profiles?page=1&page_size=10"
$profiles.items | Select-Object id, name, kind, status | Format-Table -AutoSize
$session = Invoke-Quin POST "/browsers/open" @{ profile_id = "AbCd1234"; wait = $true; timeout_s = 300 } `
-TimeoutSec 330 -Extra @{ "Idempotency-Key" = "ps-open-$([guid]::NewGuid())" }
$sid = $session.session_id
function Invoke-Action([string]$Action, $Locator = $null, $Params = @{}) {
$body = @{ action = $Action; params = $Params }
if ($Locator) { $body.locator = $Locator }
$r = Invoke-Quin POST "/browsers/$sid/actions" $body -TimeoutSec 120
if ($r.outcome -ne "ok") { throw "Action $Action failed: $($r.error.code): $($r.error.message)" }
$r.result
}
try {
$nav = Invoke-Action "navigate" $null @{ url = "https://example.com"; wait_until = "load" }
"Navigated: $($nav.url) (HTTP $($nav.status))"
"Title: " + (Invoke-Action "title").title
if ((Invoke-Action "count" @{ css = "h1" }).value -gt 0) { "H1: " + (Invoke-Action "text" @{ css = "h1" }).value }
$shot = Invoke-Action "screenshot" $null @{ full_page = $true; name = "powershell.png" }
"Screenshot: $($shot.file) ($($shot.bytes) bytes)"
}
finally {
$closed = Invoke-Quin POST "/browsers/$sid/close" @{ sync = $true; wait = $true } -TimeoutSec 930
"Closed: $($closed.state)" # CLOSED (local) or SYNCED (Quin Cloud)
}Encoding the body as UTF-8 bytes keeps non-ASCII text intact in Windows PowerShell 5.1.
Run a workflow and wait
$task = Invoke-Quin POST "/tasks" @{ workflow_id = "wf_123"; profile_ids = @("AbCd1234"); inputs = @{ query = "shoes" } } `
-Extra @{ "Idempotency-Key" = "ps-task-$([guid]::NewGuid())" }
do {
Start-Sleep -Seconds 2
$t = Invoke-Quin GET "/tasks/$($task.task_id)"
} while ($t.state -in @("QUEUED", "RUNNING", "WAITING_FOR_AGENT"))
$t.state
$t.runs | Select-Object id, profile_id, state, error_code | Format-TableStream events
curl -N "$BASE/events?kinds=browser.*,job.updated" \
-H "Authorization: Bearer $QUIN_API_TOKEN" -H "Accept: text/event-stream"Each event arrives as id:, event: and data: lines; reconnect with -H "Last-Event-ID: <id>". See
Events.
Timeouts
| Call | Suggested client timeout |
|---|---|
| Ordinary requests | 60 s |
POST /browsers/open (wait) | timeout_s + 30 s |
| Actions | timeout_ms + 15 s (120 s is a safe default) |
POST /browsers/{sid}/close (wait, sync) | 930 s — a Quin Cloud save can be large |
If your client gives up first, Quin still finishes the operation. Retry POSTs only with the same
Idempotency-Key, so the retry returns the first result instead of acting twice.