List a file's variables
curl -H "X-Api-Key: $KEY" -F template=@invoice.docx \ http://localhost:9027/v1/templates/variablesimport { openAsBlob } from 'node:fs';
const form = new FormData();form.append('template', await openAsBlob('invoice.docx'), 'invoice.docx');
const response = await fetch('http://localhost:9027/v1/templates/variables', { method: 'POST', headers: { 'X-Api-Key': process.env.KEY }, body: form,});if (!response.ok) throw new Error(await response.text());console.log(await response.json());import os
import requests
response = requests.post( "http://localhost:9027/v1/templates/variables", headers={"X-Api-Key": os.environ["KEY"]}, files=[("template", open("invoice.docx", "rb"))],)response.raise_for_status()print(response.json())package main
import ( "bytes" "io" "log" "mime/multipart" "net/http" "os" "path/filepath")
func main() { var body bytes.Buffer form := multipart.NewWriter(&body) attach(form, "template", "invoice.docx") form.Close()
request, err := http.NewRequest("POST", "http://localhost:9027/v1/templates/variables", &body) if err != nil { log.Fatal(err) } request.Header.Set("X-Api-Key", os.Getenv("KEY")) request.Header.Set("Content-Type", form.FormDataContentType())
response, err := http.DefaultClient.Do(request) if err != nil { log.Fatal(err) } defer response.Body.Close() if response.StatusCode >= 300 { message, _ := io.ReadAll(response.Body) log.Fatalf("%s: %s", response.Status, message) } if _, err := io.Copy(os.Stdout, response.Body); err != nil { log.Fatal(err) }}
// attach adds the file at path to the form as the named field.func attach(form *multipart.Writer, field, path string) { file, err := os.Open(path) if err != nil { log.Fatal(err) } defer file.Close() part, err := form.CreateFormFile(field, filepath.Base(path)) if err != nil { log.Fatal(err) } if _, err := io.Copy(part, file); err != nil { log.Fatal(err) }}Lists the data a template sent as a file reads, as
GET /v1/templates/{id}/variables does for a stored one, without storing
it. Needs no store.
Authorizations
Section titled “Authorizations”Request Bodyrequired
Section titled “Request Bodyrequired”The form POST /v1/templates/variables takes.
object
The template: Office, text, HTML or a PDF form.
Responses
Section titled “Responses”What the template reads
What a template sent as a file reads from its data.
object
Data of the right shape, with empty strings where values go.
object
Every path the template reads, parents first, as for a stored template.
One path the template reads.
object
Dotted, with [] for each item of an array: items[].price. items[]
itself says what each item is.
What a template does with a path.
Example
{ "format": "docx", "variables": [ { "path": "items[].price", "type": "value" } ]}The request has no template file
The JSON body of every error response.
object
A stable, machine-readable kind.
What went wrong, for a person.
Example
{ "error": "invalid_request", "message": "unknown step 'teleport'"}The template has syntax errors
The JSON body of every error response.
object
A stable, machine-readable kind.
What went wrong, for a person.
Example
{ "error": "invalid_request", "message": "unknown step 'teleport'"}