Skip to content
Preparing a campaign

Preparing a campaign

By Loïc Bresler 9 min read

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.

The API prepares the campaign but does not send it. The send and the scheduling are then done in the interface, once the test has been approved.

Campaign statuses

The status is returned by campaign_list and campaign_get. campaign_list also accepts a status as a filter.

statusMeaningEditable through the API
draftdraft, neither scheduled nor sentyes
scheduledsending scheduledno
partially_sentsending in waves has startedno
sentsentno
automaticautomatic campaign, used by envoi_mail_autono
otherrare special case, for instance an A/B test variantno

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:

ParameterTypeDefault valueCheck
referencetext“Campagne” followed by the timestampinternal name of the campaign, 255 characters at most
subjecttext“Nouvelle campagne”subject of the message, 250 characters at most
from_nametextthe account’s default sender name100 characters at most
from_emailtextthe account’s default sender emailvalid email, 100 characters at most. See bounce_management
reply_totextemptyvalid email or empty, 100 characters at most
bounce_management0 or 10automatic bounce handling, see below
recipient_nametextemptyname displayed for the recipient, 255 characters at most
preheadertextnonetext shown below the subject by some mail clients, 512 characters at most
languagecodederived from the account’s interface language: UK for English, DE for German, FR otherwiselanguage 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.

Do not confuse with 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 sendResulting sender email
neither from_email nor bounce_managementthe 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_emailpart 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:

ParameterTypeRequiredDescription
campaign_idintegeryesID of the campaign to edit
reference, subject, from_name, from_email, reply_to, bounce_management, recipient_name, preheader, languagenosee campaign_create

Some special cases:

What you sendResult
no parameter to changeError nothing to update
preheader: ""removes the preheader
bounce_management: 0 without from_emailthe sender goes back to the account’s default email
bounce_management: 1 without from_emailpart 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: 1from_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:

ParameterTypeRequiredDefaultDescription
campaign_idintegeryesID of the campaign
htmltextyesthe HTML message, 2 MB at most
track_linksbooleannotruefalse 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:

  1. Fragments accepted. HTML without an html tag is wrapped in a complete document.
  2. Scripts removed. script and base tags are deleted: they have no place in an email.
  3. Click tracking. Each link is replaced with a tracking link that redirects to the original address, mailto: and tel: links included. To leave a link unchanged, add no_tracking_url=true to its URL, or pass track_links: false for the whole message.
  4. Images. They stay at their original address, the platform does not copy them. They must therefore be online, with an absolute https:// URL.
  5. 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:

MessageCause
Error html is missing
Error html is too big (2 MB max)
Error no tracking domain for this accountaccount 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:

ParameterTypeRequiredDescription
campaign_idintegeryesdraft campaign, with a message and a sender email
emailsarray of stringsyes1 to 10 addresses. A duplicate address (case, spaces) is only counted once
A test sent through the API costs one credit per address, unlike a test sent from the interface, because it can be automated. For a subscription account, it counts towards the monthly and daily sending volume. The test is refused if the credit is insufficient: 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"]
}
FieldDescription
sent_tonumber of addresses kept, duplicates removed
credits_usedcredits debited
emailsaddresses kept, in lowercase

Errors specific to this method:

MessageCause
Error emails is missing
Error emails must be an arraya 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 emailaddress 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 interfacecampaign 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 againtemporary 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.

Deletion cannot be undone.

Parameters:

ParameterTypeRequiredDescription
campaign_idintegeryesID 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.

MessageMethodsCause
Error campaign_id is missing or is not numericall except campaign_create
Error this user don't have access to campaign_idall except campaign_createcampaign 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_createstatus other than draft
Error PARAMETER must be a stringcampaign_create, campaign_updatearray, 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 emailcampaign_create, campaign_update
Error from_email is not a valid emailcampaign_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_namecampaign_create, campaign_updatesender name with no letter or digit (only emojis, for instance): pass from_email
Error bounce_management must be 0 or 1campaign_create, campaign_update
Error language must be DE, UK, AR, ES, FR, IT, PT, NL, PO, CZ or HUcampaign_create, campaign_update
Error nothing to updatecampaign_updateno parameter to change
Error no return domain for this account, use bounce_management 0campaign_create, campaign_updateaccount without a configured return domain (rare)
Error account not foundcampaign_create, campaign_update
Error campaign not createdcampaign_createserver incident, try again

In the messages, PARAMETER is replaced with the name of the parameter at fault and N with the maximum length.

Last updated on