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

# Quickstart

> Generate your first document in under 5 minutes.

This guide walks you through generating a PDF document end-to-end.

## Prerequisites

* A Platendoc account ([sign up free](https://app.platendoc.com/signup))
* A published template with at least one version
* An API key with `generations:trigger` and `generations:read` scopes

## 1. Get your template ID

In the portal, open your template and copy the ID from the URL or the template settings. It looks like `tpl_01j8z...`.

## 2. Create a generation

```bash theme={null}
curl -X POST https://api.platendoc.com/v1/generations \
  -H "Authorization: Bearer pdc_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "templateId": "tpl_01j8z...",
    "format": "pdf",
    "variables": {
      "customerName": "Acme Corp",
      "invoiceNumber": "INV-0042",
      "amount": "1,250.00"
    }
  }'
```

The API responds immediately with a `PENDING` generation:

```json theme={null}
{
  "id": "gen_01j8z...",
  "status": "PENDING",
  "format": "PDF",
  "outputUrl": null,
  ...
}
```

## 3. Poll for completion

Fetch the generation by ID until `status` is `COMPLETED`:

```bash theme={null}
curl https://api.platendoc.com/v1/generations/gen_01j8z... \
  -H "Authorization: Bearer pdc_live_YOUR_KEY"
```

```json theme={null}
{
  "id": "gen_01j8z...",
  "status": "COMPLETED",
  "outputUrl": "https://...",
  ...
}
```

<Tip>
  Most generations complete in 2–5 seconds. Poll with a 1-second interval and a 30-second timeout.
</Tip>

## 4. Download the document

The `outputUrl` is a pre-signed URL valid for **1 hour**. Download it directly:

```bash theme={null}
curl -L "https://..." -o invoice.pdf
```

## Full example (Node.js)

```typescript theme={null}
import fetch from 'node-fetch'

const API_KEY = process.env.PLATENDOC_API_KEY
const BASE = 'https://api.platendoc.com/v1'

async function generateDocument(templateId: string, variables: Record<string, unknown>) {
  // 1. Create generation
  const createRes = await fetch(`${BASE}/generations`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ templateId, format: 'pdf', variables }),
  })
  const { id } = await createRes.json()

  // 2. Poll until complete
  let generation
  for (let i = 0; i < 30; i++) {
    await new Promise((r) => setTimeout(r, 1000))
    const res = await fetch(`${BASE}/generations/${id}`, {
      headers: { Authorization: `Bearer ${API_KEY}` },
    })
    generation = await res.json()
    if (generation.status === 'COMPLETED' || generation.status === 'FAILED') break
  }

  if (generation.status !== 'COMPLETED') {
    throw new Error(`Generation failed: ${generation.error}`)
  }

  return generation.outputUrl
}
```

## Error handling

If the generation fails, `status` will be `FAILED` and the `error` field describes what went wrong:

```json theme={null}
{
  "status": "FAILED",
  "error": "Template rendering failed: unknown variable 'customerNme'."
}
```

Common causes:

* Typo in a variable name
* Template has no published version
* Template was archived after the generation was created
