Get a template's fields
#!/usr/bin/env bashset -euo pipefailAPI=https://api.speccapture.comAUTH="Authorization: Bearer $SPECCAPTURE_API_KEY"
TEMPLATE_ID=c2b8f3a1-7e5d-4c9a-8f6b-1a2d3e4f5a6b # drawing, or a templateId from the list of templates
template=$(curl -sS --fail-with-body "$API/v1/templates/$TEMPLATE_ID" \ -H "$AUTH") || { echo "$template" >&2; exit 1; }jq -r '"\(.name), version \(.version):"' <<<"$template"
jq -r '.fields[] as $field | " \($field.path) is called \"\($field.name)\""' <<<"$template"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 templateId = args[0]; // drawing, or a templateId from the list of templates
JsonElement template = await Json(await Call(HttpMethod.Get, $"/v1/templates/{templateId}"));Console.WriteLine($"{template.GetProperty("name")}, version {template.GetProperty("version")}:");
foreach (JsonElement field in template.GetProperty("fields").EnumerateArray()) { Console.WriteLine($" {field.GetProperty("path")} is called \"{field.GetProperty("name")}\"");}
// 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
template_id = sys.argv[1] # drawing, or a templateId from the list of templates
template = call("GET", f"/v1/templates/{template_id}").json()print(f"{template['name']}, version {template['version']}:")
for field in template["fields"]: print(f" {field['path']} is called \"{field['name']}\"")const API = "https://api.speccapture.com";const headers = { Authorization: `Bearer ${process.env.SPECCAPTURE_API_KEY}` };
const [templateId] = process.argv.slice(2); // drawing, or a templateId from the list of templates
const template = await call("GET", `/v1/templates/${templateId}`).then((response) => response.json());console.log(`${template.name}, version ${template.version}:`);
for (const field of template.fields) { console.log(` ${field.path} is called "${field.name}"`);}
// 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;}Each field’s path (the key its values carry, never changed by a rename), name (the name on its values), standardName, order, required, alwaysCheck, section, definedBy and measured (measured for the four fields whose accuracy SpecCapture publishes, standard for the rest, notMeasured for sizes and counts); each table with its kept columns in order; the notes when delivered; and the export layout. Add ?version= for an earlier version: the one a job’s templateVersion names never changes.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”Query Parameters
Section titled “Query Parameters”Responses
Section titled “Responses”OK
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.
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, as a stable code to branch on: a published code never changes meaning.
This request’s trace: quote it when asking for help.