Communications
Copy an email template
/a/EmailTemplate_copy
Create a new template by copying an existing template body, type, and metadata.
When to use this endpoint
Use EmailTemplate_copy when an existing template is the best starting point but the copy needs its own name, subject, or sender.
Authentication and permissions
The request must authenticate with signed API-key fields or a logged-in CRM session. The handler requires login and performs no additional page or role-permission check.
The read or write is limited to the authenticated tenant. Notice endpoints that say “current user” use the authenticated session user ID within that tenant.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Integer-compatible | Yes | Source template ID. It must convert to a nonzero integer; archived sources are accepted. |
name | String | Yes | New template name after trimming. It must be nonblank and unique across active and archived templates under the database collation. |
subject | String | No | Subject for the copy. Defaults to blank; the source subject is not copied automatically. This route does not enforce the table’s 100-character subject limit before inserting. |
from_email | String | No | Sender for the copy. Blank or omitted uses nonblank tenant setting default-from-email; the source sender is not copied automatically and syntax is not validated. |
Example request
$copy = FM_api('EmailTemplate_copy', [
'id' => '152004',
'name' => 'Service completion email — commercial',
'subject' => 'Your service report',
'from_email' => 'service@example.test',
]);
Example response
{
"ok": 1,
"id": 152005
}
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 parameter: id"} | id is absent. |
{"error":"missing parameter: name"} | name is absent. |
{"error":"invalid id parameter"} | The ID converts to zero. |
{"error":"no name parameter"} | The name is blank after trimming. |
{"error":"an email template of that name already exists"} | The destination name is already stored. |
{"error":"invalid id parameter - email template could not be copied"} | No source template has that numeric ID. |
{"error":"could not copy template"} | The initial insert does not return a new ID. |
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 source
body,type, and rawmetaare copied.archivedandis_defaultuse database defaults, so a copy is active and non-default. - The body’s existing
/f/...image references are reused; files are not duplicated. - This route does not sanitize the copied HTML or validate sender syntax. A later full save applies those checks and transformations.
Side effects
- Inserts one template row and then updates its body. It writes no generic field history and performs no explicit cache invalidation.
See it in Fieldmotion
CRM1
Open Settings → Email Templates in CRM1 and filter browser developer tools for the endpoint name. Choose Copy beside a template, adjust the three displayed fields, and submit.
CRM2
Open Settings → Email Templates in CRM2 and filter browser developer tools for the endpoint name. Choose the copy action on a template card and submit the dialog.
Related endpoints
EmailTemplate_saveperforms the full editor validation and sanitization.EmailTemplate_newcreates a blank draft instead.