When to use this endpoint

Save the AutoDoc first, prepare a preview target, then call the returned api with params. This preparation does not itself render or download the document.

Authentication and permissions

Authenticate with a signed API key (acting as its owner) or a logged-in CRM session on the routed account host. Session calls include the dispatcher’s CSRF value when configured. IDs refer to the authenticated tenant unless an explicit cross-account copy is described.

CRM2 requests require Forms Edit and View for the target object (Jobs, Quotes, Purchase Orders or Invoices). These new role checks are explicitly conditional on the CRM2 request boundary; CRM1 retains its legacy preview authorization.

Before writes, Job targets pass Job record scope, Quotes pass their existing read/finance/scope boundary, Purchase Orders pass their existing View/record boundary, and Invoices retain their existing finance-access restriction. The downstream PDF endpoint is separately authorized. Preview does not change the account’s Disable Form Edits contract.

Parameters

ParameterTypeRequiredDescription
id / form_idPositive integer-compatible IDYesForm definition ID. id takes precedence; form_id is only a fallback when id is absent/null.
preview_idInteger-compatible record IDNoJob/Quote/Purchase Order/Invoice ID matching this form. Nonpositive/omitted uses meta.preview_id. A stale saved ID prompts selection again.

Example request

$preview = FM_api('Form_preparePreview', ['id'=>'1042','preview_id'=>'2081']);
$pdf = FM_api($preview['api'], $preview['params']);

Example response

{"ok":1,"type":0,"preview_id":2081,"label":"Job #2081 - JOB-2081 - 2026-11-26","api":"Job_getAsPdf","params":{"id":2081,"override_is_complete":1}}

Database numeric values can be JSON strings. Examples are representative; legacy application errors can use HTTP 200, so inspect the decoded response.

Errors and unusual responses

ResponseCondition
{"error":"not logged in"}No authenticated tenant context is available. Invalid signed credentials can be rejected by the dispatcher before the handler runs.
{"error":"missing or invalid parameter: id"}Missing/nonpositive form ID.
{"error":"form does not exist"}Unknown form.
{"error":"preview is not supported for this form type"}Unsupported type.
{"error":"preview target not configured","needs_preview_id":1}No usable supplied or saved target; ask the user to select a matching record.

Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.

Behaviour and edge cases

  • Supported form types: 0 → Job_getAsPdf with override_is_complete=1; 4 → Quote_getPdf; 5 → PurchaseOrder_getPdf; 7 → Invoice_getPdf. Each returned params includes the target id. Other types return an unsupported error.
  • Target must use this exact form_id and be nondeleted, including finance targets. Archived forms are not excluded. There is no automatic latest-record fallback.
  • Labels combine the object ID with reference/number and date when available; labels are display text, not stable identity or a timezone-normalized API timestamp. No pagination.
  • The returned PDF endpoint has its own authorization and rendering behavior; prepare success is not proof the subsequent download will be permitted.

Side effects

  • Saves meta.preview_id/cache and touches the target last_edited/cache inside one checked SQL transaction. Jobs and Invoices also receive edited_uuid=Form_preparePreview. A failed metadata or target write rolls back. It does not advance the Form last_edited, create Undo/history or render the PDF.

See it in Fieldmotion

CRM1

In the Form AutoDoc editor, Preview saves the document then calls Form_preparePreview. needs_preview_id opens a record selector; the next request passes its record ID.

CRM2

The AutoDoc Preview action follows the same prepare/select/download sequence. Inspect Form_preparePreview and the subsequent route named by api as separate requests.

Related endpoints