Submit a drawing
#!/usr/bin/env bashset -euo pipefailAPI=https://api.speccapture.comAUTH="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) is \(.status): \(.sheetCount) sheets, \(.credits.reserved) credits reserved"' <<<"$job"using System.Text.Json;
using HttpClient http = new() { BaseAddress = new Uri("https://api.speccapture.com") };http.DefaultRequestHeaders.Authorization = new("Bearer", Environment.GetEnvironmentVariable("SPECCAPTURE_API_KEY"));
string drawing = args[0]; // the drawing to send: a PDF, TIFF, PNG, JPEG, BMP or WebP
using MultipartFormDataContent form = new() { { new StreamContent(File.OpenRead(drawing)), "file", Path.GetFileName(drawing) } };JsonElement job = await Json(await Call(HttpMethod.Post, "/v1/extractions", form, Guid.NewGuid().ToString()));Console.WriteLine($"Job {job.GetProperty("jobId")} is {job.GetProperty("status")}: {job.GetProperty("sheetCount")} sheets, {job.GetProperty("credits").GetProperty("reserved")} credits reserved");
// Sends a request; stops with the problem's code and detail if the API refuses it.async Task<HttpResponseMessage> Call(HttpMethod method, string path, HttpContent? body = null, string? idempotencyKey = null) { using HttpRequestMessage request = new(method, path) { Content = body }; if (idempotencyKey is not null) request.Headers.Add("Idempotency-Key", idempotencyKey); HttpResponseMessage response = await http.SendAsync(request); if (!response.IsSuccessStatusCode) { JsonElement problem = await Json(response); string? detail = (problem.TryGetProperty("detail", out JsonElement text) ? text : problem.GetProperty("title")).GetString(); Console.Error.WriteLine($"{(int)response.StatusCode} {problem.GetProperty("code")}: {detail}"); Environment.Exit(1); } return response;}
// Reads an answer as JSON.static async Task<JsonElement> Json(HttpResponseMessage response) => JsonDocument.Parse(await response.Content.ReadAsStringAsync()).RootElement;import osimport sysimport uuid
import requests
API = "https://api.speccapture.com"session = requests.Session()session.headers["Authorization"] = f"Bearer {os.environ['SPECCAPTURE_API_KEY']}"
def call(method, path, **kwargs): """Send a request; stop with the problem's code and detail if the API refuses it.""" response = session.request(method, API + path, **kwargs) if not response.ok: problem = response.json() sys.exit(f"{response.status_code} {problem['code']}: {problem.get('detail', problem['title'])}") return response
drawing = sys.argv[1] # the drawing to send: a PDF, TIFF, PNG, JPEG, BMP or WebP
with open(drawing, "rb") as file: job = call( "POST", "/v1/extractions", files={"file": file}, headers={"Idempotency-Key": str(uuid.uuid4())}, ).json()print(f"Job {job['jobId']} is {job['status']}: {job['sheetCount']} sheets, {job['credits']['reserved']} credits reserved")import { openAsBlob } from "node:fs";import { basename } from "node:path";import { randomUUID } from "node:crypto";
const API = "https://api.speccapture.com";const headers = { Authorization: `Bearer ${process.env.SPECCAPTURE_API_KEY}` };
const [drawing] = process.argv.slice(2); // the drawing to send: a PDF, TIFF, PNG, JPEG, BMP or WebP
const form = new FormData();form.append("file", await openAsBlob(drawing), basename(drawing));const job = await call("POST", "/v1/extractions", { body: form, headers: { "Idempotency-Key": randomUUID() },}).then((response) => response.json());console.log(`Job ${job.jobId} is ${job.status}: ${job.sheetCount} sheets, ${job.credits.reserved} credits reserved`);
// Sends a request; stops with the problem's code and detail if the API refuses it.async function call(method, path, init = {}) { const response = await fetch(API + path, { ...init, method, headers: { ...headers, ...init.headers } }); if (!response.ok) { const problem = await response.json(); console.error(`${response.status} ${problem.code}: ${problem.detail ?? problem.title}`); process.exit(1); } return response;}Accepts one PDF, TIFF, PNG, JPEG, BMP or WebP as multipart/form-data, in a part named ‘file’, reserves 4 credits per sheet and answers 202 with the job. One drawing a request: a form with a second ‘file’ part is refused whole with 400 invalid_request, so send each drawing in a request of its own. Optional form fields templateId (drawing, or an id from GET /v1/templates) and templateVersion choose which fields the job keeps, under which names and in which order; left out, the workspace’s default template. Every template reads the drawing the same way. An id the workspace does not have is 422 template_not_found, before anything is reserved. Send an Idempotency-Key to make retries safe: the same key with a different file or template is 409.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Header Parameters
Section titled “Header Parameters”Request Bodyrequired
Section titled “Request Bodyrequired”The drawing, as multipart/form-data: one part named ‘file’, one drawing a request.
object
A PDF, TIFF, PNG, JPEG, BMP or WebP, recognised from its bytes. Each page is a sheet; each sheet reserves 4 credits.
Optional: the template the job is delivered with - drawing (the standard template, every field) or a template id from GET /v1/templates. Left out, the workspace’s default.
Optional: a published version of templateId; its newest when left out.
Responses
Section titled “Responses”Accepted
object
object
object
object
Bad Request: a problem with a stable code. See Errors for every code and what to do about it.
Every error: a problem with a stable code. https://speccapture.com/docs/api/errors lists every code.
object
A link to the code’s entry in the docs.
What went wrong, as a stable code to branch on: a published code never changes meaning.
This request’s trace: quote it when asking for help.
Unauthorized: a problem with a stable code. See Errors for every code and what to do about it.
Every error: a problem with a stable code. https://speccapture.com/docs/api/errors lists every code.
object
A link to the code’s entry in the docs.
What went wrong, as a stable code to branch on: a published code never changes meaning.
This request’s trace: quote it when asking for help.
Payment Required: a problem with a stable code. See Errors for every code and what to do about it.
Every error: a problem with a stable code. https://speccapture.com/docs/api/errors lists every code.
object
A link to the code’s entry in the docs.
What went wrong, as a stable code to branch on: a published code never changes meaning.
This request’s trace: quote it when asking for help.
Conflict: a problem with a stable code. See Errors for every code and what to do about it.
Every error: a problem with a stable code. https://speccapture.com/docs/api/errors lists every code.
object
A link to the code’s entry in the docs.
What went wrong, as a stable code to branch on: a published code never changes meaning.
This request’s trace: quote it when asking for help.
Payload Too Large: a problem with a stable code. See Errors for every code and what to do about it.
Every error: a problem with a stable code. https://speccapture.com/docs/api/errors lists every code.
object
A link to the code’s entry in the docs.
What went wrong, as a stable code to branch on: a published code never changes meaning.
This request’s trace: quote it when asking for help.
Unsupported Media Type: a problem with a stable code. See Errors for every code and what to do about it.
Every error: a problem with a stable code. https://speccapture.com/docs/api/errors lists every code.
object
A link to the code’s entry in the docs.
What went wrong, as a stable code to branch on: a published code never changes meaning.
This request’s trace: quote it when asking for help.
Unprocessable Entity: a problem with a stable code. See Errors for every code and what to do about it.
Every error: a problem with a stable code. https://speccapture.com/docs/api/errors lists every code.
object
A link to the code’s entry in the docs.
What went wrong, as a stable code to branch on: a published code never changes meaning.
This request’s trace: quote it when asking for help.
Too Many Requests: a problem with a stable code. See Errors for every code and what to do about it.
Every error: a problem with a stable code. https://speccapture.com/docs/api/errors lists every code.
object
A link to the code’s entry in the docs.
What went wrong, as a stable code to branch on: a published code never changes meaning.
This request’s trace: quote it when asking for help.
Not Implemented: a problem with a stable code. See Errors for every code and what to do about it.
Every error: a problem with a stable code. https://speccapture.com/docs/api/errors lists every code.
object
A link to the code’s entry in the docs.
What went wrong, as a stable code to branch on: a published code never changes meaning.
This request’s trace: quote it when asking for help.
Service Unavailable: a problem with a stable code. See Errors for every code and what to do about it.
Every error: a problem with a stable code. https://speccapture.com/docs/api/errors lists every code.
object
A link to the code’s entry in the docs.
What went wrong, as a stable code to branch on: a published code never changes meaning.
This request’s trace: quote it when asking for help.