> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dockiln.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Migrate a PDFShift integration

> Map document inputs, conversion options and delivery behavior to the DocKiln review API.

## Choose the target build

These additions belong to the **1.1 review build**. Use a matching development or staging instance for the examples. The production rollout is separate. Existing async clients can continue to submit to `POST /v1/documents` and poll the job location.

| When your client uses | Send to DocKiln |
| - | - |
| HTML string or URL in `source` | One of `html`, `url`, or a published `templateId` |
| Output-specific endpoint | `format` set to `pdf`, `png`, `jpeg` or `webp` |
| Base64 or binary response | `response` set to `base64` or `binary`. Handle HTTP 202 after a four-second wait. |
| Temporary filename | `filename` sets the attachment name. `ttlSeconds` controls retention independently. |
| Multiple source entries | `POST /v1/documents/batch` with an `Idempotency-Key` and 1–8 entries in `items`. Inspect each entry in the 207 response. |
| Test credit exemption | `sandbox: true` adds a watermark and uses a separate 20-document monthly allowance. |
| Customer bucket delivery | Configure the workspace destination in Settings, then send `delivery: "object"`. |

## Print one order

On a review instance, create an API key in Settings. Set `DOCKILN_ORIGIN` to that instance and `DOCKILN_API_KEY` to your key in the local environment. Save the following as `print-order.mjs` and run `node print-order.mjs` with Node.js 24. The output, `order.pdf`, measures four by six inches and includes a sandbox watermark.

```js title="print-order.mjs" theme={null}
import { randomUUID } from "node:crypto";
import { writeFile } from "node:fs/promises";
import { setTimeout as wait } from "node:timers/promises";

const origin = process.env.DOCKILN_ORIGIN;
const key = process.env.DOCKILN_API_KEY;
if (!origin || !key) throw Error("Set DOCKILN_ORIGIN and DOCKILN_API_KEY.");
const headers = { authorization: "Bearer " + key };
const response = await fetch(new URL("/v1/documents", origin), {
  method: "POST",
  headers: {
    ...headers,
    "content-type": "application/json",
    "idempotency-key": randomUUID(),
  },
  body: JSON.stringify({
    html: "<h1>Order DK-104</h1><p>Two paper samples</p>",
    filename: "order.pdf",
    print: { width: "4in", height: "6in", margins: { top: "12mm" } },
    processing: { metadata: { title: "Order DK-104" } },
    sandbox: true,
    response: "binary",
  }),
});
let output = response;
if (response.status === 202) {
  const { id } = await response.json();
  for (let attempt = 0; attempt < 30; attempt++) {
    await wait(1000);
    const status = await fetch(new URL("/v1/documents/" + id, origin), {
      headers,
    });
    if (!status.ok) throw Error("Polling returned HTTP " + status.status);
    const job = await status.json();
    if (job.status === "failed") throw Error(job.error);
    if (job.download) {
      output = await fetch(new URL(job.download, origin), { headers });
      break;
    }
  }
}
if (
  !output.ok ||
  !output.headers.get("content-type")?.startsWith("application/pdf")
)
  throw Error("PDF unavailable. Check the job location and its status.");
await writeFile("order.pdf", Buffer.from(await output.arrayBuffer()));
```

## Reuse HTML with JSON data

Create a template with `kind: "html"`, a title, an optional lowercase slug, `html` and a sample JSON object. Use a double-braced field in a text node. A template element with `data-each` repeats its children using each row as the current object. A template with `data-if` includes its children when the value is truthy.

```html theme={null}
<h1>{{title}}</h1>
<ul>
  <template data-each="items"><li>{{label}}</li></template>
</ul>
```

DocKiln escapes substituted text. Dynamic attributes, raw HTML slots and script substitutions are unsupported. Publish with `POST /v1/templates/{id}/publish`. Use the slug or ID and optional version when creating a document. Download published source from `GET /v1/templates/{id}/raw`, or send a `data` object to `POST /v1/templates/{id}/html` for a populated HTML attachment.

## Decide what the renderer can load

Static conversions work with the default configuration. Dynamic execution needs the operator-enabled isolated renderer. Use `controls.javascript` to execute scripts and `externalAssets` for a bounded resource catalogue. Give exact HTTPS URLs in `assetUrls` for JSON data or other assets chosen at runtime. Iframes, live connections and arbitrary navigation are blocked. For readiness, use a selector or an expression such as `window.chartReady === true`. The expression runs inside the isolated page. Native lazy images can be made eager with `controls.lazyImages`.

For a protected HTTPS source, `sourceAuth` accepts Basic credentials, custom headers or a cookie map scoped to the source origin. Credentials are stripped across origins. The page receives no authentication cookie jar. Keep secrets in server-side environment variables.

## Protect and deliver output

Set `processing.protection.ownerPassword` and optionally `userPassword`. Set `copy`, `modify` and `print` to false to request reader restrictions. PDF readers decide how to enforce permissions. Set `sensitive: true` to encrypt queued input, suppress the submission log and default to one-hour output expiry. Other job history remains available.

S3, R2 and Google Cloud Storage destinations use a private customer bucket with workspace-scoped credentials. The customer Google bucket is independent of the service’s internal storage. Supply a storage prefix and restrict access to that prefix. Include delete permission when using output expiry. On completed customer deliveries, `GET /v1/documents/{id}/link` returns a five-minute signed download when the remaining retention permits it.

A per-job callback accepts a public HTTPS `url` without query parameters and a signing `secret` of 32–128 characters. Verify the timestamp and HMAC against the exact received bytes; store the event ID before performing non-repeatable actions. Failures retry on a bounded schedule. For troubleshooting, use the `X-Request-Id` response header and the session-only request log. Logs contain route metadata and omit bodies, query strings, cookies and key values.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.