Skip to content
Get startedDashboardSupport
Print & Mail
API

Copying Templates using the API

How to duplicate a template, copy it into a sub-organization, or copy it between test and live mode with the PostGrid API.

The copy endpoint creates a new template from an existing one. Use it to duplicate a template, to copy a template into one of your sub-organizations, or to copy a template between test and live mode. The copy has the same HTML, template editor design and format settings as the original.

To copy a template, make a POST request to /templates/:id/copy, where :id is the ID of the template you want to copy. The body is optional.

With an empty body, the copy is created in your organization, in the mode of your API key. When the template is in the same mode as your API key, this duplicates it in place. With a live API key, an empty body on a test template’s ID creates the copy in live mode (see Copying between Test and Live Mode).

const fetch = require('node-fetch');
const POSTGRID_URL = 'https://api.postgrid.com/print-mail/v1';
const API_KEY = ''; // Place your API key here
/**
* @param {string} id
* @param {{ organization?: string, live?: boolean }} [destination]
*/
async function copyTemplate(id, destination) {
const requestOptions = {
method: 'POST',
body: JSON.stringify(destination ? { destination } : {}),
headers: {
'x-api-key': API_KEY,
'Content-Type': 'application/json',
},
};
const resp = await fetch(
POSTGRID_URL + `/templates/${id}/copy`,
requestOptions,
);
return await resp.json();
}

Running copyTemplate('template_suknWmGvcjFeQyW6iUsBou') returns the new template, with its own ID.

{
"id": "template_c6HSqnsD1h2zoeHJ6Z9EEA",
"object": "template",
"live": false,
"description": "This is a test template",
"html": "<html>\n\t<body>\n\t\t<h1> Dear {{to.firstName}} </h1>\n\t</body>\n</html>",
"createdAt": "2026-10-16T14:02:11.519Z",
"updatedAt": "2026-10-16T14:02:11.519Z"
}

The copy keeps the original’s description and metadata. To rename it, update the copy afterwards as described in Creating Templates.

The optional destination object controls where the copy is created.

FieldDescription
organizationThe organization to copy the template into: your own organization (the default), or one of your sub-organizations. Accepts a sub_org_ or org_ ID.
livetrue to create the copy in live mode, false for test mode. Defaults to the mode of your API key. true needs a live API key.

Pass the ID of one of your sub-organizations, as returned by the Sub-Organizations API. Sub-organizations must be enabled for your organization, and the sub-organization can’t be suspended.

await copyTemplate('template_suknWmGvcjFeQyW6iUsBou', {
organization: 'sub_org_tBnVEzz878mXLbHQaz86j8',
});

The copy is created in the sub-organization, in the mode of your API key. To copy a template into several sub-organizations, make one request for each.

The template is found by its ID in whichever mode it’s in, so you don’t need to say where it comes from, only where the copy goes.

  • Test API key: only finds test templates, and can only create test copies.
  • Live API key: finds templates in either mode and can copy in any direction: test to live, live to test, or live to live.

For example, with a live API key, this copies a test template into live mode:

await copyTemplate('template_suknWmGvcjFeQyW6iUsBou', { live: true });

You can combine both fields, for example to copy a test template straight into live mode in a sub-organization.

  • HTML, template editor design and format settings are copied as they are.
  • Description and metadata are kept from the original.
  • Images keep the same URLs as in the original.
  • Trackers and custom envelopes belong to one organization and mode. A template that uses a tracker (a {{tracker_...}} merge variable, or a tracker in the template editor) or a custom envelope can only be copied within the same organization and mode, where the copy uses the same tracker or envelope. Copying it into another organization or mode returns a template_copy_not_allowed_error.
StatusTypeCause
404template_not_found_errorNo template with that ID in your organization. With a test API key, a live template’s ID also returns this.
404sub_organization_not_found_errordestination.organization isn’t one of your sub-organizations that you can access.
403sub_organizations_not_enabled_errordestination.organization names another organization, but sub-organizations aren’t enabled for yours.
403account_inaccessible_errorThe destination sub-organization is suspended.
403org_missing_payment_method_errorThe copy goes to live mode in a sub-organization that doesn’t have live access.
422invalid_copy_destination_errordestination.live is true with a test API key.
422template_copy_not_allowed_errorThe template uses trackers or a custom envelope and the copy goes to another organization or mode.

API Reference