---
title: Copying Templates using the API | PostGrid
description: 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.

## Duplicating a Template

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](#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](/print-and-mail/api/creating-templates-using-the-api#updating-templates/index.md).

## Choosing Where the Copy Goes

The optional `destination` object controls where the copy is created.

| Field          | Description                                                                                                                                           |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| `organization` | The organization to copy the template into: your own organization (the default), or one of your sub-organizations. Accepts a `sub_org_` or `org_` ID. |
| `live`         | `true` 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.                     |

### Copying into a Sub-Organization

Pass the ID of one of your sub-organizations, as returned by the [Sub-Organizations API](/api/resources/print_mail/subresources/sub_organizations/index.md). 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.

### Copying between Test and Live Mode

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.

## What Gets Copied

- **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`.

## Errors

| Status | Type                                  | Cause                                                                                                       |
| ------ | ------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| 404    | `template_not_found_error`            | No template with that ID in your organization. With a test API key, a live template’s ID also returns this. |
| 404    | `sub_organization_not_found_error`    | `destination.organization` isn’t one of your sub-organizations that you can access.                         |
| 403    | `sub_organizations_not_enabled_error` | `destination.organization` names another organization, but sub-organizations aren’t enabled for yours.      |
| 403    | `account_inaccessible_error`          | The destination sub-organization is suspended.                                                              |
| 403    | `org_missing_payment_method_error`    | The copy goes to live mode in a sub-organization that doesn’t have live access.                             |
| 422    | `invalid_copy_destination_error`      | `destination.live` is `true` with a test API key.                                                           |
| 422    | `template_copy_not_allowed_error`     | The template uses trackers or a custom envelope and the copy goes to another organization or mode.          |

[API Reference](/api/resources/print_mail/subresources/templates/index.md)
