# Templates

## Get one template

<mark style="color:blue;">`GET`</mark> `https://www.example.com/index.php?page=acymailing_front&option=com_acym&ctrl=api&task=getOneTemplate&templateId={id}`

Get one template by ID

#### Query Parameters

| Name                                         | Type | Description               |
| -------------------------------------------- | ---- | ------------------------- |
| templateId<mark style="color:red;">\*</mark> | Int  | ID of the template to get |

#### Headers

| Name                                      | Type   | Description                                                                                         |
| ----------------------------------------- | ------ | --------------------------------------------------------------------------------------------------- |
| Api-Key<mark style="color:red;">\*</mark> | String | The API key of a valid AcyMailing license used in the AcyMailing configuration page, tab "License". |

{% tabs %}
{% tab title="200: OK The template parameters and content" %}

```json
[
    {
        "id": "84",
        "name": "Test template",
        "creation_date": "2024-01-17 15:33:41",
        "drag_editor": "0",
        "body": "<div>Hello,</div><br /><div>This is a test for a simple template.</div>",
        "subject": "Test subject",
        "from_name": "Example",
        "from_email": "info@example.com",
        "reply_to_name": "John Doe",
        "reply_to_email": "john@example.com",
        "settings": "",
        "stylesheet": "div {font-size: 14px;}",
        "headers": "",
        "preheader": "Preview line to be seen in preview of mail content"
    }
]
```

{% endtab %}

{% tab title="404: Not Found There is no template for the provided ID" %}

```json
{
    "message": "Template not found."
}
```

{% endtab %}

{% tab title="422: Unprocessable Entity Missing template ID in the request" %}

```json
{
    "message": "Template ID not provided in the request."
}
```

{% endtab %}
{% endtabs %}

## Get templates

<mark style="color:blue;">`GET`</mark> `https://www.example.com/index.php?page=acymailing_front&option=com_acym&ctrl=api&task=getTemplates`

Get a collection of templates

#### Query Parameters

| Name         | Type   | Description                                                                                                                                                                                                                                                                                  |
| ------------ | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| filters      | Array  | <p>You can filter templates searching a text in their name/subject, or specifying the type of template ("drag" for drag and drop templates, "standard" for others, leave empty for both). Example:</p><p>\[</p><p>    "search": "New Year",</p><p>    "templateType": "standard"</p><p>]</p> |
| templateType | String | Type of template to get if you want only templates for standard editor (value: standard) or for drag and drop templates (value: drag). Don't use this parameter if you want all types.                                                                                                       |
| limit        | Int    | The number of templates you would like to get in your request, by default it's set to 20                                                                                                                                                                                                     |
| offset       | Int    | From which element in the database you would like to start getting templates, by default it's set to 0                                                                                                                                                                                       |

#### Headers

| Name                                      | Type   | Description                                                                                         |
| ----------------------------------------- | ------ | --------------------------------------------------------------------------------------------------- |
| Api-Key<mark style="color:red;">\*</mark> | String | The API key of a valid AcyMailing license used in the AcyMailing configuration page, tab "License". |

{% tabs %}
{% tab title="200: OK The list of templates" %}

```
[
    {
        "id": "84",
        "name": "Test template",
        "creation_date": "2024-01-15 15:33:41",
        "drag_editor": "0",
        "body": "<div>Hello,</div><br /><div>This is a test for a simple template.</div>",
        "subject": "Test subject",
        "from_name": "Example",
        "from_email": "info@example.com",
        "reply_to_name": "John Doe",
        "reply_to_email": "john@example.com",
        "settings": "",
        "stylesheet": "div {font-size: 14px;}",
        "headers": "",
        "preheader": "Preview line to be seen in preview of mail content"
    },
    {
        "id": "85",
        "name": "Test template 2",
        "creation_date": "2024-01-17 15:33:41",
        "drag_editor": "1",
        "body": "<div id=\"acym__wysid__template\" class=\"cell\">...</div>",
        "from_name": "Example",
        "from_email": "info@example.com",
        "reply_to_name": "John Doe",
        "reply_to_email": "john@example.com",
        "settings": "",
        "stylesheet": "div {font-size: 14px;}",
        "headers": "",
        "preheader": "Preview line to be seen in preview of mail content"
    }
]
```

{% endtab %}

{% tab title="500: Internal Server Error Error while getting the templates" %}

```
{
    "message": "Error getting the collection of templates: <detail on the error>"
}
```

{% endtab %}
{% endtabs %}

## Create a template

<mark style="color:green;">`POST`</mark> `https://www.example.com/index.php?page=acymailing_front&option=com_acym&ctrl=api&task=createTemplate`

Templates created like this can only be edited with the website editor and not the drag and drop one.

#### Headers

| Name                                           | Type   | Description                                                                                         |
| ---------------------------------------------- | ------ | --------------------------------------------------------------------------------------------------- |
| Api-Key<mark style="color:red;">\*</mark>      | String | The API key of a valid AcyMailing license used in the AcyMailing configuration page, tab "License". |
| Content-Type<mark style="color:red;">\*</mark> | String | application/json                                                                                    |

