# Templates

## Create Template

`print_mail.templates.create(TemplateCreateParams**kwargs)  -> 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

- `description: Optional[str]`

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

- `html: Optional[str]`

  The HTML content of this template.

- `metadata: Optional[Dict[str, object]]`

  See the section on Metadata.

### Returns

- `class Template: …`

  - `id: str`

    A unique ID prefixed with template_

  - `created_at: datetime`

    The UTC time at which this resource was created.

  - `live: bool`

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

  - `object: Literal["template"]`

    Always `template`.

    - `"template"`

  - `updated_at: datetime`

    The UTC time at which this resource was last updated.

  - `description: Optional[str]`

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

  - `html: Optional[str]`

    The HTML content of this template.

  - `metadata: Optional[Dict[str, object]]`

    See the section on Metadata.

### Example

```python
import os
from postgrid import PostGrid

client = PostGrid(
    print_mail_api_key=os.environ.get("POSTGRID_PRINT_MAIL_API_KEY"),  # This is the default and can be omitted
)
template = client.print_mail.templates.create(
    description="Test",
    html="<b>Hello</b> {{to.firstName}}",
)
print(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

`print_mail.templates.list(TemplateListParams**kwargs)  -> SyncSkipLimit[Template]`

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

Get a list of templates.

### Parameters

- `limit: Optional[int]`

- `search: Optional[str]`

  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: Optional[int]`

### Returns

- `class Template: …`

  - `id: str`

    A unique ID prefixed with template_

  - `created_at: datetime`

    The UTC time at which this resource was created.

  - `live: bool`

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

  - `object: Literal["template"]`

    Always `template`.

    - `"template"`

  - `updated_at: datetime`

    The UTC time at which this resource was last updated.

  - `description: Optional[str]`

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

  - `html: Optional[str]`

    The HTML content of this template.

  - `metadata: Optional[Dict[str, object]]`

    See the section on Metadata.

### Example

```python
import os
from postgrid import PostGrid

client = PostGrid(
    print_mail_api_key=os.environ.get("POSTGRID_PRINT_MAIL_API_KEY"),  # This is the default and can be omitted
)
page = client.print_mail.templates.list()
page = page.data[0]
print(page.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

`print_mail.templates.retrieve(strid)  -> Template`

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

Retrieve a template by ID.

### Parameters

- `id: str`

### Returns

- `class Template: …`

  - `id: str`

    A unique ID prefixed with template_

  - `created_at: datetime`

    The UTC time at which this resource was created.

  - `live: bool`

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

  - `object: Literal["template"]`

    Always `template`.

    - `"template"`

  - `updated_at: datetime`

    The UTC time at which this resource was last updated.

  - `description: Optional[str]`

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

  - `html: Optional[str]`

    The HTML content of this template.

  - `metadata: Optional[Dict[str, object]]`

    See the section on Metadata.

### Example

```python
import os
from postgrid import PostGrid

client = PostGrid(
    print_mail_api_key=os.environ.get("POSTGRID_PRINT_MAIL_API_KEY"),  # This is the default and can be omitted
)
template = client.print_mail.templates.retrieve(
    "id",
)
print(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

`print_mail.templates.update(strid, TemplateUpdateParams**kwargs)  -> Template`

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

Update a template by ID.

### Parameters

- `id: str`

- `description: Optional[str]`

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

- `html: Optional[str]`

  The HTML content of this template.

- `metadata: Optional[Dict[str, object]]`

  See the section on Metadata.

### Returns

- `class Template: …`

  - `id: str`

    A unique ID prefixed with template_

  - `created_at: datetime`

    The UTC time at which this resource was created.

  - `live: bool`

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

  - `object: Literal["template"]`

    Always `template`.

    - `"template"`

  - `updated_at: datetime`

    The UTC time at which this resource was last updated.

  - `description: Optional[str]`

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

  - `html: Optional[str]`

    The HTML content of this template.

  - `metadata: Optional[Dict[str, object]]`

    See the section on Metadata.

### Example

```python
import os
from postgrid import PostGrid

client = PostGrid(
    print_mail_api_key=os.environ.get("POSTGRID_PRINT_MAIL_API_KEY"),  # This is the default and can be omitted
)
template = client.print_mail.templates.update(
    id="id",
    description="Test",
    html="<b>Hello</b> {{to.firstName}}!",
)
print(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

`print_mail.templates.delete(strid)  -> TemplateDeleteResponse`

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

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

### Parameters

- `id: str`

### Returns

- `class TemplateDeleteResponse: …`

  - `id: str`

    A unique ID prefixed with template_

  - `deleted: Literal[true]`

    - `true`

  - `object: Literal["template"]`

    Always `template`.

    - `"template"`

### Example

```python
import os
from postgrid import PostGrid

client = PostGrid(
    print_mail_api_key=os.environ.get("POSTGRID_PRINT_MAIL_API_KEY"),  # This is the default and can be omitted
)
template = client.print_mail.templates.delete(
    "id",
)
print(template.id)
```

#### Response

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

## Domain Types

### Template

- `class Template: …`

  - `id: str`

    A unique ID prefixed with template_

  - `created_at: datetime`

    The UTC time at which this resource was created.

  - `live: bool`

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

  - `object: Literal["template"]`

    Always `template`.

    - `"template"`

  - `updated_at: datetime`

    The UTC time at which this resource was last updated.

  - `description: Optional[str]`

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

  - `html: Optional[str]`

    The HTML content of this template.

  - `metadata: Optional[Dict[str, object]]`

    See the section on Metadata.

### Template Delete Response

- `class TemplateDeleteResponse: …`

  - `id: str`

    A unique ID prefixed with template_

  - `deleted: Literal[true]`

    - `true`

  - `object: Literal["template"]`

    Always `template`.

    - `"template"`
