Prerequisites

First, ensure you have the latest version of the htmldocs CLI installed:

npm i -g htmldocs@latest

This command installs or updates the CLI globally on your system.

If you haven’t already, run the following command to create a new htmldocs project:

npx htmldocs@latest init

Authentication

Before publishing, you’ll need to authenticate with the htmldocs cloud platform:

htmldocs login

This command will open a browser window where you can:

  1. Select your team
  2. Complete the authentication process
  3. Store your credentials securely for future use

Publishing Templates

Once authenticated, you can publish your document templates using the publish command:

Be sure to run this from the root of your project.
htmldocs publish ./documents/templates/Invoice.tsx

Make sure your template has a unique documentId defined before publishing:

Invoice.documentId = "invoice";
export default Invoice;

Generating Documents via API

After publishing, you can generate documents using the REST API. First, obtain an API key from the Dashboard.

API Authentication

Include your API key in requests using the Bearer token format:

Authorization: Bearer YOUR_API_KEY

API keys are scoped to your team and provide access only to documents owned by that team.

Making API Requests

To generate a document, send a POST request to the generation endpoint with your document variables:

curl -X POST https://api.htmldocs.com/api/documents/{documentId} \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "format": "json",
    "props": {
      "customerName": "Acme Corp",
      "items": [
        {
          "name": "Premium License",
          "quantity": 1,
          "price": 999.00
        }
      ]
    }
  }'

Replace {documentId} with your template’s document ID (e.g., “invoice”).

Managing Published Templates

You can view and manage your published templates in the Dashboard, where you can:

  • View all published templates
  • Get document IDs
  • Manage API keys
  • Monitor usage
  • View generation history