# How to Automate Document Generation via API

> Automate document generation with an API. Generate NDAs and other contracts as PDFs from your app or CRM in a step by step tutorial with real screens

- **Author**: Rishi Mohan
- **Published**: 2026-10-24
- **Tags**: Document Generation, PDF, Contracts, API, HubSpot
- **Read time**: 7 min read
- **URL**: https://orshot.com/blog/document-generation-api

---

To automate document generation via API, design a template once and send only the changing data in each request. A document generation API merges the two and returns a finished PDF, like a contract or an invoice.

Below I build a two-page mutual NDA in Orshot and generate it from code, HubSpot or n8n, with a real screen for each step. The same steps work for [invoices, offer letters and certificates](#1-design-the-document-template-in-orshot-studio).

The finished NDA came back in 1.5 seconds as a two-page PDF. It has selectable text, a "Page 1 of 2" footer and the signature block on page 2.

![An Orshot render request with the NDA template ID and contract fields like effective date, company, counterparty, purpose, term and signers, and the two-page mutual NDA PDF it returns with selectable text](https://orshot.com/blog/document-generation-api/request-to-pdf.webp)

| Step | Where you do it | What you get |
| --- | --- | --- |
| 1. Design the template | Orshot Studio | A template with flowing pages |
| 2. Mark the fields | Studio API tab | One key per placeholder |
| 3. Test it | Template page, Connect | A real PDF in the dashboard |
| 4 to 6. Automate it | Your code, HubSpot, n8n | A PDF URL, ready to sign |

## What Is Document Generation

Document generation is the automatic creation of documents like contracts, invoices and letters from a template plus data. Template-based document generation keeps the layout and wording fixed and fills only the dynamic fields.

A document generation API does this over HTTP. Your app, CRM or workflow tool sends names, dates and terms, and gets a finished file back. That is what makes it automated document generation instead of copy and paste.

Because each document is one request, the same template handles one NDA a week or a high-volume run. Bulk document generation is a loop over your rows in code, n8n, Make or Zapier.

Contract software is a different tool. It handles drafting, redlines and approvals. A document generation API only makes the file, so it fits when your wording is settled and the data already lives in your app or CRM.

![How a document generation API works in Orshot: the NDA template with 12 fields, a JSON body with the contract data, one POST request to /v1/studio/render, and the two-page PDF that comes back, ready for e-signature, a CRM record or storage](https://orshot.com/blog/document-generation-api/how-it-works.webp)

## 1. Design the Document Template in Orshot Studio

Orshot Studio is the template editor. Every document in it, from an NDA to an invoice, is a template with a fixed layout and fields that change per file.

Disclosure: I built Orshot. Every step below was run on October 24, 2026.

I made four templates for this post: an NDA, an invoice, an offer letter and a certificate. The steps below use the NDA, and the same steps work for the other three.

![Four documents generated from Orshot templates: a two-page mutual NDA, an invoice with four line items, a job offer letter and a landscape certificate of completion](https://orshot.com/blog/document-generation-api/document-gallery.webp)

| Document | What changes per file | Template |
| --- | --- | --- |
| Invoice | Client, dates, line items, totals | [Copy the invoice](https://orshot.com/templates/shared/frnnpg3o/preview?view=play) |
| Offer letter | Role, start date, salary, equity | [Copy the offer letter](https://orshot.com/templates/shared/vhhcg50o/preview?view=play) |
| Certificate | Recipient, course, date, signer | [Copy the certificate](https://orshot.com/templates/shared/qjz6s040/preview?view=play) |

The offer letter uses inline fields like the NDA, so the letter text stays in one layer. The invoice has four fixed rows with one field per cell. Add rows in Studio if your invoices run longer.

### Step 1: Lay Out the First Page

I used a 1000 by 1414 pixel canvas, the A4 ratio. The NDA header has a logo, the company name and an agreement number. Under the title sits one text box with every clause and the signature lines.

![The mutual NDA template in Orshot Studio in three parts: a fixed header and title, one agreement body text layer set to Flow with fields like effective_date and counterparty_name, and a footer that repeats on every page with Page X of Y](https://orshot.com/blog/document-generation-api/template-anatomy.webp)

### Step 2: Set the Agreement Body to Flow

Select the agreement text and set **Text Autofit** to **Flow** in the Styles panel.

Flow mode moves text that doesn't fit onto new pages. A short NDA stays at one page and a long one gets as many pages as it needs.

![Orshot Studio with the mutual NDA template open, the agreement body selected, Text Autofit set to Flow, a Flow Preview button on the canvas and the layer's API field name nda](https://orshot.com/blog/document-generation-api/studio-flow-layer.webp)

### Step 3: Repeat the Footer and Number the Pages

Turn on **Repeat on extra pages** for the footer layers. Then write `Page {{_page_number}} of {{_total_pages}}` in the footer text, and Orshot fills in the numbers on every page.

The **Flow Preview** button shows the pages before you render. Its settings set the top margin on extra pages and keep at least two lines together at a page break.

![The Orshot Flow Preview for the NDA showing 2 pages total, with Flow Settings for a 90 px top margin and 134 px bottom margin on extra pages, split by line, and at least 2 lines at the end and start of a page](https://orshot.com/blog/document-generation-api/flow-settings.webp)

The [flowing content docs](https://orshot.com/docs/orshot-studio/flowing-content) cover flow zones and break rules in more detail.

## 2. Mark the Fields That Change per Contract

Type each changing value as a placeholder in double braces inside the clause text, like `{{effective_date}}` or `{{counterparty_name}}`. Then open the **API** tab, switch on **Parameterize** and give the layer an ID. I used `nda`.

Orshot then lists every placeholder as its own key: `nda:effective_date`, `nda:company_name` and so on. Your API call sends only those values, never the wording around them.

![The Orshot Studio API tab for the NDA body with Parameterize on, Parameter ID nda, and API usage examples listing inline keys like nda:effective_date, nda:company_name, nda:company_address and nda:counterparty_name](https://orshot.com/blog/document-generation-api/api-tab-fields.webp)

**Copy this NDA template free** — Copy the mutual NDA into a free Orshot workspace, then swap in your logo, clauses and fields. No credit card required.

[Copy template](https://orshot.com/templates/shared/utvzb1ug/preview?view=play)

## 3. Test the Contract from the Dashboard

Open the template's page and click **Connect**. The API tab holds a request you can edit and run, so you see the real PDF before writing any code.

I pasted my NDA values, picked PDF and ran it. Both pages showed up in the preview, and the API's own timer read 1.5 seconds.

![The Orshot Connect panel with the NDA render request filled in for Northwind Labs and Brightline Analytics, response format PDF, and a live preview of the two-page PDF that rendered in 1.9 seconds](https://orshot.com/blog/document-generation-api/test-render.webp)

Each run uses credits, 1 per PDF page. This test used 2.

## 4. Generate the PDF from Your App

Your app sends the same request to `POST /v1/studio/render` with the template ID and the contract fields. Keep the API key on your server.

```javascript
const res = await fetch("https://api.orshot.com/v1/studio/render", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: `Bearer ${process.env.ORSHOT_API_KEY}`,
  },
  body: JSON.stringify({
    templateId: 29275, // your copy of the NDA template
    modifications: {
      "nda:effective_date": deal.signedOn, // "October 24, 2026"
      "nda:company_name": "Northwind Labs Inc.",
      "nda:company_address": "500 Market Street, San Francisco, CA 94105",
      "nda:counterparty_name": deal.company,
      "nda:counterparty_address": deal.address,
      "nda:purpose": "a possible data partnership",
      "nda:term_years": "two (2)",
      "nda:governing_state": "Delaware",
      "nda:company_signer": "Maya Chen",
      "nda:company_signer_title": "COO",
      "nda:counterparty_signer": deal.contactName,
      "nda:counterparty_signer_title": deal.contactTitle,
    },
    response: { type: "url", format: "pdf" },
  }),
});
const { data } = await res.json();
```

The response is short. `data.content` is the PDF's URL, which you save on the contract record or hand to the signing step.

```json
{
  "data": {
    "content": "https://storage.orshot.com/cloud/w-11/renders/images/jkRJIARKkBq.pdf",
    "type": "url",
    "format": "pdf",
    "responseTime": 1493.86
  }
}
```

Paid plans can also push each file to your own storage bucket.

## 5. Generate Contracts from HubSpot, n8n, Make or Zapier

If the contract data sits in HubSpot, the Orshot workflow action makes the same call without code. Trigger it when a deal reaches a stage like "Contract sent", then map deal properties to the `nda:` fields.

The action can save the PDF to HubSpot's File Manager and write its URL onto a deal property. The [HubSpot integration docs](https://orshot.com/docs/integrations/hubspot) show the setup.

![A HubSpot workflow that generates the NDA: the deal moves to Contract sent, the Orshot action renders the template, the PDF is saved in HubSpot File Manager and its link is written to a deal property, with the same template usable from n8n, Make and Zapier](https://orshot.com/blog/document-generation-api/crm-flow.webp)

In n8n, Make and Zapier, the Orshot step takes the same template ID and fields. The trigger can be a form, a new database row or a signed-up customer.

## 6. Send the PDF for Signature

Orshot makes the contract but doesn't collect signatures. Pass the PDF to your e-signature tool in the next step of the same workflow.

The PDF has real text, not a picture of text. E-signature tools that place fields by searching the document can find each "Signature:" line. DocuSign calls this [anchor tagging](https://developers.docusign.com/docs/esign-rest-api/esign101/concepts/tabs/auto-place/ "target=_blank rel=nofollow").

![The signature block on page 2 of the generated NDA with each Signature line highlighted as searchable text, next to the three things the signing step does: get the PDF URL, search for the anchor text and add a sign-here field](https://orshot.com/blog/document-generation-api/signature-anchors.webp)

## Where Orshot Falls Short for Contracts

Orshot is built for contracts with settled wording and changing data. It isn't a contract editor, and it has gaps you should know before you start.

- Designers edit the contract look in Studio, no HTML
- Long clauses flow onto new pages with footers and page numbers
- Selectable text that e-signature tools can search
- Same template from the API, HubSpot, n8n, Make, Zapier or an AI agent

Cons:
- PDF only, no Word or DOCX output
- No e-signature, you pass the PDF to another tool
- No if/else clause rules inside the template
- No table element, so line items are fixed rows

For clauses that change per contract, build the clause text in your code and send the whole body as `nda`. You can also hide a separate layer by sending `"layer.opacity": 0`.

**Verdict:** Orshot fits teams that send the same few contracts again and again from app or CRM data. It doesn't fit legal teams that negotiate every clause.

## What Document Generation Costs on Orshot

Orshot charges 1 credit per PDF page, so a two-page NDA costs 2 credits. The free plan includes 100 credits a month with API access, enough for 50 two-page NDAs (checked October 24, 2026).

**Generate your first contract free** — Copy the NDA template, run it from the dashboard, then connect your app, HubSpot, n8n, Make or Zapier. 100 free credits a month.

[Start free](https://orshot.com/pricing?via=blog-docgen-pricing)

## Document Generation API FAQ

**Q: What is a document generation API?**

A document generation API is a web service that merges your data into a template and returns a finished file, usually a PDF. You send a template ID and values like names, dates and amounts. The API returns the document, ready to email, store or send for signature.

**Q: How do I generate documents in bulk?**

Send one API request per document from a loop in your code, or let n8n, Make or Zapier run the loop over a sheet or database. Orshot renders each request from the same template. Each PDF page uses 1 credit, so 500 two-page NDAs use 1,000 credits.

**Q: Can Orshot generate Word or DOCX files?**

No. Orshot generates PDF, PNG, JPG, WebP and video files, not Word or DOCX. If your team must edit the contract in Word after it's generated, a Word-based document generation tool fits better. For a final contract that goes straight to signature, a PDF is usually what you want.

**Q: Can the clauses change for each contract?**

Yes, but your code decides which clauses go in. Orshot templates have no if/else rules. Build the clause text in your app and send it as the body field, or hide an optional layer by setting its opacity to 0 in the request.

**Q: Is a PDF contract made by an API legally binding?**

A PDF contract is binding when the parties sign it under the law that applies to them, no matter which tool made the file. Orshot only produces the document. Your e-signature tool records the signatures. Ask a lawyer about your own contracts.

**Q: How many pages can a generated contract have?**

Orshot's flow mode adds as many pages as the text needs. The header and footer repeat on each page, and page numbers update on their own. Each page in the PDF uses 1 credit, so a five-page agreement costs 5 credits.

**Q: What is Orshot?**

Orshot is an API for automated image, PDF and video generation from templates. You design a template in Orshot Studio, mark the fields that change, and generate files from your API, n8n, Make, Zapier, HubSpot or an AI agent by sending the values.

## Generate Your First NDA

Your first contract takes about ten minutes:

1. [Sign up free](https://orshot.com/pricing?via=blog-docgen-footer). 100 credits a month, no credit card.
2. Copy the NDA template and swap in your logo, clauses and fields.
3. Run it once from the Connect panel with real values.
4. Connect it to your app with the code in step 4, or to HubSpot as in step 5.

If something doesn't work the way you expect, hit the chat button. I'm usually the one on the other end.