# Templates ## Create 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. ### Body Parameters - `description: optional string` An optional string describing this resource. Will be visible in the API and the dashboard. - `html: optional string` The HTML content of this template. - `metadata: optional map[unknown]` See the section on Metadata. ### Returns - `Template = object { id, createdAt, live, 5 more }` - `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: optional string` An optional string describing this resource. Will be visible in the API and the dashboard. - `html: optional string` The HTML content of this template. - `metadata: optional map[unknown]` See the section on Metadata. ### Example ```http curl https://api.postgrid.com/print-mail/v1/templates \ -H 'Content-Type: application/json' \ -H "X-API-Key: $POSTGRID_PRINT_MAIL_API_KEY" \ -d '{}' ``` #### Response ```json { "id": "template_tBnVEzz878mXLbHQaz86j8", "object": "template", "live": false, "description": "Test", "html": "Hello {{to.firstName}}!", "createdAt": "2020-11-12T23:23:47.974Z", "updatedAt": "2020-11-12T23:23:47.974Z" } ``` ## List Templates **get** `/print-mail/v1/templates` Get a list of templates. ### Query Parameters - `limit: optional number` - `search: optional 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: optional number` ### Returns - `data: array of 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: optional string` An optional string describing this resource. Will be visible in the API and the dashboard. - `html: optional string` The HTML content of this template. - `metadata: optional map[unknown]` See the section on Metadata. - `limit: number` - `object: "list"` - `"list"` - `skip: number` - `totalCount: number` ### Example ```http curl https://api.postgrid.com/print-mail/v1/templates \ -H "X-API-Key: $POSTGRID_PRINT_MAIL_API_KEY" ``` #### Response ```json { "object": "list", "limit": 10, "skip": 0, "totalCount": 1, "data": [ { "id": "template_tBnVEzz878mXLbHQaz86j8", "object": "template", "live": false, "description": "Test", "html": "Hello {{to.firstName}}!", "createdAt": "2020-11-12T23:23:47.974Z", "updatedAt": "2020-11-12T23:23:47.974Z" } ] } ``` ## Get Template **get** `/print-mail/v1/templates/{id}` Retrieve a template by ID. ### Path Parameters - `id: string` ### Returns - `Template = object { id, createdAt, live, 5 more }` - `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: optional string` An optional string describing this resource. Will be visible in the API and the dashboard. - `html: optional string` The HTML content of this template. - `metadata: optional map[unknown]` See the section on Metadata. ### Example ```http curl https://api.postgrid.com/print-mail/v1/templates/$ID \ -H "X-API-Key: $POSTGRID_PRINT_MAIL_API_KEY" ``` #### Response ```json { "id": "template_tBnVEzz878mXLbHQaz86j8", "object": "template", "live": false, "description": "Test", "html": "Hello {{to.firstName}}!", "createdAt": "2020-11-12T23:23:47.974Z", "updatedAt": "2020-11-12T23:23:47.974Z" } ``` ## Update Template **post** `/print-mail/v1/templates/{id}` Update a template by ID. ### Path Parameters - `id: string` ### Body Parameters - `description: optional string` An optional string describing this resource. Will be visible in the API and the dashboard. - `html: optional string` The HTML content of this template. - `metadata: optional map[unknown]` See the section on Metadata. ### Returns - `Template = object { id, createdAt, live, 5 more }` - `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: optional string` An optional string describing this resource. Will be visible in the API and the dashboard. - `html: optional string` The HTML content of this template. - `metadata: optional map[unknown]` See the section on Metadata. ### Example ```http curl https://api.postgrid.com/print-mail/v1/templates/$ID \ -H 'Content-Type: application/json' \ -H "X-API-Key: $POSTGRID_PRINT_MAIL_API_KEY" \ -d '{}' ``` #### Response ```json { "id": "template_tBnVEzz878mXLbHQaz86j8", "object": "template", "live": false, "description": "Test", "html": "Hello {{to.firstName}}!", "createdAt": "2020-11-12T23:23:47.974Z", "updatedAt": "2020-11-12T23:23:47.974Z" } ``` ## Delete Template **delete** `/print-mail/v1/templates/{id}` Delete a template by ID. Note that this operation cannot be undone. ### Path Parameters - `id: string` ### Returns - `id: string` A unique ID prefixed with template_ - `deleted: true` - `true` - `object: "template"` Always `template`. - `"template"` ### Example ```http curl https://api.postgrid.com/print-mail/v1/templates/$ID \ -X DELETE \ -H "X-API-Key: $POSTGRID_PRINT_MAIL_API_KEY" ``` #### Response ```json { "id": "template_sqF12lZ1VlBb", "deleted": true, "object": "template" } ``` ## Domain Types ### Template - `Template = object { id, createdAt, live, 5 more }` - `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: optional string` An optional string describing this resource. Will be visible in the API and the dashboard. - `html: optional string` The HTML content of this template. - `metadata: optional map[unknown]` See the section on Metadata.