Prerequisites
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:
Authentication
Before publishing, you’ll need to authenticate with the htmldocs cloud platform:
npx htmldocs@latest login
This command will open a browser window where you can:
- Select your team
- Complete the authentication process
- 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.
npx htmldocs@latest 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/invoice \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"format": "json",
"props": {
"billedTo": {
"name": "Josiah Zhang",
"address": "123 Elm Street",
"city": "Anytown",
"state": "CA",
"zip": "12345",
"phone": "123-456-7890"
},
"yourCompany": {
"name": "Your Company",
"address": "456 Banana Rd.",
"city": "San Francisco",
"state": "CA",
"zip": "94107",
"taxId": "00XXXXX1234X0XX",
"phone": "123-456-7890",
"email": "hello@email.com"
},
"services": [
{
"name": "Design",
"description": "Website redesign and branding",
"quantity": 1,
"rate": 1000
},
{
"name": "Consulting",
"description": "Technical architecture review",
"quantity": 2,
"rate": 1200
}
]
}
}'
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
Responses are generated using AI and may contain mistakes.