Clients
The API is described by an OpenAPI document, so a client for it can be generated in most languages with a generator such as Kiota, NSwag or OpenAPI Generator: see OpenAPI. It is plain HTTPS and JSON, though, so it can as easily be used with any language's own HTTP client, as the examples here are.
Whatever the language, every request carries your key in the X-API-KEY header: see
Using your API Key.
Examples
Each example is a complete program that does the same job, so they can be compared:
- It reads your API key from the
PIQ_API_KEYenvironment variable, and the service's address fromPIQ_URL(https://saas.parametriq.co.ukif not set). - It lists a template's labelled variables (
POST /inputs): a 400 × 300 rectangle, its lengthLand widthWlabelled. - It measures the drawing with
L500 andW250 (POST /measure): its width, height and cut length. - It exports the drawing as a PDF (
POST /export/pdf), saves it asbox.pdf, and prints theX-PiQ-Warningsheader. - Optionally, when
PIQ_STORAGEnames one of your registered storages, it reads the template from that storage (source) and saves the PDF to it as well (POST /save/pdf).
A request that isn't a success stops it: it prints the status and the problem description (its title, detail,
and what is wrong with which value, from errors), and exits with a code other than 0. A 401 (a key that isn't
right) has no problem description, so only the status is printed.
Each page has the program to read and a link to download it.
- JavaScript: Node.js 18 or later, with its built-in
fetch; no packages. - Python: Python 3, with
requests. - C#: .NET, with
HttpClientandSystem.Net.Http.Json; a single-file console program. - Go: Go, with the standard library only.
- Java: Java 17 or later, with
java.net.http; no libraries. - PHP: PHP 8, with the curl extension.
- Ruby: Ruby 3, with
net/httpfrom the standard library. - curl: a bash script, with curl and jq.
To run one, set your key in the environment first: export PIQ_API_KEY=XXXX-XXXX-XXXX-XXXXX in bash, or
$env:PIQ_API_KEY = "XXXX-XXXX-XXXX-XXXXX" in PowerShell. Keep the key out of the program itself.
The template, in each example, is the one from API:
L=400,"Length"
W=300,"Width"
P1=[L,0]
P2=[L,W]
P3=[0,W]
POLYLINE @1,[P0,P1,P2,P3],TRUE,0
See also: API, OpenAPI, Using your API Key.