Skip to main content

Quickstart: generate an image with the API

In about 5 minutes you will create an API key, find the design_id of one of your designs, make one API call and save the image it returns. You start with a new free account and finish with an image file on your machine.

You need: a free OKZest account with at least one design. New accounts come with a Sample Design, so you can start there, or see Quickstart: email image or Quickstart: social image to make your own. Each step has a live request panel: pick your language, fill in the form and select Send API Request to make the call from this page. To run the code yourself you need curl, Node.js 18 or later, or Python 3.

The API address is https://api.okzest.com, and every path starts with /v1.

1. Create an API key​

  1. Log in and open API keys.

  2. Select Create a key. This opens a full page, Create a new API key, not a pop-up. Type a name in API key name and select Generate key.

  3. The Copy new API key page shows your key. Copy it straight away. It is shown only once. Keep it private, like a password. Select Done when you have copied it.

  4. If you run the code on your machine, store the key in an environment variable so it stays out of your code:

    export OKZEST_APIKEY="paste-your-key-here"
  5. Check that it works. In the panel below, select Authorization, paste your key into the x-api-key field, then select Send API Request. The code samples update as you type, in the language you pick. Each panel has its own Authorization field, so paste your key again in the panels in the next steps.

    A good key returns status 200 and a small JSON object with your company id and the key name:

    {"company_id":"YOUR_COMPANY_ID","key_name":"Quickstart test"}
Use the x-api-key header

The key goes in a header called x-api-key. The usual Authorization: Bearer ... header does not work and returns 401.

The API keys page with a new key

2. Find your design_id​

Every design has a design_id. You can find it in either of these ways.

From the API. List your designs. Set pageSize to 3 to keep the response short:

The response is a JSON array. Each item has the design_id and the design's name. For example (trimmed):

[{"design_id":"yGguOj0cuEilNjtoAUZdYA","name":"Review test header","optional_url_params":[{"id":"first_name","merge_tag":""}]}]

The path says images even though it lists designs. That is expected.

From the browser address bar. Open the design in the editor or on its Share page. The address contains id= followed by the design_id, for example https://okzest.com/dashboard/share?id=YOUR_DESIGN_ID. The i= value in the image link is the same id.

Now find the layers you can change. Use optional_url_params[].id from the list above, or ask for the design's fields. Paste your design_id into the designId field:

In the example, the layer ID is first_name. (The Sample Design has two layers, name and image.) You will use it as the layer_id in the next step. Take both the design_id and the layer ID from your own design, because examples elsewhere in the docs use placeholder values. Use only letters, numbers and underscores in a layer ID, for example first_name or headline. The ID input also accepts hyphens and spaces, but they are awkward in URL parameters.

3. Make the image call​

Send a POST to /v1/images with the design_id and the text for each layer you want to change. Edit the request body in the panel, using your own design_id and layer ID:

A successful call returns status 200 and the image itself, not JSON. By default it is a JPEG. Add "format":"png" to the request body to get a PNG instead, and use a matching file name.

In the curl sample, -o image.jpg tells curl to save the response to a file. The panel shows a preview of the returned image after you select Send API Request.

A wrong layer ID is not an error

If the layer_id does not match a layer in your design, the call still returns 200 and a normal image, with no error and no personalisation. If your image shows the default text, check that the layer_id matches the layer ID in your design exactly, using the fields list from step 2.

4. Save the image​

The curl sample in the panel above saves image.jpg for you. Open it to see your personalised image. To do the same in code, use one of these. Both read your key from OKZEST_APIKEY and write the response to image.jpg. Replace YOUR_DESIGN_ID and first_name with your own design_id and layer ID.

JavaScript (Node.js 18 or later)

import { writeFile } from 'node:fs/promises';

const res = await fetch('https://api.okzest.com/v1/images', {
method: 'POST',
headers: {
'x-api-key': process.env.OKZEST_APIKEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({ design_id: 'YOUR_DESIGN_ID', layers: [{ layer_id: 'first_name', text: 'Sam' }] }),
});
if (!res.ok) throw new Error(`Request failed: ${res.status}`);
await writeFile('image.jpg', Buffer.from(await res.arrayBuffer()));

Python 3

import json, os, urllib.request

req = urllib.request.Request(
"https://api.okzest.com/v1/images",
data=json.dumps({"design_id": "YOUR_DESIGN_ID", "layers": [{"layer_id": "first_name", "text": "Sam"}]}).encode(),
headers={
"x-api-key": os.environ["OKZEST_APIKEY"],
"Content-Type": "application/json",
"User-Agent": "my-app/1.0",
},
)
with urllib.request.urlopen(req) as res, open("image.jpg", "wb") as f:
f.write(res.read())
Set a User-Agent in Python

Python's default urllib User-Agent is blocked and returns 403. Always set your own, for example User-Agent: my-app/1.0.

The personalised image showing the name Sam, fetched from the media URL

You now have a working image from the API.

If something goes wrong​

What you seeLikely cause
401The key is wrong or missing, or you used Authorization: Bearer instead of x-api-key
400 with Design not found.The design_id is wrong
400 saying design_id is missingThe request body has no design_id
415The Content-Type: application/json header is missing
403 from PythonNo custom User-Agent (see above)
200, but the image has no personalisationThe layer_id does not match a layer in your design. A wrong layer ID is ignored without an error, so check the spelling against the fields list

What next​