Support for

TCAPI: Template Editing and File Assets

John Valentine
by John Valentine 5 years ago
 

Templates

Buy an InDesign file

Syntax
/templates/<template_id>/buyIndesignFile

Buys the InDesign file. This might incur a charge.

Fetch a bought InDesign file

Syntax
/templates/<template_id>/indesignFile

Fetches the template’s InDesign file, and returns it as an attachment.

Prepare a template for editing

Syntax
/templates/<template_id>/edit

Creates a template instance from a template.id. This instance can be edited by further API calls — see below.

Parameter Description
user_key Your application’s key, from developer.templatecloud.com 
format json or xml
template_id One template id (required)
HTTP request
GET http://api.templatecloud.com/sandbox/templates/5277/edit?user_key=ba386e729c5f6870cea89f38e92d7a5c&format=json
HTTP response (JSON)
{
    "instance_id": "436935"
}

Template instances

Make a PDF

Syntax
/instances/<instance_id>/makePDF

Initiates the creation of a PDF file, and charges your account.

Parameter Description
user_key Your application’s key, from developer.templatecloud.com 
format json or xml
queue 0 = generate and wait (synchronous)
1 = queue for later retrieval (asynchronous) – recommended!
skip_buy Some API consumers have a special permission enabled, to bypass the fees, which can be exercised using skip_buy=1. This option is disabled for the majority of API keys.
HTTP request
PUT http://api.templatecloud.com/sandbox/instances/50010/makePDF?user_key=ba386e729c5f6870cea89f38e92d7a5c&format=json
HTTP response (JSON)
{
    "status": "ok",
    "message": "PDF generation in progress",
    "job": "2152428"
}

No further edits of a template instance are possible after a call to makePDF; further edits must be made to a new template instance which may be created using call to /templates/<template_id>/edit

Poll/Fetch PDF

Syntax
/instances/<instance_id>/pdf

If the PDF is ready to download, the response to a GET request is a URL to the PDF file; otherwise it is an error notification.

It is advised that you poll /pdf with a HEAD request until the 200 response is returned; feed back the latest result to your web page via AJAX.

HTTP request
HEAD http://api.templatecloud.com/sandbox/instances/50010/pdf?user_key=ba386e729c5f6870cea89f38e92d7a5c&format=json
HTTP response 202 (JSON)
{
    "status": "error",
    "message": "PDF generation in progress." 
}
HTTP response 500 (JSON)
{
    "status": "error",
    "message": "PDF generation failed." 
}
HTTP response 404 (JSON)
{
    "status": "error",
    "message": "PDF not created (probably instance not found, or some unknown error)." 
}
HTTP response 200 (JSON)
{
    "status": "ok",
    "message": "PDF ready." 
}

After receiving a 200 response, the file can be retrieved using the equivalent GET request:

HTTP request
GET http://api.templatecloud.com/sandbox/instances/50010/pdf?user_key=ba386e729c5f6870cea89f38e92d7a5c&format=json

If the file is still available, the 200 response will contain a binary stream. If the file is not available, the response will be an XML/JSON notification of the error (as above).

 

Jump to contents page of

TemplateCloud API Guide

 
 
 

All content is (c) Grafenia Operations Limited, 2020 and may not be used, copied or distributed without permission.