Reusable document and recurrence templates
List reusable templates by type
/a/Templates_get
Fetch the reusable presets for one object type with selected storage fields
When to use this endpoint
Populate a template picker, optionally loading obj with the names to avoid one request per selection. This is an unpaged projection lookup, not a DataTables request. It returns storage names rather than the mapped aliases used by Templates_getDataTable.
Authentication and permissions
Authenticate with signed API-key fields or a logged-in CRM session. Template_get, Template_new, Template_setObj and Templates_get require an authenticated tenant context; Template_delete and both table handlers also call the login guard. There is no handler-level administrator, page, role, creator or ownership check.
Templates are shared within the authenticated tenant, not private to created_by. There is no user, department, feature-setting or active/deleted filter. The dispatcher also applies its normal account, authentication and team-access checks; the shared table predicate adds no template-specific row restriction.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
type | Integer | Yes | Integer-converted positive template type. This parameter is named type, unlike obj_type in Templates_getDT and objType in Templates_getDataTable. |
fields | JSON array text | Yes | JSON-encoded array of storage names: id, cdate, last_edited, obj, obj_type, name, created_by. Unknown names are ignored and duplicates removed. At least one valid name must remain. A native request array is not decoded here. |
Example request
$templates = FM_api('Templates_get', [
'type' => '3',
'fields' => json_encode(['id', 'name', 'obj']),
]);
Example response
[{"id":"1042","name":"Standard quote","obj":"{\"notes\":\"Reusable quote notes\"}"}]
Returns a bare array, [] when no rows match. Only requested valid fields are selected: id is not added automatically. obj is not decoded; numeric database values can be strings.
Errors and unusual responses
| Response | Condition |
|---|---|
{"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: type"} | Integer-converted type is below 1. |
{"error":"missing parameter: fields"} | fields missing or null. |
{"error":"no fields selected"} | No valid names remain, including an empty array or malformed JSON that yields no selected names. Malformed/non-array JSON may additionally emit PHP warnings; send an actual encoded array. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- The CRM2 enum defines 1=recurrence, 2=job, 3=quote, 4=invoice and 5=opportunity. The PHP handlers accept any positive integer, not just that enum. These are saved input presets, not email templates or PDF/Word document designs.
- Filters only obj_type. No server ordering, pagination, text search, default selection or user filter is applied. The CRM1 recurrence picker sorts names client-side. start, length and order do not page this call.
- No direct mobile-app or m-service caller for this template family was found in the source search. The CRM2 widget’s payload is client-defined; storing it does not validate that another document endpoint will accept every field.
Side effects
- Read-only; loading a preset does not apply it or create a business object.
See it in Fieldmotion
CRM1
Open the job recurrence template selector or Save as Template dialog. Filter for Templates_get: CRM1 passes type=1 and encoded id/name, or id/name/obj, fields.
CRM2
CRM2’s widgetTemplate.js loads Templates_get with JSON-encoded id/name/obj fields, parses obj locally, and uses Template_new, Template_setObj and Template_delete from its save/trash controls. Observe these requests in a create dialog whose configured layout includes the Template widget, such as a quote or invoice. The widget is layout-dependent, not present on every screen. The production opportunity create dialog supplies Opportunity (5), separately from Invoice (4), and the caller regression exercises that actual module path.
Related endpoints
- Templates_get supplies the selectable presets for one type.
- Template_get reads one stored preset without applying it.
- Template_new creates a separate preset; Template_setObj replaces an existing preset’s payload.
- Template_delete removes the reusable preset, not documents previously created from it.