# Follow Up

## Create a new follow up

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

This endpoint allows you to create or update an existing follow up

**Headers**

| Name         | Value                                                                                               |
| ------------ | --------------------------------------------------------------------------------------------------- |
| Content-Type | `application/json`                                                                                  |
| Api-Key      | The API key of a valid AcyMailing license used in the AcyMailing configuration page, tab "License". |

**Body**

<table><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code>name</code></td><td>string</td><td>Name of the user</td></tr><tr><td><code>display_name</code></td><td>string</td><td>The name displayed in the front end when a user is on the unsubscribe page</td></tr><tr><td><code>trigger</code></td><td>string</td><td>When a follow up will be triggered, it should be one of these value:<br>- <strong>user_subscribe</strong>: When a user subscribe<br>- <strong>birthday</strong>: On user birthday<br>- <strong>user_creation</strong>: On user creation<br>- <strong>woocommerce_purchase</strong>: When a user purchase a product on WooCommerce<br>- <strong>hikashop_purchase</strong>: When a user purchase a product on WooCommerce</td></tr><tr><td><code>condition</code></td><td>array</td><td><p>This option is not required, if you want to add condition on the trigger:</p><pre class="language-json"><code class="lang-json">"condition": { // optionnal
  "lists_status": "is", // or "is_not"
  "lists": [1], // list ids
  "segments_status": "is_not",
  "segments": [1] // segment ids
}
</code></pre></td></tr><tr><td><code>loop</code></td><td>integer</td><td>1 or 0 if you want to loop the follow-up, this means that when sending the last follow-up email to a subscriber, the follow-up can be re-trigger and all emails are sent again to this subscriber</td></tr><tr><td><code>loop_delay</code></td><td>integer</td><td>You need to specify the amount of seconds.<br>If you want to loop you can add a delay before the follow-up is re-triggered, for example you send your first email 1 day after the trigger, if you add a delay of 2 days, the first email will be sent 3 days after the last email of the follow-up</td></tr><tr><td><code>loop_mail_skip</code></td><td>array</td><td>Array of mail ID to skip when the follow-up is looping</td></tr></tbody></table>

**Example of Body**

```json
{
    "followUpId": 3,
    "name": "Test follow-up",
    "display_name": "Test follow-up display name",
    "trigger": "user_subscribe",
    "condition": { // optionnal
        "lists_status": "is", // or "is_not"
        "lists": [1], // list ids
        "segments_status": "is_not",
        "segments": [1] // segment ids
    },
    "loop": 1, // 1 or 0, by default 0
    "loop_delay": 3600 // in seconds, so 1 hour here
    "loop_mail_skip": [1, 2] // mail ID to skip when follow-up is looping
}
```

**Response**

{% tabs %}
{% tab title="201" %}

```json
{
  "followUpId": <followUpId>
}
```

{% endtab %}

{% tab title="404" %}
The follow up that you are trying to update doesn't exist
{% endtab %}

{% tab title="422" %}
This means that something is missing in the body
{% endtab %}

{% tab title="500" %}
Something went wrong while saving the follow up
{% endtab %}
{% endtabs %}

## Attach an email to a follow up

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

This endpoint allows you to create and attach an email to a follow up.\
You can also update an existing email attached to a follow up.

**Headers**

| Name         | Value                                                                                               |
| ------------ | --------------------------------------------------------------------------------------------------- |
| Content-Type | `application/json`                                                                                  |
| Api-Key      | The API key of a valid AcyMailing license used in the AcyMailing configuration page, tab "License". |

**Body**

