Create a render (image or PDF)
Creating a render on Templated is achieved via this endpoint.
This endpoint responds with 202 Accepted
after which your render will be queued to generate. Renders are usually rendered within a few seconds. When completed, the status changes to completed
.
Sample Request
Here’s a sample request to create a render:
POST /v1/render;
fetch('https://api.templated.io/v1/render', { method: 'POST', body: JSON.stringify( { "template" : TEMPLATE_ID, "layers" : { "text-1" : { "text" : "This is my text to be rendered", "color" : "#FFFFFF", "background" : "#0000FF" }, "image-1": { "image_url" : "https://pathtomyphoto.com/123.jpg" } } } ), headers: { 'Content-Type' : 'application/json', 'Authorization' : `Bearer ${API_KEY}` }})
import requests
api_key = 'API_KEY'template_id = 'TEMPLATE_ID'
url = 'https://api.templated.io/v1/render'headers = { 'Content-Type': 'application/json', 'Authorization': f'Bearer {api_key}'}
data = { 'template': template_id, 'layers': { 'text-1': { 'text': 'This is my text to be rendered', 'color': '#FFFFFF', 'background': '#0000FF' }, 'image-1': { 'image_url': 'https://pathtomyphoto.com/123.jpg' } }}
response = requests.post(url, json=data, headers=headers)
if response.status_code == 202: print('Render request accepted.')else: print('Render request failed. Response code:', response.status_code) print(response.text)
import java.net.HttpURLConnection;import java.net.URL;import java.io.OutputStream;import org.json.JSONObject;
public class RenderRequest { public static void main(String[] args) { try { String apiKey = "API_KEY"; String templateId = "TEMPLATE_ID";
URL url = new URL("https://api.templated.io/v1/render"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Authorization", "Bearer " + apiKey); connection.setDoOutput(true);
JSONObject layers = new JSONObject() .put("text-1", new JSONObject() .put("text", "This is my text to be rendered") .put("color", "#FFFFFF") .put("background", "#0000FF")) .put("image-1", new JSONObject() .put("image_url", "https://pathtomyphoto.com/123.jpg"));
JSONObject jsonInput = new JSONObject() .put("template", templateId) .put("layers", layers);
try (OutputStream os = connection.getOutputStream()) { byte[] input = jsonInput.toString().getBytes("utf-8"); os.write(input, 0, input.length); }
int responseCode = connection.getResponseCode(); System.out.println(responseCode); } catch (Exception e) { e.printStackTrace(); } }}
<?php $apiKey = 'API_KEY'; $templateId = 'TEMPLATE_ID'; $url = 'https://api.templated.io/v1/render';
$data = [ 'template' => $templateId, 'layers' => [ 'text-1' => [ 'text' => 'This is my text to be rendered', 'color' => '#FFFFFF', 'background' => '#0000FF' ], 'image-1' => [ 'image_url' => 'https://pathtomyphoto.com/123.jpg' ] ] ];
$options = [ 'http' => [ 'header' => [ 'Content-Type: application/json', 'Authorization: Bearer ' . $apiKey ], 'method' => 'POST', 'content' => json_encode($data) ] ];
$context = stream_context_create($options); $result = file_get_contents($url, false, $context); if ($result === FALSE) { // Handle error }
echo $result;?>
Parameters
template string
REQUIRED
The template id that you want to use.
webhook_url string
A url to POST the full Render object to upon rendering completed.
format boolean
Render format (jpg
, png
, webp
or pdf
). Default is jpg
.
transparent boolean
Make the background transparent when the render format is png
. Default is false
.
layers object
REQUIRED
An object of layers that will be updated in the template.
The object key is the layer name and the value is an object with the following properties to override the template layers:
Layer Parameters
text string
Replacement text you want to use.
image_url string
Replacement image src for an image layer.
color string
Color in hex format e.g. “#FF0000”.
background string
Background color in hex format e.g. “#FF0000”.
font_family string
Change the font family.
font_size string
Change the font size. Use a CSS value like (“24px” or “12pt”)
border_width integer
Width of the object border.
border_color string
Border color in hex format e.g. “#FF0000”.
fill string
Shape fill color in hex format e.g. “#FF0000”.
stroke string
Shape stroke (border) color in hex format e.g. “#FF0000”.
hide boolean
Set to true to hide the layer.