Skip to content
API console (try a request with your own key)Get early access

Quickstart

From an API key to every value on a drawing in a few minutes. You need:

  • An API key. A workspace’s owner or an admin makes one in the SpecCapture dashboard, under API keys (how).
  • A drawing: a PDF, TIFF, PNG, JPEG, BMP or WebP.
  • One of: curl (with jq for the longer scripts), .NET 10, Python 3.9 or later with requests, or Node.js 20 or later. Every sample below comes in all four; pick a tab and the docs remember it.

1. Put the key where the samples look for it

Section titled “1. Put the key where the samples look for it”

Every sample reads the key from the environment variable SPECCAPTURE_API_KEY, so it never appears in code:

Terminal window
export SPECCAPTURE_API_KEY="sc_live_..."

In PowerShell: $env:SPECCAPTURE_API_KEY = "sc_live_...".

check_key.sh
#!/usr/bin/env bash
set -euo pipefail
API=https://api.speccapture.com
AUTH="Authorization: Bearer $SPECCAPTURE_API_KEY"
account=$(curl -sS --fail-with-body "$API/v1/account" \
-H "$AUTH") || { echo "$account" >&2; exit 1; }
jq -r '"Workspace \(.workspaceName): \(.credits.available) credits, enough for \(.credits.sheetsAvailable) sheets"' <<<"$account"

Save as check_key.sh, set SPECCAPTURE_API_KEY, and run: bash check_key.sh. Needs curl; scripts also use bash and jq.

An answer of 401 means the key was not accepted; its code says why (Errors).

3. Submit a drawing, wait for it, and read it

Section titled “3. Submit a drawing, wait for it, and read it”
quickstart.sh
#!/usr/bin/env bash
set -euo pipefail
API=https://api.speccapture.com
AUTH="Authorization: Bearer $SPECCAPTURE_API_KEY"
DRAWING=bracket.pdf # the drawing to send: a PDF, TIFF, PNG, JPEG, BMP or WebP
job=$(curl -sS --fail-with-body "$API/v1/extractions" \
-H "$AUTH" \
-H "Idempotency-Key: $(openssl rand -hex 16)" \
-F "file=@$DRAWING") || { echo "$job" >&2; exit 1; }
jq -r '"Job \(.jobId): \(.sheetCount) sheets, \(.credits.reserved) credits reserved"' <<<"$job"
while true; do
job=$(curl -sS --fail-with-body "$API/v1/extractions/$(jq -r '.jobId' <<<"$job")" \
-H "$AUTH") || { echo "$job" >&2; exit 1; }
jq -r '" \(.status): \(.progress.sheetsCompleted) of \(.sheetCount) sheets read"' <<<"$job"
if [[ "$(jq -r '.status' <<<"$job")" =~ ^(completed|failed)$ ]]; then break; fi
sleep 5
done
while IFS= read -r summary; do
if [[ "$(jq -r '.status' <<<"$summary")" == "completed" ]]; then
sheet=$(curl -sS --fail-with-body "$API/v1/extractions/$(jq -r '.jobId' <<<"$job")/sheets/$(jq -r '.sheetNumber' <<<"$summary")" \
-H "$AUTH") || { echo "$sheet" >&2; exit 1; }
jq -r '"Sheet \(.sheetNumber) (\(.reviewState))"' <<<"$sheet"
jq -r '.fields[] as $field | " \($field.path) = \($field.value // "(not on the sheet)") [\($field.reviewState), \($field.confidence)]"' <<<"$sheet"
fi
done < <(jq -c '.sheets[]' <<<"$job")

Save as quickstart.sh, set SPECCAPTURE_API_KEY, and run: bash quickstart.sh. Needs curl; scripts also use bash and jq.

The program sends the drawing with an Idempotency-Key, so a retry can never be charged twice; asks for the job every 5 seconds until it has finished; then prints every value of every sheet that was read, with its review state and confidence. A value printed as needsReview waits for a person in your workspace: it is delivered as read, but nobody has confirmed it yet.