Preparing a campaign
These methods set up a draft email campaign: settings (subject, sender, preheader), HTML message and test send. Recipients are loaded with the methods on the Campaign recipients page, and the Building a campaign step by step page shows the full sequence.
They are all called with POST, with a JSON body that contains your api_key. Parameter tables do not repeat it. See the common rules.
Campaign statuses
The status is returned by campaign_list and campaign_get. campaign_list also accepts a status as a filter.
status | Meaning | Editable through the API |
|---|---|---|
draft | draft, neither scheduled nor sent | yes |
scheduled | sending scheduled | no |
partially_sent | sending in waves has started | no |
sent | sent | no |
automatic | automatic campaign, used by envoi_mail_auto | no |
other | rare special case, for instance an A/B test variant | no |
Only a draft campaign can be edited, receive a message, receive recipients through campaign_add_recipients, receive a test send or be deleted. To edit a scheduled campaign, first cancel its scheduling in the interface.
An API campaign is a raw HTML message
Every campaign set up through the API is a raw message: the message is a complete HTML document that you provide. In the interface, the campaign can still be edited with the source editor (“HTML code” button). The simplified editor and the responsive editor do not apply to these campaigns.
Create a campaign
Access point: https://www.mdworks.fr/api_http/campaign_create
This method creates a draft campaign. All parameters are optional and are passed in a single call. They are the same as for campaign_update.
Parameters:
| Parameter | Type | Default value | Check |
|---|---|---|---|
reference | text | “Campagne” followed by the timestamp | internal name of the campaign, 255 characters at most |
subject | text | “Nouvelle campagne” | subject of the message, 250 characters at most |
from_name | text | the account’s default sender name | 100 characters at most |
from_email | text | the account’s default sender email | valid email, 100 characters at most. See bounce_management |
reply_to | text | empty | valid email or empty, 100 characters at most |
bounce_management | 0 or 1 | 0 | automatic bounce handling, see below |
recipient_name | text | empty | name displayed for the recipient, 255 characters at most |
preheader | text | none | text shown below the subject by some mail clients, 512 characters at most |
language | code | derived from the account’s interface language: UK for English, DE for German, FR otherwise | language of the footer (unsubscribe link), see below |
Line breaks and tabs are replaced with spaces, and leading and trailing spaces are removed.
Maximum lengths apply after characters outside the Latin set have been converted to HTML entities (see text encoding). An emoji therefore counts for about 9 characters and the € sign for 7: keep some margin on a subject that contains them.
The campaign also takes the account’s other default settings, as in the interface: presence of the unsubscribe link, open tracking, consent.
language codes: FR, UK (English), DE, ES, IT, PT, NL, PO (Polish), CZ (Czech), HU (Hungarian), AR (Arabic). They are case-insensitive.
user_lang. language sets the language of the email footer of a campaign, with 11 two-letter codes, and English is written UK there. user_lang sets the language of the account’s interface, with 5 lowercase codes (fr, en, it, es, de). The two settings are independent and do not share their codes.Example of posted data:
{
"api_key": "YOUR_API_KEY",
"reference": "November newsletter",
"subject": "What's new in November 🚀",
"from_name": "Example Team",
"from_email": "contact@example.com",
"reply_to": "contact@example.com",
"preheader": "Three new things to discover",
"language": "UK"
}Response:
{"result": "ok", "campaign_id": 123456}Keep campaign_id: every following method needs it.
Errors: see the set-up errors.
Sender address and bounce handling
With bounce_management: 1, the platform handles bounces itself (invalid addresses, hard bounces). from_email then only contains the part before the @ (letters, digits, ., _, -), and the platform adds its return domain. campaign_get returns the full address.
| What you send | Resulting sender email |
|---|---|
neither from_email nor bounce_management | the account’s default sender email |
from_email: "contact@client.com" | contact@client.com |
bounce_management: 1 and from_email: "team" | team@ followed by the platform’s return domain |
bounce_management: 1 without from_email | part before the @ derived from the sender name: from_name: "Équipe Ediware" gives equipe-ediware@ followed by the return domain |
Without from_email, the part before the @ is derived from the sender name, as in the interface: the one in the call, otherwise the account’s. Accents are removed, spaces and punctuation become hyphens, everything is lowercased, and only the first 3 words are kept (40 characters at most). Without a sender name, the account login is used.
Edit a campaign
Access point: https://www.mdworks.fr/api_http/campaign_update
This method edits a draft campaign. It takes the same parameters as campaign_create, plus campaign_id. Only the parameters you send are changed.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
campaign_id | integer | yes | ID of the campaign to edit |
reference, subject, from_name, from_email, reply_to, bounce_management, recipient_name, preheader, language | no | see campaign_create |
Some special cases:
| What you send | Result |
|---|---|
| no parameter to change | Error nothing to update |
preheader: "" | removes the preheader |
bounce_management: 0 without from_email | the sender goes back to the account’s default email |
bounce_management: 1 without from_email | part before the @ derived from the sender name in the call, otherwise the campaign’s (see sender address) |
from_email alone, on a campaign already in bounce_management: 1 | from_email must be the part before the @ |
All checks run before the first write: a rejected call changes nothing.
Example of posted data:
{
"api_key": "YOUR_API_KEY",
"campaign_id": 123456,
"subject": "What's new in December",
"preheader": ""
}Response:
{"result": "ok", "campaign_id": 123456}To read the campaign back after editing it, use campaign_get.
Errors: see the set-up errors.
Load the HTML message
Access point: https://www.mdworks.fr/api_http/campaign_set_message
This method loads the HTML message of a draft campaign. Any previous message is replaced.
Parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
campaign_id | integer | yes | ID of the campaign | |
html | text | yes | the HTML message, 2 MB at most | |
track_links | boolean | no | true | false leaves every link in the message unchanged |
The platform does not accept a URL to download: you fetch the HTML yourself and send it in html.
What the platform does with the HTML:
- Fragments accepted. HTML without an
htmltag is wrapped in a complete document. - Scripts removed.
scriptandbasetags are deleted: they have no place in an email. - Click tracking. Each link is replaced with a tracking link that redirects to the original address,
mailto:andtel:links included. To leave a link unchanged, addno_tracking_url=trueto its URL, or passtrack_links: falsefor the whole message. - Images. They stay at their original address, the platform does not copy them. They must therefore be online, with an absolute
https://URL. - Accents and emojis. They are kept.
Example of posted data:
{
"api_key": "YOUR_API_KEY",
"campaign_id": 123456,
"html": "MESSAGE_HTML_CODE"
}MESSAGE_HTML_CODE is the content of your HTML file, encoded as a JSON string: double quotes become \" and line breaks \n. In PHP, json_encode() takes care of it.
Response:
{"result": "ok", "campaign_id": 123456, "tracked_links": 1}tracked_links gives the number of links turned into tracking links.
Errors specific to this method:
| Message | Cause |
|---|---|
Error html is missing | |
Error html is too big (2 MB max) | |
Error no tracking domain for this account | account without a configured tracking domain (rare), contact support |
Plus the set-up errors related to campaign_id and to the status.
Send a test
Access point: https://www.mdworks.fr/api_http/campaign_send_test
This method sends a test (proof) of a draft campaign to 1 to 10 test addresses. The subject is prefixed with “[BAT]”. Personalisation fields are replaced with visible markers (%nom%, %prenom%, %p1%…), as for a test sent from the interface. The campaign stays a draft.
The test goes out within minutes of the call.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
campaign_id | integer | yes | draft campaign, with a message and a sender email |
emails | array of strings | yes | 1 to 10 addresses. A duplicate address (case, spaces) is only counted once |
account_info gives the available credit.Example of posted data:
{
"api_key": "YOUR_API_KEY",
"campaign_id": 123456,
"emails": ["mary.smith@example.com", "john.brown@example.com"]
}Response:
{
"result": "ok",
"campaign_id": 123456,
"sent_to": 2,
"credits_used": 2,
"emails": ["mary.smith@example.com", "john.brown@example.com"]
}| Field | Description |
|---|---|
sent_to | number of addresses kept, duplicates removed |
credits_used | credits debited |
emails | addresses kept, in lowercase |
Errors specific to this method:
| Message | Cause |
|---|---|
Error emails is missing | |
Error emails must be an array | a single address must also be passed in an array |
Error emails must only contain strings | |
Error a BAT is limited to 10 addresses per call | |
Error X is not a valid email | address X is malformed |
Error the campaign has no valid from_email, use campaign_update | |
Error the campaign has no message, use campaign_set_message | |
Error BAT of a campaign with embedded images is only available in the interface | campaign with embedded images, set up in the interface |
Error not enough credits (X available, N needed) | insufficient credit. A variant without the available credit exists: Error not enough credits (N needed) |
Error BAT not queued, try again | temporary incident, try again |
Plus the set-up errors related to campaign_id and to the status. A rejected call sends nothing and debits nothing.
Delete a campaign
Access point: https://www.mdworks.fr/api_http/campaign_delete
This method deletes a draft campaign and its recipients.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
campaign_id | integer | yes | ID of the campaign to delete |
Example of posted data:
{
"api_key": "YOUR_API_KEY",
"campaign_id": 123456
}Response:
{"result": "ok", "campaign_id": 123456}Deletion is refused while recipients are being imported (Error an import is running on this campaign, try again later). To know when the import is finished, use campagne_import_status.
Set-up errors
Errors common to the methods on this page, in addition to the errors common to the whole API.
| Message | Methods | Cause |
|---|---|---|
Error campaign_id is missing or is not numeric | all except campaign_create | |
Error this user don't have access to campaign_id | all except campaign_create | campaign does not exist or belongs to another account |
Error this campaign is not a draft (scheduled, sent or automatic campaigns cannot be changed) | all except campaign_create | status other than draft |
Error PARAMETER must be a string | campaign_create, campaign_update | array, object or boolean instead of text |
Error PARAMETER is too long (N characters max) | campaign_create, campaign_update | |
Error reply_to is not a valid email | campaign_create, campaign_update | |
Error from_email is not a valid email | campaign_create, campaign_update | |
Error with bounce_management 1, from_email must only be the part before @ (letters, digits, . _ -) | campaign_create, campaign_update | |
Error from_email (the part before @) is required with bounce_management 1, it could not be derived from from_name | campaign_create, campaign_update | sender name with no letter or digit (only emojis, for instance): pass from_email |
Error bounce_management must be 0 or 1 | campaign_create, campaign_update | |
Error language must be DE, UK, AR, ES, FR, IT, PT, NL, PO, CZ or HU | campaign_create, campaign_update | |
Error nothing to update | campaign_update | no parameter to change |
Error no return domain for this account, use bounce_management 0 | campaign_create, campaign_update | account without a configured return domain (rare) |
Error account not found | campaign_create, campaign_update | |
Error campaign not created | campaign_create | server incident, try again |
In the messages, PARAMETER is replaced with the name of the parameter at fault and N with the maximum length.