Skip to content
Automatic campaigns

Automatic campaigns

By Loïc Bresler 2 min read

An automatic campaign is prepared once in the interface, then the API triggers it on demand, for one recipient or for a batch. It is the only REST API method that actually sends emails to recipients, apart from the test send.

The method is called with POST, with a JSON body that contains your api_key. See the common rules.

Trigger an automatic campaign

Access point: https://www.mdworks.fr/api_http/envoi_mail_auto

This method sends the email prepared in Marketing automation > Automatic campaigns to the recipients passed in the call. The message is personalised if the template is designed for it.

Parameters:

ParameterTypeRequiredDescription
campaign_idintegeryesID of the automatic campaign to use
tab_insertarray of arraysyesthe recipients, 255 rows at most per call

Each row of tab_insert is an array of values, without field names, in this order: email, last name, first name, then perso1 to perso24, that is 27 values at most. Only the first element, the email address, is required. Values missing at the end of the row count as empty.

For performance reasons, we advise against sending rows one by one when you have several recipients to process.

Example of posted data:

{
  "api_key": "YOUR_API_KEY",
  "campaign_id": 875246,
  "tab_insert": [
    ["test@ediware.net", "Martin", "Hugo"],
    ["test2@ediware.net", "Dupont", "Laurent"]
  ]
}

PHP example:

$url = 'https://www.mdworks.fr/api_http/envoi_mail_auto';

$tab_insert = array(
    array('test@ediware.net', 'Martin', 'Hugo'),
    array('test2@ediware.net', 'Dupont', 'Laurent')
);

$data = array(
    'api_key'     => 'YOUR_API_KEY',
    'campaign_id' => 875246,
    'tab_insert'  => $tab_insert
);

$json = json_encode($data, JSON_UNESCAPED_UNICODE);

// Send with cURL
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

echo $response;

Response:

{"result": "ok", "campaign_id": 875246, "increment": 359}

Errors:

MessageCause
Error campaign_id is missing
Error tab_insert is missing
Error tab_insert is not an array
Error this list not owned by auth userthe campaign does not belong to your account
Error this campaign is not automaticthe campaign is not an automatic campaign

If the account’s credit is insufficient, the response takes a particular form, without an error key:

{"result": "error", "detail": "Crédit insuffisant pour envoyer cet email"}

So test result in your code too, not just the presence of error.

Last updated on