# Templates

## Create Template

`client.printMail.templates.create(TemplateCreateParamsbody, RequestOptionsoptions?): Template`

**post** `/print-mail/v1/templates`

Create a template. Note that if you want to create a template that works with our template editor, you must use our dashboard.

### Parameters

- `body: TemplateCreateParams`

  - `description?: string`

    An optional string describing this resource. Will be visible in the API and the dashboard.

  - `html?: string`

    The HTML content of this template.

  - `metadata?: Record<string, unknown>`

    See the section on Metadata.

### Returns

- `Template`

  - `id: string`

    A unique ID prefixed with template_

  - `createdAt: string`

    The UTC time at which this resource was created.

  - `live: boolean`

    `true` if this is a live mode resource else `false`.

  - `object: "template"`

    Always `template`.

    - `"template"`

  - `updatedAt: string`

    The UTC time at which this resource was last updated.

  - `description?: string`

    An optional string describing this resource. Will be visible in the API and the dashboard.

  - `html?: string`

    The HTML content of this template.

  - `metadata?: Record<string, unknown>`

    See the section on Metadata.

### Example

```typescript
import PostGrid from 'postgrid-node';

const client = new PostGrid({
  printMailAPIKey: process.env['POSTGRID_PRINT_MAIL_API_KEY'], // This is the default and can be omitted
});

const template = await client.printMail.templates.create({
  description: 'Test',
  html: '<b>Hello</b> {{to.firstName}}',
});

console.log(template.id);
```

#### Response

```json
{
  "id": "template_tBnVEzz878mXLbHQaz86j8",
  "object": "template",
  "live": false,
  "description": "Test",
  "html": "<b>Hello</b> {{to.firstName}}!",
  "createdAt": "2020-11-12T23:23:47.974Z",
  "updatedAt": "2020-11-12T23:23:47.974Z"
}
```

## List Templates

`client.printMail.templates.list(TemplateListParamsquery?, RequestOptionsoptions?): SkipLimit<Template>`

**get** `/print-mail/v1/templates`

Get a list of templates.

### Parameters

- `query: TemplateListParams`

  - `limit?: number`

  - `search?: string`

    You can supply any string to help narrow down the list of resources. For example, if you pass `"New York"` (quoted), it will return resources that have that string present somewhere in their response. Alternatively, you can supply a structured search query. See the documentation on `StructuredSearchQuery` for more details.

  - `skip?: number`

### Returns

- `Template`

  - `id: string`

    A unique ID prefixed with template_

  - `createdAt: string`

    The UTC time at which this resource was created.

  - `live: boolean`

    `true` if this is a live mode resource else `false`.

  - `object: "template"`

    Always `template`.

    - `"template"`

  - `updatedAt: string`

    The UTC time at which this resource was last updated.

  - `description?: string`

    An optional string describing this resource. Will be visible in the API and the dashboard.

  - `html?: string`

    The HTML content of this template.

  - `metadata?: Record<string, unknown>`

    See the section on Metadata.

### Example

```typescript
import PostGrid from 'postgrid-node';

const client = new PostGrid({
  printMailAPIKey: process.env['POSTGRID_PRINT_MAIL_API_KEY'], // This is the default and can be omitted
});

// Automatically fetches more pages as needed.
for await (const template of client.printMail.templates.list()) {
  console.log(template.id);
}
```

#### Response

```json
{
  "object": "list",
  "limit": 10,
  "skip": 0,
  "totalCount": 1,
  "data": [
    {
      "id": "template_tBnVEzz878mXLbHQaz86j8",
      "object": "template",
      "live": false,
      "description": "Test",
      "html": "<b>Hello</b> {{to.firstName}}!",
      "createdAt": "2020-11-12T23:23:47.974Z",
      "updatedAt": "2020-11-12T23:23:47.974Z"
    }
  ]
}
```

## Get Template

`client.printMail.templates.retrieve(stringid, RequestOptionsoptions?): Template`

**get** `/print-mail/v1/templates/{id}`

Retrieve a template by ID.

### Parameters

- `id: string`

### Returns

- `Template`

  - `id: string`

    A unique ID prefixed with template_

  - `createdAt: string`

    The UTC time at which this resource was created.

  - `live: boolean`

    `true` if this is a live mode resource else `false`.

  - `object: "template"`

    Always `template`.

    - `"template"`

  - `updatedAt: string`

    The UTC time at which this resource was last updated.

  - `description?: string`

    An optional string describing this resource. Will be visible in the API and the dashboard.

  - `html?: string`

    The HTML content of this template.

  - `metadata?: Record<string, unknown>`

    See the section on Metadata.