<table><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code>followUpId</code></td><td>number</td><td>The ID of the follow up you want to attach an email to</td></tr><tr><td><code>delay</code></td><td>number</td><td>The delay of the email in the follow-up</td></tr><tr><td><code>delay_unit</code></td><td>number</td><td>The unit of the delay, its value should be one of these:<br>- minutes <br>- hours<br>- days<br>- weeks<br>- months</td></tr><tr><td><code>mail</code></td><td>array</td><td><p>The email to send, here is the structure:</p><pre class="language-json"><code class="lang-json"><strong>{
</strong>  //"id": 40, // If you want to update an email add its id
  "name": "Mail followup 1",
  "subject": "Subject follow-up 1",
  "body": "This is the body of the first follow-up",
  "bcc": "", // optional, email separated by comma
  "from_name": "", // optional, by default it takes the value in the configuration
  "from_email": "", // optional, by default it takes the value in the configuration
  "reply_to_name": "", // optional, by default it takes the value in the configuration
  "reply_to_email": "", // optional, by default it takes the value in the configuration
  "bounce_email": "", // optional, by default it takes the value in the configuration
  "preheader": "" // optional, short text displayed in the receiver's inbox, next to the subject
}
</code></pre></td></tr></tbody></table>

**Example of body**

```json
{
    "followUpId": 3,
    "mail": {
        "name": "Mail followup 2",
        "subject": "Subject follow-up 2",
        "body": "This is the body of the second follow-up",
        "bcc": "", // optional, email separated by comma
        "from_name": "", // optional, by default it takes the value in the configuration
        "from_email": "", // optional, by default it takes the value in the configuration
        "reply_to_name": "", // optional, by default it takes the value in the configuration
        "reply_to_email": "", // optional, by default it takes the value in the configuration
        "bounce_email": "", // optional, by default it takes the value in the configuration
        "preheader": "" // optional, short text displayed in the receiver's inbox, next to the subject
    },
    "delay": 12,
    "delay_unit": "minutes"
}
```

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
    "message": "Email attached to follow-up.",
    "mailId": 43
}
```

{% endtab %}

{% tab title="404" %}
The email that you are trying to update doesn't exist
{% endtab %}

{% tab title="422" %}
This means that something is missing in the body
{% endtab %}

{% tab title="500" %}
Something went wrong when saving the email or attaching it to the follow up
{% endtab %}
{% endtabs %}

## Delete an email from a follow up

<mark style="color:red;">`DELETE`</mark> `https://www.example.com/index.php?page=acymailing_front&option=com_acym&ctrl=deleteEmailFromFollowUp`

This endpoint allows you to delete an emails from a follow up

**Headers**

| Name         | Value                                                                                               |
| ------------ | --------------------------------------------------------------------------------------------------- |
| Content-Type | `application/json`                                                                                  |
| Api-Key      | The API key of a valid AcyMailing license used in the AcyMailing configuration page, tab "License". |

**Query**

| Name         | Type   | Description         |
| ------------ | ------ | ------------------- |
| `followUpId` | number | ID of the follow up |
| `mailId`     | number | ID of the email     |

**Example of query**

`https://www.example.com/index.php?page=acymailing_front&option=com_acym&ctrl=deleteEmailFromFollowUp&followUpId=3&mailId=43`

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
    "message": "Email deleted from follow-up."
}
```

{% endtab %}

{% tab title="404" %}
The follow up or the email do not exist
{% endtab %}

{% tab title="500" %}
Something went wrong when deleting the email
{% endtab %}
{% endtabs %}

## Delete a follow up

<mark style="color:red;">`DELETE`</mark> `https://www.example.com/index.php?page=acymailing_front&option=com_acym&ctrl=deleteFollowUp`

This endpoint allows you to delete a follow up

**Headers**

| Name         | Value                                                                                               |
| ------------ | --------------------------------------------------------------------------------------------------- |
| Content-Type | `application/json`                                                                                  |
| Api-Key      | The API key of a valid AcyMailing license used in the AcyMailing configuration page, tab "License". |

**Query**

| Name         | Type   | Description                   |
| ------------ | ------ | ----------------------------- |
| `followUpId` | number | ID of the follow up to delete |

**Example of query**

