C#
Generate images from a template with HttpClient and System.Text.Json from the base class library. Imejis returns the finished image directly in the response, so there is nothing to poll and no webhook to receive.
Set two environment variables first: IMEJIS_API_KEY (from your dashboard) and IMEJIS_DESIGN_ID (any design's id). Then send the fields you want to change as component.property pairs: headline.text, title.color, image.image. Only the fields you send change; everything else keeps its designed value, and a design's overridable fields are listed in its Share / API panel.
Every block below is a copy-paste runnable program, and every one of them is executed in Docker against a real render service before it ships.
Generate a single imageGenerate a single image
One POST, one image. The response body is the rendered image itself, with nothing to poll and no webhook to receive.
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Web;
var apiKey = Environment.GetEnvironmentVariable("IMEJIS_API_KEY")!;
var designId = Environment.GetEnvironmentVariable("IMEJIS_DESIGN_ID")!;
var baseUrl = Environment.GetEnvironmentVariable("IMEJIS_RENDER_URL")
?? "https://render.imejis.io";
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("dma-api-key", apiKey);
// POST a JSON body to `path` with the render key.
async Task<HttpResponseMessage> Render(string path, string query, object body)
{
var url = baseUrl + path + (query.Length == 0 ? "" : "?" + query);
var content = new StringContent(
JsonSerializer.Serialize(body), Encoding.UTF8, "application/json");
return await client.PostAsync(url, content);
}
// Build a query string from alternating key/value pairs.
string Query(params string[] pairs)
{
var parts = new List<string>();
for (var i = 0; i < pairs.Length; i += 2)
{
parts.Add($"{HttpUtility.UrlEncode(pairs[i])}={HttpUtility.UrlEncode(pairs[i + 1])}");
}
return string.Join("&", parts);
}
// The size to render on a multi-size design; absent/"master" is the base.
var variation = Environment.GetEnvironmentVariable("IMEJIS_VARIATION_ID") ?? "story";
// Render one image. The response body IS the image — no polling, no webhook.
var res = await Render($"/v1/{designId}", "", new Dictionary<string, string>
{
["headline.text"] = "Hello from C#",
["subtitle.text"] = "Rendered in one request",
});
var image = await res.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("output.jpg", image);
Console.WriteLine($"single: {(int)res.StatusCode} {image.Length} bytes");Every output format png jpeg webp and pdfEvery output format: PNG, JPEG, WebP and PDF
Pick the output with ?format=. PNG and WebP keep transparency, JPEG is the smallest lossy option, and PDF is a single print-ready page. ?quality= applies to JPEG only.
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Web;
var apiKey = Environment.GetEnvironmentVariable("IMEJIS_API_KEY")!;
var designId = Environment.GetEnvironmentVariable("IMEJIS_DESIGN_ID")!;
var baseUrl = Environment.GetEnvironmentVariable("IMEJIS_RENDER_URL")
?? "https://render.imejis.io";
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("dma-api-key", apiKey);
// POST a JSON body to `path` with the render key.
async Task<HttpResponseMessage> Render(string path, string query, object body)
{
var url = baseUrl + path + (query.Length == 0 ? "" : "?" + query);
var content = new StringContent(
JsonSerializer.Serialize(body), Encoding.UTF8, "application/json");
return await client.PostAsync(url, content);
}
// Build a query string from alternating key/value pairs.
string Query(params string[] pairs)
{
var parts = new List<string>();
for (var i = 0; i < pairs.Length; i += 2)
{
parts.Add($"{HttpUtility.UrlEncode(pairs[i])}={HttpUtility.UrlEncode(pairs[i + 1])}");
}
return string.Join("&", parts);
}
// The size to render on a multi-size design; absent/"master" is the base.
var variation = Environment.GetEnvironmentVariable("IMEJIS_VARIATION_ID") ?? "story";
// Every output format, with JPEG quality. PNG and WebP keep transparency; PDF
// is a single print-ready page. quality only affects JPEG.
foreach (var format in new[] { "png", "jpeg", "webp", "pdf" })
{
var q = format == "jpeg"
? Query("format", format, "quality", "85")
: Query("format", format);
var r = await Render($"/v1/{designId}", q, new Dictionary<string, string>
{
["headline.text"] = $"Format: {format}",
});
var bytes = await r.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync($"output.{format}", bytes);
Console.WriteLine(
$"formats: {format} {r.Content.Headers.ContentType} {bytes.Length}");
}Render multiple sizes from one templateRender multiple sizes from one template
A multi-size design carries several canvases: an OG image, a square post, a vertical story. ?variation=<id> picks which one you get back; omit it for the base size.
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Web;
var apiKey = Environment.GetEnvironmentVariable("IMEJIS_API_KEY")!;
var designId = Environment.GetEnvironmentVariable("IMEJIS_DESIGN_ID")!;
var baseUrl = Environment.GetEnvironmentVariable("IMEJIS_RENDER_URL")
?? "https://render.imejis.io";
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("dma-api-key", apiKey);
// POST a JSON body to `path` with the render key.
async Task<HttpResponseMessage> Render(string path, string query, object body)
{
var url = baseUrl + path + (query.Length == 0 ? "" : "?" + query);
var content = new StringContent(
JsonSerializer.Serialize(body), Encoding.UTF8, "application/json");
return await client.PostAsync(url, content);
}
// Build a query string from alternating key/value pairs.
string Query(params string[] pairs)
{
var parts = new List<string>();
for (var i = 0; i < pairs.Length; i += 2)
{
parts.Add($"{HttpUtility.UrlEncode(pairs[i])}={HttpUtility.UrlEncode(pairs[i + 1])}");
}
return string.Join("&", parts);
}
// The size to render on a multi-size design; absent/"master" is the base.
var variation = Environment.GetEnvironmentVariable("IMEJIS_VARIATION_ID") ?? "story";
// One template, many sizes. ?variation=<id> picks the size; omit it for the
// base. The ids are listed in the design's Share / API panel.
var sized = await Render($"/v1/{designId}",
Query("format", "png", "variation", variation),
new Dictionary<string, string> { ["headline.text"] = "Story size" });
var sizedBytes = await sized.Content.ReadAsByteArrayAsync();
Console.WriteLine($"variation: {(int)sized.StatusCode} {sizedBytes.Length} bytes");An image url for img tags email and thumbnailsAn image URL for <img> tags, email and thumbnails
The same render as a plain GET URL, with the field values in the query string. Drop it into an <img src>, an HTML email, or a Slack message and it renders fresh every time it is fetched.
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Web;
var apiKey = Environment.GetEnvironmentVariable("IMEJIS_API_KEY")!;
var designId = Environment.GetEnvironmentVariable("IMEJIS_DESIGN_ID")!;
var baseUrl = Environment.GetEnvironmentVariable("IMEJIS_RENDER_URL")
?? "https://render.imejis.io";
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("dma-api-key", apiKey);
// POST a JSON body to `path` with the render key.
async Task<HttpResponseMessage> Render(string path, string query, object body)
{
var url = baseUrl + path + (query.Length == 0 ? "" : "?" + query);
var content = new StringContent(
JsonSerializer.Serialize(body), Encoding.UTF8, "application/json");
return await client.PostAsync(url, content);
}
// Build a query string from alternating key/value pairs.
string Query(params string[] pairs)
{
var parts = new List<string>();
for (var i = 0; i < pairs.Length; i += 2)
{
parts.Add($"{HttpUtility.UrlEncode(pairs[i])}={HttpUtility.UrlEncode(pairs[i + 1])}");
}
return string.Join("&", parts);
}
// The size to render on a multi-size design; absent/"master" is the base.
var variation = Environment.GetEnvironmentVariable("IMEJIS_VARIATION_ID") ?? "story";
// The same render as a plain GET URL — drop it into an <img> tag, an HTML
// email, or a Slack message. Field overrides ride the query string.
var getUrl = $"{baseUrl}/v1/{designId}?" + Query(
"dma-api-key", apiKey,
"format", "png",
"headline.text", "Hello from a URL",
"subtitle.text", "No request body needed");
Console.WriteLine($"get: {getUrl}");
var viaUrl = await client.GetAsync(getUrl);
var urlBytes = await viaUrl.Content.ReadAsByteArrayAsync();
Console.WriteLine($"get: {(int)viaUrl.StatusCode} {urlBytes.Length} bytes");Hosted delivery get a public image url backHosted delivery: get a public image URL back
?delivery=hosted stores the render and returns a public URL instead of raw bytes, which is what an email, a webhook payload, or a dashboard needs: a link rather than a file.
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Web;
var apiKey = Environment.GetEnvironmentVariable("IMEJIS_API_KEY")!;
var designId = Environment.GetEnvironmentVariable("IMEJIS_DESIGN_ID")!;
var baseUrl = Environment.GetEnvironmentVariable("IMEJIS_RENDER_URL")
?? "https://render.imejis.io";
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("dma-api-key", apiKey);
// POST a JSON body to `path` with the render key.
async Task<HttpResponseMessage> Render(string path, string query, object body)
{
var url = baseUrl + path + (query.Length == 0 ? "" : "?" + query);
var content = new StringContent(
JsonSerializer.Serialize(body), Encoding.UTF8, "application/json");
return await client.PostAsync(url, content);
}
// Build a query string from alternating key/value pairs.
string Query(params string[] pairs)
{
var parts = new List<string>();
for (var i = 0; i < pairs.Length; i += 2)
{
parts.Add($"{HttpUtility.UrlEncode(pairs[i])}={HttpUtility.UrlEncode(pairs[i + 1])}");
}
return string.Join("&", parts);
}
// The size to render on a multi-size design; absent/"master" is the base.
var variation = Environment.GetEnvironmentVariable("IMEJIS_VARIATION_ID") ?? "story";
// delivery=hosted stores the render and returns a PUBLIC URL instead of bytes —
// for an email, a webhook payload, or a dashboard that needs a link.
var hostedRes = await Render($"/v1/{designId}",
Query("delivery", "hosted", "format", "png"),
new Dictionary<string, string> { ["headline.text"] = "Hosted delivery" });
var hosted = JsonNode.Parse(await hostedRes.Content.ReadAsStringAsync())!;
Console.WriteLine($"hosted: {hosted["url"]} {hosted["file"]!["size"]} bytes");Signed delivery a private expiring image urlSigned delivery: a private, expiring image URL
?delivery=signed stores the render privately and returns a time-limited signed URL. ?expiresIn= is minutes.
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Web;
var apiKey = Environment.GetEnvironmentVariable("IMEJIS_API_KEY")!;
var designId = Environment.GetEnvironmentVariable("IMEJIS_DESIGN_ID")!;
var baseUrl = Environment.GetEnvironmentVariable("IMEJIS_RENDER_URL")
?? "https://render.imejis.io";
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("dma-api-key", apiKey);
// POST a JSON body to `path` with the render key.
async Task<HttpResponseMessage> Render(string path, string query, object body)
{
var url = baseUrl + path + (query.Length == 0 ? "" : "?" + query);
var content = new StringContent(
JsonSerializer.Serialize(body), Encoding.UTF8, "application/json");
return await client.PostAsync(url, content);
}
// Build a query string from alternating key/value pairs.
string Query(params string[] pairs)
{
var parts = new List<string>();
for (var i = 0; i < pairs.Length; i += 2)
{
parts.Add($"{HttpUtility.UrlEncode(pairs[i])}={HttpUtility.UrlEncode(pairs[i + 1])}");
}
return string.Join("&", parts);
}
// The size to render on a multi-size design; absent/"master" is the base.
var variation = Environment.GetEnvironmentVariable("IMEJIS_VARIATION_ID") ?? "story";
// delivery=signed stores it privately and returns a time-limited signed URL.
// expiresIn is minutes (default 60, max 7 days).
var signedRes = await Render($"/v1/{designId}",
Query("delivery", "signed", "format", "png", "expiresIn", "30"),
new Dictionary<string, string> { ["headline.text"] = "Signed delivery" });
var signed = JsonNode.Parse(await signedRes.Content.ReadAsStringAsync())!;
Console.WriteLine(
$"signed: {signed["expiresAt"]} {signed["url"]!.ToString()[..80]}...");Bulk image generation in one callBulk image generation in one call
POST /bulk to render many images in a single request: several sizes, several data variants, a mix of designs, or the ordered slides of a carousel. results preserves input order, so results[i] is items[i].
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Web;
var apiKey = Environment.GetEnvironmentVariable("IMEJIS_API_KEY")!;
var designId = Environment.GetEnvironmentVariable("IMEJIS_DESIGN_ID")!;
var baseUrl = Environment.GetEnvironmentVariable("IMEJIS_RENDER_URL")
?? "https://render.imejis.io";
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("dma-api-key", apiKey);
// POST a JSON body to `path` with the render key.
async Task<HttpResponseMessage> Render(string path, string query, object body)
{
var url = baseUrl + path + (query.Length == 0 ? "" : "?" + query);
var content = new StringContent(
JsonSerializer.Serialize(body), Encoding.UTF8, "application/json");
return await client.PostAsync(url, content);
}
// Build a query string from alternating key/value pairs.
string Query(params string[] pairs)
{
var parts = new List<string>();
for (var i = 0; i < pairs.Length; i += 2)
{
parts.Add($"{HttpUtility.UrlEncode(pairs[i])}={HttpUtility.UrlEncode(pairs[i + 1])}");
}
return string.Join("&", parts);
}
// The size to render on a multi-size design; absent/"master" is the base.
var variation = Environment.GetEnvironmentVariable("IMEJIS_VARIATION_ID") ?? "story";
// Many images in ONE call. results keeps input order, so results[i] is items[i]
// — for a carousel the array IS the slide order. Each item is one metered
// render, and a failed item does not abort the rest.
var bulkRes = await Render("/bulk", "", new Dictionary<string, object>
{
["delivery"] = "hosted",
["format"] = "png",
["items"] = new object[]
{
new Dictionary<string, object>
{
["designId"] = designId,
["overrides"] = new Dictionary<string, string> { ["headline.text"] = "Slide 1" },
},
new Dictionary<string, object>
{
["designId"] = designId,
["variation"] = variation,
["format"] = "jpeg",
["quality"] = 80,
["overrides"] = new Dictionary<string, string> { ["headline.text"] = "Slide 2" },
},
new Dictionary<string, object>
{
["designId"] = designId,
["format"] = "pdf",
["overrides"] = new Dictionary<string, string> { ["headline.text"] = "Slide 3" },
},
},
});
var bulk = JsonNode.Parse(await bulkRes.Content.ReadAsStringAsync())!;
Console.WriteLine($"bulk: {bulk["summary"]!.ToJsonString()}");
foreach (var item in bulk["results"]!.AsArray())
{
Console.WriteLine($" {item!["index"]} {item["format"]} {item["url"] ?? item["error"]}");
}Bulk from a list of rowsBulk from a list of rows
Send data instead of items and every row becomes one render, with no item list to build. That is the shape to reach for when the input is a spreadsheet, a database query, or a CSV.
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Web;
var apiKey = Environment.GetEnvironmentVariable("IMEJIS_API_KEY")!;
var designId = Environment.GetEnvironmentVariable("IMEJIS_DESIGN_ID")!;
var baseUrl = Environment.GetEnvironmentVariable("IMEJIS_RENDER_URL")
?? "https://render.imejis.io";
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("dma-api-key", apiKey);
// POST a JSON body to `path` with the render key.
async Task<HttpResponseMessage> Render(string path, string query, object body)
{
var url = baseUrl + path + (query.Length == 0 ? "" : "?" + query);
var content = new StringContent(
JsonSerializer.Serialize(body), Encoding.UTF8, "application/json");
return await client.PostAsync(url, content);
}
// Build a query string from alternating key/value pairs.
string Query(params string[] pairs)
{
var parts = new List<string>();
for (var i = 0; i < pairs.Length; i += 2)
{
parts.Add($"{HttpUtility.UrlEncode(pairs[i])}={HttpUtility.UrlEncode(pairs[i + 1])}");
}
return string.Join("&", parts);
}
// The size to render on a multi-size design; absent/"master" is the base.
var variation = Environment.GetEnvironmentVariable("IMEJIS_VARIATION_ID") ?? "story";
// The same design over a LIST OF ROWS — one render per row, no items[] to
// build. Use "variations" = ["master","story"] instead to render every SIZE.
var rowsRes = await Render("/bulk", "", new Dictionary<string, object>
{
["designId"] = designId,
["delivery"] = "signed",
["expiresIn"] = 15,
["format"] = "png",
["data"] = new object[]
{
new Dictionary<string, string>
{
["headline.text"] = "Ada Lovelace", ["subtitle.text"] = "Mathematician",
},
new Dictionary<string, string>
{
["headline.text"] = "Alan Turing", ["subtitle.text"] = "Computer scientist",
},
new Dictionary<string, string>
{
["headline.text"] = "Grace Hopper", ["subtitle.text"] = "Rear admiral",
},
},
});
var rows = JsonNode.Parse(await rowsRes.Content.ReadAsStringAsync())!;
Console.WriteLine($"bulk-data: {rows["summary"]!.ToJsonString()}");The response is the raw image (`image/jpeg` by default). Choose the format with `?format=png|jpeg|webp|pdf` (default jpeg) and set JPEG quality with `?quality=1-100`. Store the result and get a URL back with `?delivery=hosted` (or `?delivery=signed&expiresIn=60`), and render a specific size of a multi-size design with `?variation=<id>`.
| Parameter | Values | Default | What it does |
|---|---|---|---|
?format= | png · jpeg · webp · pdf | jpeg | Output image format. |
?quality= | 1–100 | none | Compression quality for lossy output; ignored for other formats. (JPEG only) |
?delivery= | stream · hosted · signed | stream | stream = raw image bytes (default); hosted = store + return a public URL; signed = store + return a time-limited URL. |
?expiresIn= | minutes | 60 | Signed-URL lifetime in minutes (default 60, max 10080 = 7 days). (delivery=signed only) |
?variation= | <size id> | master | Which multi-dimension SIZE to render. Omit or use "master" for the base size; an unknown id falls back to the master. (multi-size designs only) |
- PNG (
?format=png): Lossless, supports transparency. Largest file. - JPEG (
?format=jpeg): Smaller, lossy, no transparency. Quality adjustable. - WebP (
?format=webp): Smallest, supports transparency. Modern browsers. - PDF (
?format=pdf): Vector page, for print and documents.
See the delivery modes and generate images with the API guides.
In a web app the same call becomes a minimal-API handler: the ASP.NET Core page has all five. Create HttpClient once and reuse it, or use IHttpClientFactory; a new client per render exhausts sockets under load. One render per call, 100 free a month, then pricing.