### Example

```typescript
import PostGrid from 'postgrid-node';

const client = new PostGrid({
  printMailAPIKey: process.env['POSTGRID_PRINT_MAIL_API_KEY'], // This is the default and can be omitted
});

const template = await client.printMail.templates.retrieve('id');

console.log(template.id);
```

#### Response

```json
{
  "id": "template_tBnVEzz878mXLbHQaz86j8",
  "object": "template",
  "live": false,
  "description": "Test",
  "html": "<b>Hello</b> {{to.firstName}}!",
  "createdAt": "2020-11-12T23:23:47.974Z",
  "updatedAt": "2020-11-12T23:23:47.974Z"
}
```

## Update Template

`client.printMail.templates.update(stringid, TemplateUpdateParamsbody, RequestOptionsoptions?): Template`

**post** `/print-mail/v1/templates/{id}`

Update a template by ID.

### Parameters

- `id: string`

- `body: TemplateUpdateParams`

  - `description?: string`

    An optional string describing this resource. Will be visible in the API and the dashboard.

  - `html?: string`

    The HTML content of this template.

  - `metadata?: Record<string, unknown>`

    See the section on Metadata.

### Returns

- `Template`

  - `id: string`

    A unique ID prefixed with template_

  - `createdAt: string`

    The UTC time at which this resource was created.

  - `live: boolean`

    `true` if this is a live mode resource else `false`.

  - `object: "template"`

    Always `template`.

    - `"template"`

  - `updatedAt: string`

    The UTC time at which this resource was last updated.

  - `description?: string`

    An optional string describing this resource. Will be visible in the API and the dashboard.

  - `html?: string`

    The HTML content of this template.

  - `metadata?: Record<string, unknown>`

    See the section on Metadata.

### Example

```typescript
import PostGrid from 'postgrid-node';

const client = new PostGrid({
  printMailAPIKey: process.env['POSTGRID_PRINT_MAIL_API_KEY'], // This is the default and can be omitted
});

const template = await client.printMail.templates.update('id', {
  description: 'Test',
  html: '<b>Hello</b> {{to.firstName}}!',
});

console.log(template.id);
```

#### Response

```json
{
  "id": "template_tBnVEzz878mXLbHQaz86j8",
  "object": "template",
  "live": false,
  "description": "Test",
  "html": "<b>Hello</b> {{to.firstName}}!",
  "createdAt": "2020-11-12T23:23:47.974Z",
  "updatedAt": "2020-11-12T23:23:47.974Z"
}
```

## Delete Template

`client.printMail.templates.delete(stringid, RequestOptionsoptions?): TemplateDeleteResponse`

**delete** `/print-mail/v1/templates/{id}`

Delete a template by ID. Note that this operation cannot be undone.

### Parameters

- `id: string`

### Returns

- `TemplateDeleteResponse`

  - `id: string`

    A unique ID prefixed with template_

  - `deleted: true`

    - `true`

  - `object: "template"`

    Always `template`.

    - `"template"`

### Example

```typescript
import PostGrid from 'postgrid-node';

const client = new PostGrid({
  printMailAPIKey: process.env['POSTGRID_PRINT_MAIL_API_KEY'], // This is the default and can be omitted
});

const template = await client.printMail.templates.delete('id');

console.log(template.id);
```

#### Response

```json
{
  "id": "template_sqF12lZ1VlBb",
  "deleted": true,
  "object": "template"
}
```

## Domain Types

### Template

- `Template`

  - `id: string`

    A unique ID prefixed with template_

  - `createdAt: string`

    The UTC time at which this resource was created.

  - `live: boolean`

    `true` if this is a live mode resource else `false`.

  - `object: "template"`

    Always `template`.

    - `"template"`

  - `updatedAt: string`

    The UTC time at which this resource was last updated.

  - `description?: string`

    An optional string describing this resource. Will be visible in the API and the dashboard.

  - `html?: string`

    The HTML content of this template.

  - `metadata?: Record<string, unknown>`

    See the section on Metadata.

### Template Delete Response

- `TemplateDeleteResponse`

  - `id: string`

    A unique ID prefixed with template_

  - `deleted: true`

    - `true`

  - `object: "template"`

    Always `template`.

    - `"template"`
