# Content

Use the Content API to create content templates that can be sent in pushes and [managed in the Airship dashboard](/guides/personalization/content/templates/).


## Create content template {#createcontenttemplate}

Create a new content template.

[Jump to examples ↓](#createcontenttemplate-examples)

### `POST /api/content/templates`

**Security:**

- [basicAuth]({{< ref "/developer/rest-api/ua/introduction/" >}}#security-basicAuth)
- [oauth2Token]({{< ref "/developer/rest-api/ua/introduction/" >}}#security-oauth2Token): tpl

**Request body**

A single content template object.

**Content-Type:** `application/json`

[Content template object]({{< ref "/developer/rest-api/ua/schemas/content-objects/" >}}#contenttemplateobject)

**Responses**

**`201`** The template was created.

Response headers:

| Name | Type | Description |
|------|------|-------------|
| `Location` | `string` | The URI for the template, used for later updates or sends. |

Response body:

**Content-Type:** `application/vnd.urbanairship+json; version=3`

- **`ok`** `boolean` **REQUIRED**

  If `true`, the operation completed successfully and returns an expected response.

- **`operation_id`** `string`

  A unique string identifying the operation, useful for reporting and troubleshooting.

  Format: `uuid`

  Example: `ef625038-70a3-41f1-826f-57bc11dd625a`

- **`template_id`** `string`

  A unique string identifying the template, used to reference it when sending messages and in other operations.

  Format: `uuid`

  Example: `0f7704e9-5dc0-4f7d-9964-e89055701b0a`

**`400`** There was a parsing or validation error in the request. Bad Request errors typically include `path` and `location` in the response to help you find the cause of the error.

Response body:

**Content-Type:** `application/json`

[Error response]({{< ref "/developer/rest-api/ua/schemas/responses/" >}}#error)

**`401`** Authentication information (the app key and secret or bearer token) was either incorrect or missing.

Response body:

**Content-Type:** `text/plain`

[Error response]({{< ref "/developer/rest-api/ua/schemas/responses/" >}}#error)

**Examples**

*Example create email content template with snippet and feed references*

```http
POST /api/content/templates HTTP/1.1
Authorization: Basic <master authorization string>
Accept: application/vnd.urbanairship+json; version=3
Content-Type: application/json

{
    "external_id": "welcome_message",
    "name": "Welcome Message",
    "description": "Our welcome message",
    "type": "email",
    "content": {
        "subject": "Welcome!",
        "html_body": "<html><body>Hi, {{first_name}}! {{>footer}}</body></html>",
        "plaintext_body": "Hi, {{first_name}}!"
    },
    "snippet_references": {
        "snippets": [
          {
            "name": "footer"
          }
        ]
    },
    "feed_references": {
        "feeds": [
          {
            "name": "featured_product"
          }
        ]
    }
}

```

```http
HTTP/1.1 201 Created
Location: https://go.urbanairship.com/api/content/templates/ef34a8d9-0ad7-491c-86b0-aea74da15161
Content-Type: application/vnd.urbanairship+json; version=3

{
    "ok" : true,
    "operation_id" : "9ce808c8-7176-45dc-b79e-44aa74249a5a",
    "template_id": "ef34a8d9-0ad7-491c-86b0-aea74da15161"
}

```

---

## Create or update content template by external ID {#updatecontenttemplatebyexternalid}

Create or update a content template by its external ID.

[Jump to examples ↓](#updatecontenttemplatebyexternalid-examples)

### `PUT /api/content/templates/external/{type}/{external_id}`

**Security:**

- [basicAuth]({{< ref "/developer/rest-api/ua/introduction/" >}}#security-basicAuth)
- [oauth2Token]({{< ref "/developer/rest-api/ua/introduction/" >}}#security-oauth2Token): tpl

**Path parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `type` | `string` | Required | The message type for the template. Possible values: `email`, `sms`, `open`, `app`, `web`, `message_center` |
| `external_id` | `string` | Required | The customer-defined external ID of the template. |

**Request body**

A partially defined content template object.

**Content-Type:** `application/json`

[Content template object]({{< ref "/developer/rest-api/ua/schemas/content-objects/" >}}#contenttemplateobject)

**Responses**

**`200`** Returned if the template has been successfully updated.

Response body:

**Content-Type:** `application/vnd.urbanairship+json; version=3`

- **`ok`** `boolean` **REQUIRED**

  If `true`, the operation completed successfully and returns an expected response.

- **`operation_id`** `string`

  A unique string identifying the operation, useful for reporting and troubleshooting.

  Format: `uuid`

  Example: `ef625038-70a3-41f1-826f-57bc11dd625a`

**`400`** There was a parsing or validation error in the request. Bad Request errors typically include `path` and `location` in the response to help you find the cause of the error.

Response body:

**Content-Type:** `application/json`

[Error response]({{< ref "/developer/rest-api/ua/schemas/responses/" >}}#error)

**`401`** Authentication information (the app key and secret or bearer token) was either incorrect or missing.

Response body:

**Content-Type:** `text/plain`

[Error response]({{< ref "/developer/rest-api/ua/schemas/responses/" >}}#error)

**Examples**

*Example update content template by external ID*

```http
PUT /api/content/templates/external/email/customer-defined-id HTTP/1.1
Authorization: Basic <master authorization string>
Accept: application/vnd.urbanairship+json; version=3
Content-Type: application/json

{
    "name": "Welcome Message",
    "description": "Our welcome message",
    "content": {
        "subject": "Welcome!",
        "html_body": "<html><body>Hi, {{first_name}}!</body></html>",
        "plaintext_body": "Hi, {{first_name}}!"
    }
}

```

```http
HTTP/1.1 200 OK
Content-Type: application/vnd.urbanairship+json; version=3

{
    "ok" : true,
    "operation_id" : "9ce808c8-7176-45dc-b79e-44aa74249a5a"
}

```

---

## Delete content template {#deletecontenttemplate}

Delete a content template.

[Jump to examples ↓](#deletecontenttemplate-examples)

### `DELETE /api/content/templates/{template_id}`

**Security:**

- [basicAuth]({{< ref "/developer/rest-api/ua/introduction/" >}}#security-basicAuth)
- [oauth2Token]({{< ref "/developer/rest-api/ua/introduction/" >}}#security-oauth2Token): tpl

**Path parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `template_id` | `string` | Required | The UUID of the template. |

**Responses**

**`200`** The template with the given ID has been successfully deleted.

Response body:

**Content-Type:** `application/vnd.urbanairship+json; version=3`

- **`ok`** `boolean` **REQUIRED**

  If `true`, the operation completed successfully and returns an expected response.

- **`operation_id`** `string`

  A unique string identifying the operation, useful for reporting and troubleshooting.

  Format: `uuid`

  Example: `ef625038-70a3-41f1-826f-57bc11dd625a`

**`401`** Authentication information (the app key and secret or bearer token) was either incorrect or missing.

Response body:

**Content-Type:** `text/plain`

[Error response]({{< ref "/developer/rest-api/ua/schemas/responses/" >}}#error)

**`404`** The requested resource doesn't exist.

Response body:

**Content-Type:** `application/vnd.urbanairship+json`

[Error response]({{< ref "/developer/rest-api/ua/schemas/responses/" >}}#error)

**Examples**

*Example delete content template*

```http
DELETE /api/content/templates/ef34a8d9-0ad7-491c-86b0-aea74da15161 HTTP/1.1
Authorization: Basic <master authorization string>
Accept: application/vnd.urbanairship+json; version=3

```

```http
HTTP/1.1 200 OK
Content-Type: application/vnd.urbanairship+json; version=3

{
    "ok" : true,
    "operation_id" : "9ce808c8-7176-45dc-b79e-44aa74249a5a"
}

```

---

## Delete content template by external ID {#deletecontenttemplatebyexternalid}

Delete a content template.

[Jump to examples ↓](#deletecontenttemplatebyexternalid-examples)

### `DELETE /api/content/templates/external/{type}/{external_id}`

**Security:**

- [basicAuth]({{< ref "/developer/rest-api/ua/introduction/" >}}#security-basicAuth)
- [oauth2Token]({{< ref "/developer/rest-api/ua/introduction/" >}}#security-oauth2Token): tpl

**Path parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `type` | `string` | Required | The message type for the template. Possible values: `email`, `sms`, `open`, `app`, `web`, `message_center` |
| `external_id` | `string` | Required | The customer-defined external ID of the template. |

**Responses**

**`200`** The template with the given external ID has been successfully deleted.

Response body:

**Content-Type:** `application/vnd.urbanairship+json; version=3`

- **`ok`** `boolean` **REQUIRED**

  If `true`, the operation completed successfully and returns an expected response.

- **`operation_id`** `string`

  A unique string identifying the operation, useful for reporting and troubleshooting.

  Format: `uuid`

  Example: `ef625038-70a3-41f1-826f-57bc11dd625a`

**`401`** Authentication information (the app key and secret or bearer token) was either incorrect or missing.

Response body:

**Content-Type:** `text/plain`

[Error response]({{< ref "/developer/rest-api/ua/schemas/responses/" >}}#error)

**`404`** The requested resource doesn't exist.

Response body:

**Content-Type:** `application/vnd.urbanairship+json`

[Error response]({{< ref "/developer/rest-api/ua/schemas/responses/" >}}#error)

**Examples**

*Example delete content template by external ID*

```http
DELETE /api/content/templates/external/email/customer-defined-id HTTP/1.1
Authorization: Basic <master authorization string>
Accept: application/vnd.urbanairship+json; version=3

```

```http
HTTP/1.1 200 OK
Content-Type: application/vnd.urbanairship+json; version=3

{
    "ok" : true,
    "operation_id" : "9ce808c8-7176-45dc-b79e-44aa74249a5a"
}

```

---

## List content templates {#listcontenttemplates}

List all existing content templates. Returns an array of content template objects in the `content_templates` attribute.

[Jump to examples ↓](#listcontenttemplates-examples)

### `GET /api/content/templates`

**Security:**

- [basicAuth]({{< ref "/developer/rest-api/ua/introduction/" >}}#security-basicAuth)
- [oauth2Token]({{< ref "/developer/rest-api/ua/introduction/" >}}#security-oauth2Token): tpl

**Query parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page` | `integer` |  | Specifies the desired page number. Defaults to 1. |
| `page_size` | `integer` |  | Specifies how many results to return per page. |
| `sort` | `string` |  | Specifies the name of the field you want to sort results by. Defaults to `created_at`. Possible values: `created_at`, `modified_at` |
| `order` | `string` |  | Specifies the sort order as ascending (`asc`) or descending (`desc`). Defaults to `asc`. Possible values: `asc`, `desc` |

**Responses**

**`200`** Returned on success, with the JSON representation of the content templates in the body of the response.

Response body:

**Content-Type:** `application/vnd.urbanairship+json; version=3`

- **`content_templates`** `array` <[Content template object]({{< ref "/developer/rest-api/ua/schemas/content-objects/" >}}#contenttemplateobject)>

  An array of content template objects.

- **`count`** `integer`

  The number of content templates in the current response. This is effectively the page size.

- **`next_page`** `string`

  There might be more than one page of results for this listing. When present, use this URL to fetch the next batch of results.

  Format: `url`

- **`ok`** `boolean` **REQUIRED**

  Success.

- **`prev_page`** `string`

  Link to the previous page, if available.

  Format: `url`

- **`total_count`** `integer`

  The total number of content templates.

**`401`** Authentication information (the app key and secret or bearer token) was either incorrect or missing.

Response body:

**Content-Type:** `text/plain`

[Error response]({{< ref "/developer/rest-api/ua/schemas/responses/" >}}#error)

**Examples**

*Example list content templates*

```http
GET /api/content/templates HTTP/1.1
Authorization: Basic <master authorization string>
Accept: application/vnd.urbanairship+json; version=3

```

```http
HTTP/1.1 200 OK
Content-Type: application/vnd.urbanairship+json; version=3

{
    "ok" : true,
    "count": 1,
    "total_count": 1,
    "content_templates": [
        {
          "id": "ef34a8d9-0ad7-491c-86b0-aea74da15161",
          "external_id": "welcome_message",
          "name": "Welcome Message",
          "description": "Our welcome message",
          "type": "email",
          "content": {
              "subject": "Welcome!",
              "html_body": "<html><body>Hi, {{first_name}}!</body></html>",
              "plaintext_body": "Hi, {{first_name}}!"
          },
          "created_at": "2020-08-17T11:10:02Z",
          "modified_at": "2020-08-17T11:10:02Z"
      }
    ],
    "next_page": null,
    "prev_page": null
}

```

---

## Look up a content template {#getcontenttemplate}

Fetch a single content template using UUID.

[Jump to examples ↓](#getcontenttemplate-examples)

### `GET /api/content/templates/{template_id}`

**Security:**

- [basicAuth]({{< ref "/developer/rest-api/ua/introduction/" >}}#security-basicAuth)
- [oauth2Token]({{< ref "/developer/rest-api/ua/introduction/" >}}#security-oauth2Token): tpl

**Path parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `template_id` | `string` | Required | The UUID of the template. |

**Responses**

**`200`** Returned on success, with the JSON representation of the template in the body of the response.

Response body:

**Content-Type:** `application/vnd.urbanairship+json; version=3`

- **`content_template`** `object` <[Content template object]({{< ref "/developer/rest-api/ua/schemas/content-objects/" >}}#contenttemplateobject)>

  A reusable template containing fields for a message type. Can be referenced by its UUID or a customer-defined external ID.

- **`ok`** `boolean` **REQUIRED**

  If `true`, the operation completed successfully and returns an expected response.

**`401`** Authentication information (the app key and secret or bearer token) was either incorrect or missing.

Response body:

**Content-Type:** `text/plain`

[Error response]({{< ref "/developer/rest-api/ua/schemas/responses/" >}}#error)

**`404`** The requested resource doesn't exist.

Response body:

**Content-Type:** `application/vnd.urbanairship+json`

[Error response]({{< ref "/developer/rest-api/ua/schemas/responses/" >}}#error)

**Examples**

*Example look up content template*

```http
GET /api/content/templates/ef34a8d9-0ad7-491c-86b0-aea74da15161 HTTP/1.1
Authorization: Basic <master authorization string>
Accept: application/vnd.urbanairship+json; version=3

```

```http
HTTP/1.1 200 OK
Content-Type: application/vnd.urbanairship+json; version=3

{
  "ok" : true,
  "content_template":  {
    "id": "ef34a8d9-0ad7-491c-86b0-aea74da15161",
    "external_id": "welcome_message",
    "name": "Welcome Message",
    "description": "Our welcome message",
    "type": "email",
    "content": {
        "subject": "Welcome!",
        "html_body": "<html><body>Hi, {{first_name}}! {{>footer}}</body></html>",
        "plaintext_body": "Hi, {{first_name}}!"
    },
    "created_at": "2020-08-17T11:10:02Z",
    "modified_at": "2020-08-17T11:10:02Z",
    "snippets": [
      {
        "name": "footer"
      }
    ]
  }
}

```

---

## Look up a content template by external ID {#getcontenttemplatebyexternalid}

Fetch a single content template using external ID.

[Jump to examples ↓](#getcontenttemplatebyexternalid-examples)

### `GET /api/content/templates/external/{type}/{external_id}`

**Security:**

- [basicAuth]({{< ref "/developer/rest-api/ua/introduction/" >}}#security-basicAuth)
- [oauth2Token]({{< ref "/developer/rest-api/ua/introduction/" >}}#security-oauth2Token): tpl

**Path parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `type` | `string` | Required | The message type for the template. Possible values: `email`, `sms`, `open`, `app`, `web`, `message_center` |
| `external_id` | `string` | Required | The customer-defined external ID of the template. |

**Responses**

**`200`** Returned on success, with the JSON representation of the template in the body of the response.

Response body:

**Content-Type:** `application/vnd.urbanairship+json; version=3`

- **`content_template`** `object` <[Content template object]({{< ref "/developer/rest-api/ua/schemas/content-objects/" >}}#contenttemplateobject)>

  A reusable template containing fields for a message type. Can be referenced by its UUID or a customer-defined external ID.

- **`ok`** `boolean` **REQUIRED**

  If `true`, the operation completed successfully and returns an expected response.

**`401`** Authentication information (the app key and secret or bearer token) was either incorrect or missing.

Response body:

**Content-Type:** `text/plain`

[Error response]({{< ref "/developer/rest-api/ua/schemas/responses/" >}}#error)

**`404`** The requested resource doesn't exist.

Response body:

**Content-Type:** `application/vnd.urbanairship+json`

[Error response]({{< ref "/developer/rest-api/ua/schemas/responses/" >}}#error)

**Examples**

*Example look up content template by external ID*

```http
GET /api/content/templates/external/email/customer-defined-id HTTP/1.1
Authorization: Basic <master authorization string>
Accept: application/vnd.urbanairship+json; version=3

```

```http
HTTP/1.1 200 OK
Content-Type: application/vnd.urbanairship+json; version=3

{
  "ok" : true,
  "content_template":  {
    "id": "ef34a8d9-0ad7-491c-86b0-aea74da15161",
    "external_id": "customer-defined-id",
    "name": "Welcome Message",
    "description": "Our welcome message",
    "type": "email",
    "content": {
        "subject": "Welcome!",
        "html_body": "<html><body>Hi, {{first_name}}! {{>footer}}</body></html>",
        "plaintext_body": "Hi, {{first_name}}!"
    },
    "created_at": "2020-08-17T11:10:02Z",
    "modified_at": "2020-08-17T11:10:02Z",
    "snippets": [
      {
        "name": "footer"
      }
    ]
  }
}

```

---

## Update content template {#updatecontenttemplate}

Update a content template.

[Jump to examples ↓](#updatecontenttemplate-examples)

### `PUT /api/content/templates/{template_id}`

**Security:**

- [basicAuth]({{< ref "/developer/rest-api/ua/introduction/" >}}#security-basicAuth)
- [oauth2Token]({{< ref "/developer/rest-api/ua/introduction/" >}}#security-oauth2Token): tpl

**Path parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `template_id` | `string` | Required | The UUID of the template. |

**Request body**

A partially defined content template object.

**Content-Type:** `application/json`

[Content template object]({{< ref "/developer/rest-api/ua/schemas/content-objects/" >}}#contenttemplateobject)

**Responses**

**`200`** Returned if the template has been successfully updated.

Response body:

**Content-Type:** `application/vnd.urbanairship+json; version=3`

- **`ok`** `boolean` **REQUIRED**

  If `true`, the operation completed successfully and returns an expected response.

- **`operation_id`** `string`

  A unique string identifying the operation, useful for reporting and troubleshooting.

  Format: `uuid`

  Example: `ef625038-70a3-41f1-826f-57bc11dd625a`

**`400`** There was a parsing or validation error in the request. Bad Request errors typically include `path` and `location` in the response to help you find the cause of the error.

Response body:

**Content-Type:** `application/json`

[Error response]({{< ref "/developer/rest-api/ua/schemas/responses/" >}}#error)

**`401`** Authentication information (the app key and secret or bearer token) was either incorrect or missing.

Response body:

**Content-Type:** `text/plain`

[Error response]({{< ref "/developer/rest-api/ua/schemas/responses/" >}}#error)

**Examples**

*Example update content template*

```http
PUT /api/content/templates/ef34a8d9-0ad7-491c-86b0-aea74da15161 HTTP/1.1
Authorization: Basic <master authorization string>
Accept: application/vnd.urbanairship+json; version=3
Content-Type: application/json

{
    "name": "Welcome Message",
    "description": "Our welcome message",
    "content": {
        "subject": "Welcome!",
        "html_body": "<html><body>Hi, {{first_name}}!</body></html>",
        "plaintext_body": "Hi, {{first_name}}!"
    }
}

```

```http
HTTP/1.1 200 OK
Content-Type: application/vnd.urbanairship+json; version=3

{
    "ok" : true,
    "operation_id" : "9ce808c8-7176-45dc-b79e-44aa74249a5a"
}

```

---

