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

# Publishing to the Cloud

> Publish and generate documents from your document templates using the API

## 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:

```bash theme={null}
npx htmldocs@latest init
```

## Authentication

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

```bash theme={null}
npx htmldocs@latest 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:

<Warning>Be sure to run this from the root of your project.</Warning>

```bash theme={null}
npx htmldocs@latest publish ./documents/templates/Invoice.tsx
```

<Note>
  Make sure your template has a unique `documentId` defined before publishing:

  ```tsx theme={null}
  Invoice.documentId = "invoice";
  export default Invoice;
  ```
</Note>

## Generating Documents via API

After publishing, you can generate documents using the REST API. First, obtain an API key from the [Dashboard](https://htmldocs.com/dashboard).

### API Authentication

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

```bash theme={null}
Authorization: Bearer YOUR_API_KEY
```

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

### Making API Requests

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

```bash theme={null}
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](https://htmldocs.com/dashboard), where you can:

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