# Create MMS Template

### Authentication

{% hint style="info" %}
Authentication is done by passing your TSG Global API key via the Authorization header in the format "Authorization: Bearer \<api\_key>" (using the messaging API key specifically). API credentials can be found here: <https://customer-portal.tsgglobal.com/account>
{% endhint %}

<mark style="color:green;">`POST`</mark> `https://mmsc.tsgglobal.world/mms/templates`

Creates a new MMS template, the template has placeholders so you can use it to fill per-customer information as needed.

### **Request body**

| Name                                       | Type   | Description                                                                        |
| ------------------------------------------ | ------ | ---------------------------------------------------------------------------------- |
| `data.type`                                | string | Must be `"mms-template"`                                                           |
| `data.attributes.name`                     | string | **Required.** Template name                                                        |
| `data.attributes.body_template`            | string | **Required.** Body text with `{placeholder}` syntax                                |
| `data.attributes.subject_template`         | string | Optional. Subject line with `{placeholder}` syntax                                 |
| `data.attributes.parts`                    | array  | Optional. List of attachment parts (see below)                                     |
| `data.attributes.parts[].kind`             | string | **Required.** One of `"data-uri"`, `"uri"`, `"plain"`, `"embedded"`                |
| `data.attributes.parts[].content_location` | string | Optional. Filename for the attachment                                              |
| `data.attributes.parts[].uri`              | string | Required for `"uri"` and `"data-uri"` kinds. The resource URI or RFC 2397 data URI |
| `data.attributes.parts[].body`             | string | Required for `"plain"` kind                                                        |
| `data.attributes.parts[].content_type`     | string | Optional. MIME type (default: `"text/plain"`)                                      |

Placeholders use the pattern `{key}` where key matches `[a-zA-Z_][a-zA-Z0-9_]*`. Extracted placeholders are returned in the response.

### &#x20;Example with placeholders

#### Example of a request

Besides the text in `body_template` there's 2 parts: a Base64 encoded attachment (`kind: "data-uri"`) and a image that's referenced by a URL (`"kind": "uri"`).

```json
{
  "data": {
    "type": "mms-template",
    "attributes": {
      "name": "visit-thank-you",
      "subject_template": "Hello {name}",
      "body_template": "Dear {name}, welcome to {company}.",
      "parts": [
        {
          "kind": "data-uri",
          "content_location": "brochure.txt",
          "uri": "data:text/plain,Hello%20Brochure"
        },
        {
          "kind": "uri",
          "content_location": "unnamed-1.png",
          "uri": "https://www.tsgglobal.com/wp-content/uploads/2025/01/unnamed-1.png"
        }
      ]
    }
  }
}
```

#### Example response

```json
{
  "data": {
    "attributes": {
      "name": "visit-thank-you",
      "parts": [
        {
          "uri": "https://content-mms.staging.smshub.world/templates/491aa990-1fbb-4058-8af0-c78049010d2f/attachments/1-brochure.txt",
          "content_type": "text/plain",
          "content_location": "brochure.txt"
        },
        {
          "uri": "https://content-mms.staging.smshub.world/templates/491aa990-1fbb-4058-8af0-c78049010d2f/attachments/2-unnamed-1.png",
          "content_type": "image/png",
          "content_location": "unnamed-1.png"
        }
      ],
      "inserted_at": "2026-03-20T19:53:02.165449",
      "updated_at": "2026-03-20T19:53:02.165449",
      "placeholders": [
        "name",
        "company"
      ],
      "body_template": "Dear {name}, welcome to {company}.",
      "subject_template": "Hello {name}"
    },
    "id": "491aa990-1fbb-4058-8af0-c78049010d2f",
    "type": "mms-template"
  }
}

```

### Example without placeholders

This is an example with no placeholders (notice the lack of `{placeholder}` syntax.

#### Example of a request

This is an example without placeholders and a single image attachment provided via  (`"kind": "uri"`). **Note:** the attachment has to be publicly accessible.&#x20;

```json
{
  "data": {
    "type": "mms-template",
    "attributes": {
      "name": "no-placeholder-example",
      "subject_template": "New deals!",
      "body_template": "Check our new deals!",
      "parts": [
        {
          "kind": "uri",
          "content_location": "unnamed-1.png",
          "uri": "https://www.tsgglobal.com/wp-content/uploads/2025/01/unnamed-1.png"
        }
      ]
    }
  }
}
```

#### Example response

```json
{
  "data": {
    "attributes": {
      "name": "no-placeholder-example",
      "parts": [
        {
          "uri": "https://content-mms.staging.smshub.world/templates/491aa990-1fbb-4058-8af0-c78049010d2f/attachments/2-unnamed-1.png",
          "content_type": "image/png",
          "content_location": "unnamed-1.png"
        }
      ],
      "inserted_at": "2026-03-20T19:53:02.165449",
      "updated_at": "2026-03-20T19:53:02.165449",
      "placeholders": [
        "name",
        "company"
      ],
      "body_template": "Check out our new deals!",
      "subject_template": "New deals!"
    },
    "id": "491aa990-1fbb-4058-8af0-c78049010d2f",
    "type": "mms-template"
  }
}
```
