Skip to main content

Document Service

The Document service validates Typograph templates against the schema and upgrades older templates to the current schema version. Both endpoints operate on a template that is hosted at a URL — the service downloads it, processes it, and returns the result inline.

Endpoints

MethodPathDescriptionToken TypeScopes
POST/v1/document/validateValidate a hosted template against a schema versionuser or clientdocument, document:read
POST/v1/document/upgradeUpgrade a hosted template to a newer schema versionuser or clientdocument, document:write
GET/health/documentLiveness check proxied through the gateway

Both operational endpoints accept either a user token (Authorization Code / Refresh Token) or a client token (Client Credentials). See Token Types.

Request Body

Both endpoints share the same request body shape:

FieldTypeRequiredDescription
template_urlstring (URL, max 2000 chars)YesPublicly reachable URL of the template JSON file. The service HEAD-checks the URL and downloads the file. Only .json extensions are accepted.
versionstringNoSchema version to validate/upgrade against (e.g. "1.0.0"). Must match the pattern <major>.<minor>.<patch>. When omitted, the service uses the version declared inside the template.

The downloaded template file must be ≤ 50 MB.

Validate a Template

Check whether a template conforms to the Typograph schema.

curl -X POST https://api.typograph.nl/v1/document/validate \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"template_url": "https://example.com/my-template.json",
"version": "1.0.0"
}'

Response — Valid Template

If the template is valid, the response is an empty array:

[]

Response — Validation Errors

If the template has violations, the response is an array of violation objects:

[
{
"property_path": "pages[0].elements[2].width",
"message": "This value should be greater than 0.",
"invalid_value": -10
},
{
"property_path": "pages[1]",
"message": "This value should not be null.",
"invalid_value": null
}
]

Violation Object

FieldTypeDescription
property_pathstringJSON-path style pointer to the invalid property inside the template
messagestringHuman-readable description of the violation
invalid_valueanyThe value that failed validation
info

The service returns the violations array directly, not an { "valid": ..., "violations": [...] } envelope. Treat an empty array as "valid".

Upgrade a Template

Upgrade an older template to a target schema version. The response is the upgraded template JSON.

curl -X POST https://api.typograph.nl/v1/document/upgrade \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"template_url": "https://example.com/legacy-template.json",
"version": "1.0.0"
}'

Response

The upgraded template is returned inline, matching the target schema version:

{
"version": "1.0.0",
"type": "template",
"metaData": { ... },
"fontData": [ ... ],
"swatches": [ ... ],
"pages": [ ... ],
"activePageIndex": 0
}

See the Documents concept page for the full template shape.

Schema Versions

The current shipping schema version is 1.0.0. The service validates the version parameter against the <major>.<minor>.<patch> pattern; pass a matching version string or omit the field to defer to the version declared inside the template payload itself.

Errors

HTTPErrorCause
400Bad Requesttemplate_url missing, not a URL, not reachable, or not a .json file
400Bad Requestversion provided but doesn't match X.Y.Z pattern
400Bad RequestDownloaded file exceeds 50 MB
401UnauthorizedMissing or invalid access token
403ForbiddenToken lacks document scope (or document:read for validate / document:write for upgrade)

All errors follow the standard gateway JSON error format (see API Overview).

Use Cases

Pre-Submission Validation

Validate a template before handing it off to the Publisher service:

async function generatePdf(templateUrl, token) {
const validation = await fetch('https://api.typograph.nl/v1/document/validate', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ template_url: templateUrl, version: '1.0.0' })
}).then(r => r.json());

if (validation.length > 0) {
throw new Error(`Template invalid: ${validation.length} violation(s)`);
}

return fetch('https://api.typograph.nl/v1/publisher/jobs', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
template: { url: templateUrl },
generator: { type: 'pdf' }
})
}).then(r => r.json());
}

Batch Upgrade

Upgrade a list of hosted templates to the current schema version:

async function upgradeAll(templateUrls, token) {
const results = [];

for (const url of templateUrls) {
const upgraded = await fetch('https://api.typograph.nl/v1/document/upgrade', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ template_url: url, version: '1.0.0' })
}).then(r => r.json());

results.push({ source: url, upgraded });
}

return results;
}