Export many finished extractions as one file
#!/usr/bin/env bashset -euo pipefailAPI=https://api.speccapture.comAUTH="Authorization: Bearer $SPECCAPTURE_API_KEY"
status=$(curl -sS --fail-with-body "$API/v1/exports" \ -H "$AUTH" \ -H "Content-Type: application/json" \ -d '{"format":"csv","filter":{"status":"completed","createdAfter":"2026-10-01T00:00:00Z"}}' \ -o extractions-csv.zip \ -w '%{http_code}')if [[ $status == 202 ]]; then exportJob=$(cat extractions-csv.zip) && rm extractions-csv.zip jq -r '"Over 100 sheets: export \(.exportId) is \(.status). Follow it until it is ready, then download its file."' <<<"$exportJob"else echo "Saved extractions-csv.zip"fiusing System.Net;using System.Text;using System.Text.Json;using System.Text.Json.Nodes;
using HttpClient http = new() { BaseAddress = new Uri("https://api.speccapture.com") };http.DefaultRequestHeaders.Authorization = new("Bearer", Environment.GetEnvironmentVariable("SPECCAPTURE_API_KEY"));
StringContent body = new(new JsonObject { ["format"] = "csv", ["filter"] = new JsonObject { ["status"] = "completed", ["createdAfter"] = "2026-10-01T00:00:00Z" },}.ToJsonString(), Encoding.UTF8, "application/json");HttpResponseMessage response = await Call(HttpMethod.Post, "/v1/exports", body);if (response.StatusCode == HttpStatusCode.Accepted) { JsonElement exportJob = await Json(response); Console.WriteLine($"Over 100 sheets: export {exportJob.GetProperty("exportId")} is {exportJob.GetProperty("status")}. Follow it until it is ready, then download its file.");} else { await File.WriteAllBytesAsync("extractions-csv.zip", await response.Content.ReadAsByteArrayAsync()); Console.WriteLine("Saved extractions-csv.zip");}
// 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 sys
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
response = call( "POST", "/v1/exports", json={"format": "csv", "filter": {"status": "completed", "createdAfter": "2026-10-01T00:00:00Z"}},)if response.status_code == 202: export_job = response.json() print(f"Over 100 sheets: export {export_job['exportId']} is {export_job['status']}. Follow it until it is ready, then download its file.")else: with open("extractions-csv.zip", "wb") as download: download.write(response.content) print("Saved extractions-csv.zip")import { writeFile } from "node:fs/promises";
const API = "https://api.speccapture.com";const headers = { Authorization: `Bearer ${process.env.SPECCAPTURE_API_KEY}` };
const response = await call("POST", "/v1/exports", { body: JSON.stringify({ format: "csv", filter: { status: "completed", createdAfter: "2026-10-01T00:00:00Z" } }), headers: { "Content-Type": "application/json" },});if (response.status === 202) { const exportJob = await response.json(); console.log(`Over 100 sheets: export ${exportJob.exportId} is ${exportJob.status}. Follow it until it is ready, then download its file.`);} else { await writeFile("extractions-csv.zip", Buffer.from(await response.arrayBuffer())); console.log("Saved extractions-csv.zip");}
// 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;}Body: format (json when left out, csv or xlsx), content (template when left out, or complete for every detail: what was read, the review state and the confidence beside every value and each sheet’s details in csv and xlsx, whatever the templates carry) and exactly one of extractionIds (1 to 500 job ids, exported in the order named) or filter (status completed or failed, fileName, createdAfter and createdBefore, as GET /v1/extractions takes them, over the finished extractions, newest first; {} for every one). Up to 100 sheets: 200 with the file - json holds extractions and sheets, each exactly as GET /v1/extractions/{jobId} and …/sheets/{n} answer; csv is a zip of sheets.csv and one file per table type; xlsx one workbook. Every row starts with its document (Document, Extraction id, and Template on the sheets), and the columns are the union of the documents’ templates, each headed by every template’s own name for it. From 101 to 5,000 sheets: 202 with the export (status queued) and Location /v1/exports/{exportId}; follow it there, or wait for the export.ready webhook, then download its fileUrl within 7 days. More than 5,000 is 422 export_too_large with sheetCount and maximumSheets; more than 5 exports waiting at once is 409 too_many_exports. An id not in the workspace is 404 not_found and one still being read 409 not_finished, each naming it; the request is refused whole. Exporting is never charged.
Authorizations
Section titled “Authorizations”Request Bodyrequired
Section titled “Request Bodyrequired”object
Json (one file of the extractions and their sheets, exactly as this API answers them), csv (a zip: sheets.csv and a file per table) or xlsx (one workbook). json when left out.
1 to 500 job ids from POST /v1/extractions or GET /v1/extractions, exported in the order named; an id named twice is exported once. Leave it out when filter chooses them.
The workspace’s finished extractions this matches, newest first; {} for every one.
object
Completed or failed; both when left out. An extraction still being read has nothing to export.
Only extractions whose file name contains this, anywhere and in any case.
Only extractions made strictly after this date and time (ISO 8601, such as 2026-10-14T09:30:00Z or 2026-10-14T09:30:00+02:00; without an offset it is UTC).
Only extractions made strictly before this date and time (ISO 8601, such as 2026-10-14T09:30:00Z or 2026-10-14T09:30:00+02:00; without an offset it is UTC).
Template (when left out): the csv and xlsx files carry what the documents’ templates carry when every one lays its files out alike, and the full layout otherwise. complete: every detail, whatever the templates say - what was read, the review state and the confidence beside every value, and each sheet’s details. The json is the complete answer either way. Never a field a document did not keep.
object
Json (one file of the extractions and their sheets, exactly as this API answers them), csv (a zip: sheets.csv and a file per table) or xlsx (one workbook). json when left out.
1 to 500 job ids from POST /v1/extractions or GET /v1/extractions, exported in the order named; an id named twice is exported once. Leave it out when filter chooses them.
The workspace’s finished extractions this matches, newest first; {} for every one.
object
Completed or failed; both when left out. An extraction still being read has nothing to export.
Only extractions whose file name contains this, anywhere and in any case.
Only extractions made strictly after this date and time (ISO 8601, such as 2026-10-14T09:30:00Z or 2026-10-14T09:30:00+02:00; without an offset it is UTC).
Only extractions made strictly before this date and time (ISO 8601, such as 2026-10-14T09:30:00Z or 2026-10-14T09:30:00+02:00; without an offset it is UTC).
Template (when left out): the csv and xlsx files carry what the documents’ templates carry when every one lays its files out alike, and the full layout otherwise. complete: every detail, whatever the templates say - what was read, the review state and the confidence beside every value, and each sheet’s details. The json is the complete answer either way. Never a field a document did not keep.
Examples
The finished extractions a filter matches, as a zip of CSV files
{ "format": "csv", "filter": { "status": "completed", "createdAfter": "2026-10-01T00:00:00Z" }}Named extractions, in the order named, as one workbook with every detail
{ "format": "xlsx", "content": "complete", "extractionIds": [ "7c9e6679-7425-40de-944b-e07fc1f90ae7", "1b4e28ba-2fa1-41d2-883f-0016d3cca427" ]}Responses
Section titled “Responses”OK
The file’s bytes: save them as they come, under the name the Content-Disposition header gives.
The file’s bytes: save them as they come, under the name the Content-Disposition header gives.
The file’s bytes: save them as they come, under the name the Content-Disposition header gives.
Accepted
An export too large to build while you wait: POST /v1/exports answers 202 with it for a selection of more than 100 sheets, and GET /v1/exports/{exportId} says how it stands. Once ready, its file downloads from fileUrl - the same file a smaller export answers at once - until expiresAt.
object
The export’s id: what following it and downloading its file name.
json, csv or xlsx.
template, or complete for every detail: what the request asked the file to hold.
Where the export stands.
How many extractions it holds, decided when it was asked for.
How many sheets they hold.
When it was asked for.
Who made something.
object
One of the workspace’s people, or one of its API keys.
The person’s name - else their email - as the workspace’s people list last knew them, kept after they leave; or the key’s name. Null when nothing names them.
When it became ready, or failed; null until then.
When its file is deleted, 7 days after it was ready; null until it is.
/v1/exports/{exportId}/file while ready; null otherwise.
What the file is saved as: speccapture-export-2026-10-14.xlsx; null until it is ready.
The file’s size; null until it is ready.
Extractions deleted after the export was asked for and before it was built, left out of the file.
While failed, or retrying after a failed attempt: what went wrong, in words; null otherwise.
Examples
More than 100 sheets: an export to follow until its file is ready
{ "exportId": "5f2a8c1e-3d4b-4e6f-9a7c-8b1d2e3f4a5b", "format": "xlsx", "content": "template", "status": "queued", "extractionCount": 38, "sheetCount": 412, "createdAt": "2026-10-14T10:00:03+00:00", "createdBy": { "kind": "apiKey", "name": "ERP import" }, "completedAt": null, "expiresAt": null, "fileUrl": null, "fileName": null, "fileSizeBytes": null, "extractionsLeftOut": [], "problem": null}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, in a few words for a person: the same for every problem with this code.
The HTTP status of the answer.
What went wrong with this request and what to do about it, in a sentence or two for a person. Present on nearly every problem.
The path of the request that was refused.
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.
Examples
The request is not valid.
{ "type": "https://speccapture.com/docs/api/errors#invalid_request", "title": "The request is not valid.", "status": 400, "detail": "Send extractionIds or filter, not both.", "instance": "/v1/exports", "code": "invalid_request", "traceId": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"}Not Found: 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, in a few words for a person: the same for every problem with this code.
The HTTP status of the answer.
What went wrong with this request and what to do about it, in a sentence or two for a person. Present on nearly every problem.
The path of the request that was refused.
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.
Examples
Not found.
{ "type": "https://speccapture.com/docs/api/errors#not_found", "title": "Not found.", "status": 404, "detail": "There is no extraction 1b4e28ba-2fa1-41d2-883f-0016d3cca427 in your workspace.", "instance": "/v1/exports", "code": "not_found", "traceId": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01", "extractionId": "1b4e28ba-2fa1-41d2-883f-0016d3cca427"}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, in a few words for a person: the same for every problem with this code.
The HTTP status of the answer.
What went wrong with this request and what to do about it, in a sentence or two for a person. Present on nearly every problem.
The path of the request that was refused.
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.
Examples
The job has not finished.
{ "type": "https://speccapture.com/docs/api/errors#not_finished", "title": "The job has not finished.", "status": 409, "detail": "Extraction 7c9e6679-7425-40de-944b-e07fc1f90ae7 is still extracting: it can be exported once every sheet has finished. Follow GET /v1/extractions/7c9e6679-7425-40de-944b-e07fc1f90ae7, or a webhook.", "instance": "/v1/exports", "code": "not_finished", "traceId": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01", "extractionId": "7c9e6679-7425-40de-944b-e07fc1f90ae7", "jobStatus": "extracting"}The workspace has as many exports waiting as it may.
{ "type": "https://speccapture.com/docs/api/errors#too_many_exports", "title": "The workspace has as many exports waiting as it may.", "status": 409, "detail": "Your workspace already has 5 exports waiting or being built, as many as it may: they are built one at a time. Ask again once one is ready (GET /v1/exports, or the export.ready webhook).", "instance": "/v1/exports", "code": "too_many_exports", "traceId": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01", "waitingCount": 5, "maximumWaiting": 5}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, in a few words for a person: the same for every problem with this code.
The HTTP status of the answer.
What went wrong with this request and what to do about it, in a sentence or two for a person. Present on nearly every problem.
The path of the request that was refused.
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.
Examples
The request body is not a media type this endpoint takes.
{ "type": "https://speccapture.com/docs/api/errors#unsupported_media_type", "title": "The request body is not a media type this endpoint takes.", "status": 415, "detail": "Send the body as JSON, with the header Content-Type: application/json: this endpoint takes a JSON object with \"format\", \"extractionIds\", \"filter\" and \"content\".", "instance": "/v1/exports", "code": "unsupported_media_type", "traceId": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"}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, in a few words for a person: the same for every problem with this code.
The HTTP status of the answer.
What went wrong with this request and what to do about it, in a sentence or two for a person. Present on nearly every problem.
The path of the request that was refused.
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.
Examples
The export would hold more sheets than it may.
{ "type": "https://speccapture.com/docs/api/errors#export_too_large", "title": "The export would hold more sheets than it may.", "status": 422, "detail": "The 512 extractions this filter matches hold 6,340 sheets; one export holds up to 5,000 sheets. Narrow the filter: createdAfter and createdBefore split it by time.", "instance": "/v1/exports", "code": "export_too_large", "traceId": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01", "sheetCount": 6340, "extractionCount": 512, "maximumSheets": 5000}