Thumbnails
Get preview images of the first page of your resources through the Print & Mail API, generated automatically whenever a resource is saved.
A thumbnail is a JPEG preview of the first page of a resource, so you can show your users what it looks like without rendering it yourself. PostGrid generates thumbnails automatically.
Note: Thumbnails are in early access and must be enabled for your organization. Contact [email protected] to request access. Until they are enabled, requests return a
template_thumbnails_disabled_error.
Supported Resources
Section titled “Supported Resources”Thumbnails are currently generated for templates only, so resources and
id take template IDs (template_...). Other resources will be added to the
same endpoint and object.
How Thumbnails Are Generated
Section titled “How Thumbnails Are Generated”Once thumbnails are enabled for your organization, PostGrid checks every minute for resources that need a new thumbnail:
- Existing resources all get a thumbnail on the first check after the feature is enabled. For an organization with many resources this backfill can take several minutes.
- New and updated resources get a new thumbnail within about a minute of being created or saved. A resource saved several times within a minute is rendered once.
- Archived and deleted resources are not rendered. Deleting a resource removes its thumbnail.
Resources are rendered in both live and test mode.
What a Thumbnail Shows
Section titled “What a Thumbnail Shows”- The first page of the resource.
- An image 800 pixels wide. The height follows the page’s aspect ratio, so a US Letter page is 800 x 1035 pixels.
- The design only. No merge variables are filled in, so placeholders such as
{{to.firstName}}appear as written.
Because merge variables are left empty, anything whose URL depends on one won’t
load. For example, an image with src="https://cdn.example.com/{{logo}}.png"
shows as a missing image, and a stylesheet or font loaded from such a URL falls
back to the default styling. The rest of the thumbnail is still generated, and
orders created from the resource are not affected.
Getting Started
Section titled “Getting Started”To use the Thumbnails API, you will need your PostGrid API key. You can find your API key on your PostGrid dashboard settings page.
Requests are made to:
https://api.postgrid.com/print-mail/v1/thumbnailsAuthenticate by passing your API key in the x-api-key header.
Thumbnails are scoped to the mode of your API key: a test-mode key only returns thumbnails of test-mode resources, and a live-mode key only returns thumbnails of live-mode resources.
The Thumbnail Object
Section titled “The Thumbnail Object”| Field | Type | Description |
|---|---|---|
id | string | The ID of the resource this thumbnail is for. See Supported Resources. |
object | string | Always thumbnail. |
status | string | The status of the latest render: generating, generated, or failed. See Statuses below. |
medium | string | Optional. A signed, temporary URL to the JPEG. Absent until the resource’s first render has finished. The link expires after 15 minutes — see Image URLs. |
Statuses
Section titled “Statuses”| Status | Meaning |
|---|---|
generating | A render is queued or running. If the resource had a thumbnail before, medium still points to the previous image until the new one is ready. |
generated | The latest version of the resource has been rendered and medium points to it. |
failed | The latest render failed. It is not retried until the resource is saved again. If an earlier render succeeded, medium still points to that image, which may be out of date. |
Get Thumbnails
Section titled “Get Thumbnails”Send a GET request to /thumbnails with the IDs of up to 100 resources in the
resources query parameter, separated by commas. See the
API Reference for the full
request and response schema.
curl "https://api.postgrid.com/print-mail/v1/thumbnails?resources=template_pxd7wnnD1xY6H6etKNvjb4,template_7mhJUt25TnagyYzy1N81SJ" \ -H "x-api-key: <your-api-key>"Query Parameters
Section titled “Query Parameters”| Parameter | Type | Description |
|---|---|---|
resources | string | Required. Between 1 and 100 resource IDs, separated by commas. Spaces and empty items are ignored. The array forms (resources[]=...) are not accepted. See Supported Resources. |
Response
Section titled “Response”{ "object": "list", "data": [ { "id": "template_pxd7wnnD1xY6H6etKNvjb4", "object": "thumbnail", "status": "generated", "medium": "https://pg-prod-bucket-1.s3.amazonaws.com/thumbnails/...medium.jpg?X-Amz-Expires=900&X-Amz-Signature=..." }, { "id": "template_7mhJUt25TnagyYzy1N81SJ", "object": "thumbnail", "status": "generating" } ]}data holds the thumbnails of the requested resources that have one, in no
particular order, so match them to your resources by id. An ID is left out of
data, without an error, when:
- the resource doesn’t have a thumbnail yet (for example, it was created less than a minute ago), or
- the resource is deleted, doesn’t exist, or belongs to another organization or mode.
This endpoint isn’t paginated: the response has no skip, limit or
totalCount, and every thumbnail found is returned at once.
Image URLs
Section titled “Image URLs”medium is a signed URL that expires 15 minutes after the request. Each
response returns a fresh URL.
Rate Limits and Polling
Section titled “Rate Limits and Polling”This endpoint is limited to 10 requests per minute. Requests above the limit
return a 429 with a rate_limit_exceeded_error.
To stay within the limit:
- Request the thumbnails for a whole page of resources (up to 100) in one call, instead of one call per resource.
- After saving a resource, wait about a minute before checking for its new
thumbnail, then poll no more than every 10–15 seconds until its
statusisgeneratedorfailed.
Errors
Section titled “Errors”| Status | Type | When |
|---|---|---|
400 | validation_error | resources is missing, has more than 100 IDs, uses the array form, or contains an ID of a resource that isn’t supported yet. |
401 | missing_auth_error | The API key is missing or invalid. |
403 | template_thumbnails_disabled_error | Thumbnails are not enabled for your organization. Contact [email protected]. |
403 | permission_missing_error | The API key’s user doesn’t have the thumbnails:read permission. |
429 | rate_limit_exceeded_error | More than 10 requests in a minute. See Rate Limits and Polling. |
See Errors for the shape of error responses.