Images from templates (API)
Make post images from ready-made templates over the REST API, drawn in your brand kit at once, then post them.
The REST API can make post images from the same ready-made templates as the dashboard. You send a template and its text; ShareTotem draws it in the brand's colours, fonts and logo, fits long text, checks it, and returns the images. Drawing takes well under a second a slide, so there's no job to poll: the answer has the images.
Every request uses an API token from Settings → API tokens (Authorization: Bearer …). Reading the catalogue needs the read ability; making images needs create. The brand needs a brand kit.
#1. The catalogue
1GET /api/v1/designs/templates?domain_id=12
Each template lists its layouts and, for each, its texts: key, label, max characters, whether it's required, a default and a hint on how to write it. Carousels say how many slides they take. With a domain_id, an Enterprise brand's own templates come first, as brand-<key>.
#2. Make the images
1POST /api/v1/designs
2Content-Type: application/json
3
4{
5 "domain_id": 12,
6 "template": "breaking-news",
7 "network": "instagram",
8 "text": { "headline": "City council approves the *new tram line*", "kicker": "Rome · 18:40" },
9 "photo_media_id": "9b1e…",
10 "dry_run": true
11}
| Field | |
|---|---|
template |
A template id from the catalogue. |
text |
A one-image template's texts by key. Mark words: *words* get the text's highlight, _words_ a hand-drawn underline, ((words)) a hand-drawn circle. |
highlight |
How each text's *words* look, by key: block, color, underline or circle, e.g. { "headline": "underline" }. In a carousel, each slide takes its own highlight. Default: the template's. |
slides |
A carousel instead: [{ "layout": "cover", "text": {…} }, { "text": {…} }, …], 2 to 10 slides. Without layout, slides are a cover, items and a closing slide by position. |
layout |
A one-image template's other layout, e.g. a meme's top-bottom. |
style |
One of the template's styles (colour, plain, dark). |
extras |
Things added on top of a slide, only when you want them: [{ "kind": "label", "text": "New", "x": 0.06, "y": 0.05 }]. kind text (up to 160 characters), label (40), shape (with shape rect, circle or line, and a height in pixels) or arrow; x/y (0-0.95) is where its top-left starts, as a share of the image. They're named x1, x2… in order: style one with text_style under that name (color, width, and for texts and labels everything else). In a carousel, each slide takes its own extras. Up to 8 per slide. |
boxes |
Moves and changes by part: { "glyph": { "hidden": true } } hides a part on that slide (never the logo, or a part holding a text the template needs). |
mesh |
With options.background: "mesh", the mesh made your own: { "colors": ["#7c3aed", "accent"], "strength": 1.2, "arrange": "diagonal", "flow": true }. colors up to 3 (palette names or #rrggbb), strength 0.3-1.5, arrange corners, diagonal, top, bottom, centre or scatter (with any seed number), flow (carousels) runs the glows on from slide to slide. |
text_style |
A text's own look, by key, only when you want one: { "headline": { "align": "center", "size": 1.2, "weight": "heavy", "case": "upper", "color": "highlight" } }. align left, center or right; size 0.7-1.5 (1 is the template's; long text still shrinks to fit); weight regular, bold or heavy; case upper or normal; color primary, accent, highlight, text, white, black or any #rrggbb; leading 0.7-1.8 (line spacing, times the template's: 1 keeps it); tracking -0.05 to 0.25 (letter spacing in em, added to the template's); backdrop shadow, dark, light or brand (behind the text, for photos); width 80-1200 (pixels). In a carousel, each slide takes its own text_style. |
options |
The template's design options, from the catalogue: background (plain, grid, mesh), navigation for carousels (arrows, progress, counter, classic, none), arrow (pill, circle, line), photo_edge (straight, torn). Only the ones the template lists; the rest keep its defaults. |
format |
square, portrait, story or landscape. Or give network for that network's usual size. |
photo_media_id / photo_url |
The photo, for templates that take one: an image in the brand's library, or a link to it (or to the page it's on). It goes on every slide with a photo spot that has none of its own. |
photo |
A one-image template's photo and its framing: { "id": "<media id>", "x": 50, "y": 30, "zoom": 1.4, "darken": 0.3, "look": "natural" }. x/y (0-100) is the point of the photo kept in view, zoom 1-3, darken 0-0.8, look natural, bw or tint (the brand colour). Where the photo sits on top of the slide (the catalogue's photo_edge: true layouts), also height (0.2-0.75 of the image), tilt (-10 to 10 degrees: the bottom edge slants, positive is lower on the right) and tear (any number: another tear shape, with options.photo_edge: "torn"). In a carousel, each slide takes its own photo. |
dry_run |
true: return the images as data: URIs and save nothing. |
The answer. With dry_run, 200 with images. Otherwise 201 with media, the images in the brand's media library in slide order.
What to fix. A 422 lists what to fix, keyed like the request:
1{
2 "message": "\"Headline\" is 112 characters; this template fits 100. Shorten it.",
3 "errors": {
4 "slides.0.text.headline": ["\"Headline\" is 112 characters; this template fits 100. Shorten it."],
5 "slides.0.photo": ["This template needs a photo."]
6 }
7}
Other keys: template, style, options.<name> (an option the template doesn't have, or a value it can't take), slides.N.boxes.<text>.highlight, brand_kit (the brand has no kit yet), slides.N.photo (a photo missing, or not in the brand's library) and slides.N (a problem with a slide as a whole). Text over a photo is measured too: "hard to read over the photo" means darken it, or move the text.
Making images is limited to 30 a minute per token.
#3. Post them
Post the media ids with POST /api/v1/posts, in order:
1POST /api/v1/posts
2{ "body": "…", "accounts": [34], "media": [{ "id": "…" }, { "id": "…" }], "when": "draft" }