#### Request Body

| Name                                   | Type   | Description                                                                   |
| -------------------------------------- | ------ | ----------------------------------------------------------------------------- |
| name<mark style="color:red;">\*</mark> | String | Name of the template                                                          |
| subject                                | String | Default subject of emails created using this template                         |
| body                                   | String | HTML content of the email (only the body part)                                |
| from\_name                             | String | Default from name for emails created using this template                      |
| from\_email                            | String | Default from email address for emails created using this template             |
| reply\_to\_name                        | String | Default reply-to name for emails created using this template                  |
| reply\_to\_email                       | String | Default reply-to email address for emails created using this template         |
| headers                                | String | Extra headers to add to emails created using this template                    |
| preheader                              | String | Preview line displayed in mail clients for emails created using this template |
| stylesheet                             | String | CSS to be added to the email                                                  |

{% tabs %}
{% tab title="201: Created Template successfully created" %}
The answers will contains the ID of the template created

```json
{
    "templateId": 9
}
```

{% endtab %}

{% tab title="422: Unprocessable Entity The template name is missing" %}

```json
{
    "message": "Missing template name."
}
```

{% endtab %}

{% tab title="500: Internal Server Error An error occurred when creating the template" %}

```json
{
    "message": "Error creating template."
}
```

{% endtab %}
{% endtabs %}

## Modify a template

<mark style="color:green;">`POST`</mark> `https://www.example.com/index.php?page=acymailing_front&option=com_acym&ctrl=api&task=updateTemplate`

Modify an existing template

#### Headers

| Name                                           | Type   | Description                                                                                         |
| ---------------------------------------------- | ------ | --------------------------------------------------------------------------------------------------- |
| Api-Key<mark style="color:red;">\*</mark>      | String | The API key of a valid AcyMailing license used in the AcyMailing configuration page, tab "License". |
| Content-Type<mark style="color:red;">\*</mark> | String | application/json                                                                                    |

#### Request Body

| Name                                         | Type   | Description                                                                   |
| -------------------------------------------- | ------ | ----------------------------------------------------------------------------- |
| templateId<mark style="color:red;">\*</mark> | Int    | ID of the template to modify                                                  |
| preheader                                    | String | Preview line displayed in mail clients for emails created using this template |
| headers                                      | String | Extra HTML headers to add to emails created using this template               |
| reply\_to\_email                             | String | Default reply-to email address for emails created using this template         |
| reply\_to\_name                              | String | Default reply-to name for emails created using this template                  |
| from\_email                                  | String | Default from email address for emails created using this template             |
| from\_name                                   | String | Default from name for emails created using this template                      |
| body                                         | String | HTML content of the email (only the body part)                                |
| subject                                      | String | Default subject of emails created using this template                         |
| name                                         | String | Name of the template                                                          |
| stylesheet                                   | String | CSS to be added to the email                                                  |

{% tabs %}
{% tab title="200: OK Template modified" %}

```
{
    "templateId": "85"
}
```

{% endtab %}

{% tab title="422: Unprocessable Entity Missing or incorrect template ID" %}

```json
{
    "message": "Missing or incorrect template ID."
}
```

{% endtab %}

{% tab title="404: Not Found There is no template for the provided ID" %}

```json
{
    "message": "Missing or incorrect template ID."
}
```

{% endtab %}

{% tab title="403: Forbidden You are trying to modify a non standard template " %}

```
{
    "message": "You can't edit this template."
}
```

{% endtab %}

{% tab title="500: Internal Server Error Error while modifying the template" %}

```
{
    "message": "Error modifying template."
}
```

{% endtab %}
{% endtabs %}

## Delete a template

<mark style="color:red;">`DELETE`</mark> `https://www.example.com/index.php?page=acymailing_front&option=com_acym&ctrl=api&task=deleteTemplate&templateId={id}`

#### Query Parameters

| Name                                         | Type | Description                  |
| -------------------------------------------- | ---- | ---------------------------- |
| templateId<mark style="color:red;">\*</mark> | Int  | ID of the template to delete |

#### Headers

| Name                                      | Type   | Description                                                                                         |
| ----------------------------------------- | ------ | --------------------------------------------------------------------------------------------------- |
| Api-Key<mark style="color:red;">\*</mark> | String | The API key of a valid AcyMailing license used in the AcyMailing configuration page, tab "License". |

{% tabs %}
{% tab title="200: OK Template deleted" %}

```json
{
    "message": "Template deleted."
}
```

{% endtab %}

{% tab title="404: Not Found There is no template for the provided ID" %}

```json
{
    "message": "Template not found."
}
```

{% endtab %}

{% tab title="422: Unprocessable Entity Missing template ID in the request" %}

```json
{
    "message": "Template ID not provided in the request."
}
```

{% endtab %}

{% tab title="500: Internal Server Error An error occurred while deleting the template" %}

```json
{
    "message": "Failed deleting template."
}
```

{% endtab %}
{% endtabs %}
