Docly Developers
Function API only Updated 22 Oct 2026

publishDocument(path, domain, [options])

Publishes one document inside the site with one of its schema's templates, on one of the subscription's domains. Only available in API mode (.js endpoints), and only when the subscription has SaaS enabled. The script publishes as the user who published the site, with the same checks as the Publish dialog.

Parameters

pathstringrequired

The document, relative to the site root. It must lie inside the site's own folder; documents elsewhere in the workspace and the template's files are refused with "path not found in the site".

domainstringrequired

The domain name, as getDomains returns it (not case-sensitive). Must be a verified domain on the workspace's subscription.

optionsobjectoptional
Specify any of the following options parameters:
templatestring

The template to render the document with: the template's id (case-sensitive) or its display name (not case-sensitive). May be omitted when the document's schema has exactly one template; with several, it is required.

aliasstring

The path under the domain. Omitted: the document name, with spaces replaced by "-".

authModenumber

Omitted: public. 2 = sign-in by redirect, 3 = sign-in in a popup.

Returns

The new publication, in the same shape as a row from getPublications (isDocument is true). Keep the guid if you want to unpublish later.

Errors are fixed texts that never repeat the value you sent — the same as for publishFolder, plus "specify a template" (several templates, none given) and "template not found".

Example

Mixed HTML (or any text file) with inline JavaScript between hash signs.
let pub = docly.publishDocument("#/Websites/ola/Offer", {
  domain: "customers.example.com",
  template: "Offer",
  alias: "ola-offer"
});
return pub.url;