When to use this endpoint

Use this when saving the HTML editor in CRM1 or the email-template block editor. FormBlock_saveCode is an equivalent newer route used by CRM2’s ordinary Form Blocks screen.

Authentication and permissions

The request must authenticate with signed API-key fields or a logged-in CRM session and is scoped to the authenticated tenant.

The handler performs no record-owner or page-permission check. Definition writes are blocked when the tenant’s features2.disableFormEdits flag is 1, except for the temporary setup user identified by userdata.meta.is_tmp=1.

Parameters

ParameterTypeRequiredDescription
idPositive integerYesExisting tenant block ID.
codeStringYesNon-empty HTML. Embedded base64 image sources may be stored separately and rewritten to /f/ paths.

Example request

$result = FM_api('FormBlock_setCode', [
	'id' => '4822',
	'code' => '<footer>{{COMPANY_NAME}}</footer>',
]);

Example response

{
  "ok": 1
}

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":"invalid or missing parameter: id"}ID is absent or not positive.
{"error":"invalid or missing parameter: code"}Code is absent or blank after trimming.
{"error":"no such form block"}No matching row exists.
{"error":"form edits are disabled for this account"}Definition edits are disabled.

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

Behaviour and edge cases

  • After image normalization, an exact match returns {"ok":1,"warning":"no change needed"}.
  • Image extraction, resizing, and orphan behavior are identical to FormBlock_saveCode. Empty HTML cannot be used to clear a block.

Side effects

  • Updates the HTML and last_edited Unix timestamp.
  • May write type-22 stored images referenced from the rewritten HTML.

See it in Fieldmotion

CRM1

Saving Code in either the Form Blocks or Email Template Blocks editor calls this route.

CRM2

The Email Template Blocks editor uses this route; the ordinary Form Blocks editor uses FormBlock_saveCode.

Related endpoints