`https://www.example.com/index.php?page=acymailing_front&option=com_acym&ctrl=deleteFollowUp&followUpId=3`

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
    "message": "Follow-up deleted."
}
```

{% endtab %}

{% tab title="404" %}
The follow up doesn't exist
{% endtab %}

{% tab title="422" %}
The follow up ID information is missing
{% endtab %}

{% tab title="500" %}
Something went wrong when deleting the follow up
{% endtab %}
{% endtabs %}

## Get all follow ups

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

This endpoint allows you to get all the follow ups

**Headers**

| Name         | Value                                                                                               |
| ------------ | --------------------------------------------------------------------------------------------------- |
| Content-Type | `application/json`                                                                                  |
| Api-Key      | The API key of a valid AcyMailing license used in the AcyMailing configuration page, tab "License". |

**Query**

<table><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code>offset</code></td><td>number</td><td>The start of the followup you want to be returned from the database, by default it's value is 0</td></tr><tr><td><code>limit</code></td><td>number</td><td>The number of follow up returned, by default it's 100</td></tr><tr><td><code>filters</code></td><td>array</td><td><p>You can filters follow up by column value:</p><pre class="language-json"><code class="lang-json">[
  "id": 3,
  "name": "part of the name",
  "display_name": "Test",
  "active": 1,
  "send_once": 0,
  "trigger": "user_subscribe"
]
</code></pre></td></tr></tbody></table>

**Example of Query**

Query to get follow ups with **test** in the name

`https://www.example.com/index.php?page=acymailing_front&option=com_acym&ctrl=getFollowUps&filter[name]=test`

Query to get 3 follow ups with the **trigger** birthday

`https://www.example.com/index.php?page=acymailing_front&option=com_acym&ctrl=getFollowUps&filter[trigger]=birthday&limit=3`\
**Response**

{% tabs %}
{% tab title="200" %}

```json
[
    {
        "id": 1,
        "name": "test 1",
        "display_name": "Test 1",
        "creation_date": "2024-04-23 13:27:41",
        "trigger": "user_subscribe",
        "condition": {
            "lists_status": "is",
            "segments_status": "is"
        },
        "active": 1,
        "send_once": 1,
        "list_id": 3,
        "last_trigger": 1718005129
    },
    {
        "id": 2,
        "name": "test 2",
        "display_name": "Test 2",
        "creation_date": "2024-05-23 08:20:05",
        "trigger": "user_subscribe",
        "condition": {
            "lists_status": "is",
            "lists": [
                "1"
            ],
            "segments_status": "is_not",
            "segments": [
                "1"
            ]
        },
        "active": 1,
        "send_once": 1,
        "list_id": 4,
        "last_trigger": 1718005129
    }
]
```

{% endtab %}
{% endtabs %}

## Get one follow up by ID

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

This endpoint allows you to get a specific follow up

**Headers**

| Name         | Value                                                                                               |
| ------------ | --------------------------------------------------------------------------------------------------- |
| Content-Type | `application/json`                                                                                  |
| Api-Key      | The API key of a valid AcyMailing license used in the AcyMailing configuration page, tab "License". |

**Query**

| Name         | Type   | Description                    |
| ------------ | ------ | ------------------------------ |
| `followUpId` | number | The ID of the follow up to get |

**Example of Query**

`https://www.example.com/index.php?page=acymailing_front&option=com_acym&ctrl=getFollowUpById&followUpId=1`

**Response**

{% tabs %}
{% tab title="200" %}

```json
[
    {
        "id": 1,
        "name": "test 1",
        "display_name": "Test 1",
        "creation_date": "2024-04-23 13:27:41",
        "trigger": "user_subscribe",
        "condition": {
            "lists_status": "is",
            "segments_status": "is"
        },
        "active": 1,
        "send_once": 1,
        "list_id": 3,
        "last_trigger": 1718005129,
        "mails": [
            {
                "mail_id": 26,
                "followup_id": 1,
                "delay": 0,
                "delay_unit": 86400,
                "send_once": 1
            },
            {
                "mail_id": 43,
                "followup_id": 1,
                "delay": 12,
                "delay_unit": 60,
                "send_once": 1
            }
        ]
    }
]
```

{% endtab %}

{% tab title="400" %}

```json
{
  "error": "Invalid request"
}
```

{% endtab %}
{% endtabs %}
