Campaign recipients
Two methods load the recipients of a campaign, depending on where the contacts come from:
| Your contacts | Method |
|---|---|
| come from another tool (CRM, business database, file) | campaign_add_recipients, in batches of 255 |
| are already in a list on the platform | inject_segmentlist_2_campaign, with an optional filter |
In both cases, the platform then cleans the recipients. campagne_import_status tells you when it is finished, and mails_retires_imports lists the removed addresses.
These methods are all called with POST, with a JSON body that contains your api_key. Parameter tables do not repeat it. See the common rules.
Add recipients
Access point: https://www.mdworks.fr/api_http/campaign_add_recipients
This method adds recipients to a draft campaign, 255 rows at most per call. Recipients already in the campaign are kept: you can chain as many calls as needed.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
campaign_id | integer | yes | ID of the campaign |
tab_insert | array of objects | yes | 1 to 255 rows |
Each row is an object whose possible keys are:
| Key | Max length | Role |
|---|---|---|
email | 200 | recipient address, required for the row to be kept |
nom, prenom | 200 | personalisation (last name, first name) |
perso1 to perso24 | 255 | free personalisation fields |
A missing key counts as empty. Keys are case-insensitive.
Example of posted data:
{
"api_key": "YOUR_API_KEY",
"campaign_id": 123456,
"tab_insert": [
{"email": "mary.smith@example.com", "nom": "Smith", "prenom": "Mary", "perso1": "London"},
{"email": "john.brown@example.com", "nom": "Brown", "prenom": "John"}
]
}Response:
{"result": "ok", "campaign_id": 123456, "received": 2, "inserted": 2, "ignored": 0, "total": 2}| Field | Description |
|---|---|
received | rows received |
inserted | rows added |
ignored | rows discarded: no email, or address already in the campaign |
total | recipients of the campaign after the addition, before the cleaning |
Row processing, the same as for a file imported in the interface:
- the email is lowercased, with spaces and quotes removed;
- an address already in the campaign is ignored, so there are no duplicates;
- accents, € and emojis are accepted in every field.
Automatic cleaning of recipients
A few tens of seconds after the addition, the platform removes from the campaign:
- malformed emails;
- unsubscribed addresses, from the platform or from your account;
- spam traps;
- hard-bounced addresses.
To track this cleaning, campagne_import_status answers "running" until it is finished, then the final number of recipients. mails_retires_imports then lists the removed addresses and the reason.
Retry during a cleaning
An addition is refused while the campaign’s cleaning is running, with the message Error a cleaning of the recipients is running on this campaign, try again in a few seconds.
The cleaning usually lasts a few seconds: simply send the same batch again. Build an automatic retry on this error into your code, with several attempts 10 to 30 seconds apart. The Building a campaign step by step page gives an example.
Errors:
| Message | Cause |
|---|---|
Error tab_insert is missing or is not an array | |
Error tab_insert is limited to 255 rows per call | split into batches of 255 rows |
Error row N is not an object | row N is not a JSON object |
Error row N: unknown field X (allowed: email, nom, prenom, perso1 to perso24) | field mapping error: key X is not recognised |
Error row N: field X must be a string | array or object instead of text |
Error row N: field X is too long (L characters max) | |
Error this campaign has a segmented sending, recipients cannot be changed | a segmented send is configured in the interface |
Error a cleaning of the recipients is running on this campaign, try again in a few seconds | try again, see above |
Error the recipients table of this campaign is missing | incident, contact support |
The errors related to campaign_id and to the campaign status, described in the set-up errors, also apply. A rejected call writes nothing: all checks run before the first addition.
Inject a segment of a list into a campaign
Access point: https://www.mdworks.fr/api_http/inject_segmentlist_2_campaign
This method injects an extract of a platform contact list into a campaign. The list must be accessible to the user: the user must own it, or be among the users it is shared with.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
list_id | integer | yes | ID of the list (see list_list) |
campaign_id | integer | yes | ID of the campaign |
filter | text | yes | a key / value object encoded as JSON, the key being a field of the list and the value the string to look for. Several keys are combined (all must match). To inject the whole list, pass an empty object: "{}" |
filter keys are case-sensitive: they must use the exact field name as defined when the list was created (NAF_700, not naf_700). Note that list_fields returns names in lowercase: for a list whose fields were created in uppercase, use the original name here.Example of posted data:
{
"api_key": "YOUR_API_KEY",
"list_id": "4781",
"campaign_id": "784541",
"filter": "{\"NAF_700\":\"0111Z\",\"EFFECTIF\":0}"
}Example of a PHP variable:
$filter = json_encode(array('NAF_700' => '0111Z', 'EFFECTIF' => 0));Response:
{"result": "ok"}Injected contacts go through the same automatic cleaning as those added with campaign_add_recipients.
Errors:
| Message | Cause |
|---|---|
Error list_id is missing or is not numeric | |
Error campaign_id is missing or is not numeric | |
Error filter is missing | filter missing or empty: pass "{}" for the whole list |
Error X is not in the fields of list N | key X of filter is not a field of the list (mind the case) |
Error there is not email fields in the list N | the list has no email field defined |
Error this user don't have access to list_id | list neither owned nor shared |
Error this user don't have access to campaign_id | campaign does not exist or belongs to another account |
Check that the import is finished
Access point: https://www.mdworks.fr/api_http/campagne_import_status
This method tells you whether the import of contacts into a campaign, and their cleaning, are finished.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
campaign_id | integer | yes | ID of the campaign |
Example of posted data:
{
"api_key": "YOUR_API_KEY",
"campaign_id": "784541"
}Response while processing is running:
{"result": "running"}Response once processing is finished: the final number of recipients, as a number and not as text.
{"result": 42053}Call this method in a loop, with a pause of a few seconds between calls, until you get a number.
Errors:
| Message | Cause |
|---|---|
Error campaign_id is missing or is not numeric | |
Error this user don't have access to campaign_id | campaign does not exist or belongs to another account |
Retrieve the addresses removed at import
Access point: https://www.mdworks.fr/api_http/mails_retires_imports
This method returns the addresses removed when a campaign’s recipients were imported, whatever the import method (interface, API, etc.). This information remains available for about a month after the import. Emptying a campaign’s recipients deletes it immediately.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
campaign_id | integer | yes | ID of the campaign |
Example of posted data:
{
"api_key": "YOUR_API_KEY",
"campaign_id": "234433"
}Response: an array of objects.
[
{
"date": "2024-02-19",
"email": "test@test.com",
"raison": "npai"
},
{
"date": "2024-02-19",
"email": "test2.test.com",
"raison": "errone"
}
]Possible values for raison:
| Reason | Meaning |
|---|---|
errone | malformed address |
desabo | unsubscribed from the account, through the unsubscribe link of its emails |
desabo_client | present in an exclusion list imported by the account |
radiation | present in the suppression list of the reseller (parent account) |
radiation_prospection | opted out of all emails sent by the platform |
spamtrap | spam trap |
npai | hard-bounced address |
Errors:
| Message | Cause |
|---|---|
Error campaign_id is missing or is not numeric | |
Error this user don't have access to campaign_id | campaign does not exist or belongs to another account |
No result | no address removed, or information expired |