Newsletter
Your own newsletter to your own contacts, written and sent for you.
Newsletter's methods are what its screens call, from a signed-in dashboard session, and two that your website calls to sign a reader up. Every one of them carries the private flag, so a general API key cannot call them. They are listed so you know what the screens do. From outside the dashboard, only the two sign up methods are within reach: mailer_subscribe from the form on your site, and mailer_add_subscriber from your site's own code through the SDK.
A screen method acts for the owner of one workspace (the home one, or the workspace_id it is given), needs a session at user clearance, and answers code 1 when it works. A refusal answers a negative code and says why in data. The month's emails, the newsletters a plan keeps and what a newsletter's sections may hold are checked on the server, whatever a screen offered.
Ids
The dashboard calls a template a newsletter: the one its issues are made from.
- A newsletter reads
mlt_followed by 16 hex characters. - An issue reads
mli_, the newsletter's 16 hex characters, an underscore and its number: the first issue of a newsletter is 1. - An issue's state is
preparing,sending,paused,held_cap(waiting: the month's emails ran short),sentorcancelled.
Setup and plans
get_mailer_setupanswers what the screens start from: theplan, this month'susageand what is left, the plan'slimits, thesenders({ kind: 'platform' }, and{ kind: 'mailbox', email_account_id, address, provider }for each mailbox of the workspace that can send now), the contactgroupsandtags, the Commercestoresof this workspace, the WebPilotpilots, andbrand_default(the brand newsletters wear when they set none, the looks Branding allows and the website form token).get_mailer_plansreads the plans with their prices, features and entitlements, the plan this workspace is on, whether Newsletter is switched on, and how many newsletters it holds.mailer_set_planswitches Newsletter on, changes the plan (plan_idismailer_free,mailer_starter,mailer_growthormailer_business), or switches it off (an emptyplan_id, ordeactivateset totrue). Switching off keeps every newsletter and subscriber. Both plan methods take an optionalbilling_workspace_id, a workspace you own whose plan to read or change.
Newsletters
get_mailer_templateslists the newsletters, newest change first, with how many are live and how many the plan allows. Witharchivedset totrueit lists the archived ones.get_mailer_templatereads one (template_id): its subject, sections, audience, look, sender, footer and schedule, with its last ten issues.save_mailer_templatecreates a newsletter, or changes one. It takestemplate, the newsletter as a whole: its name, subject, preheader, language,audience(kindisall,grouportag, withgroup_ids,tagsandexclude_tags),theme(styleisplain,card,accentorminimal, and anaccentcolour), brand,sender(kindisplatformormailbox, withemail_account_id,from_nameandreply_to), postal address, footer,store_id(the store a Products for each reader section picks from) and up to 20 sections. A section's type iseditor,ai,commerce,webpilotordrive. Keys it does not know are dropped. It is refused when the newsletter uses something the plan does not include.archive_mailer_templatearchives a newsletter, which pauses its schedule (template_id,archivedset totrue), or restores one (archivedset tofalse), which counts against the plan's newsletters again.mailer_audience_countcounts anaudienceas the Audience tab shows it:selected(the live contacts of the audience, one for each address),subscribed(those of them who said yes and are not suppressed: the ones an issue mails) andsuppressed.
Sending
preview_mailer_issuedraws an issue as one contact reads it, without sending anything or spending credits:template_id, or atemplatenot saved yet, with an optionalcontact_id(their name and their products) and an optionalthemeto try. AI and article sections show what they will be made from. It answerssubjectandhtml.send_mailer_testsends a test to your own address or one of this workspace's mailboxes (template_id, an optionalto). It reads as the issue will: its AI sections are written and paid in AI credits, and its article sections are not started. Up to 20 a day, each counted against the month's emails.send_mailer_issue_to_contactsends an issue that went out, or is going out, to one contact of this workspace you pick (issue_id,contact_id), as their own copy: the mail a reader gets, with their own unsubscribe link, never a test. It is what putting a contact down on a newsletter's card does. It is refused for a contact with no email address, one who unsubscribed or whose address is suppressed, one who already got this issue, and past three newsletters to them in a week, and it counts against the month's emails and on the issue. It answers the issue'snumberand the contact'sname.mailer_send_issuesends the next issue of a newsletter to its audience: only contacts who said yes, never a suppressed address, at most three newsletters to a contact in a week. It takestemplate_id, aclient_key(4 to 80 letters, digits,_,:,.or-: the same key twice is the same issue, so a double press or a retried call never sends twice),trigger({ kind: 'now' }, the default, or{ kind: 'workflow', id, run_id, step_id }for a workflow's step), an optionalfirst_nanddry_run. It answersissue_id,stateandreaders. When the month has fewer emails left than readers, nothing is sent and the answer says how many are left: ask again withfirst_nto send to the first that many. Withdry_runset totrueit answers the issue's number and its readers and sends nothing.get_mailer_issueslists the issues, newest first, with their state and counts;template_idkeeps one newsletter's.get_mailer_issuereads one issue (issue_id) with its counts and its readers a page at a time:statekeeps the readers in one state (sending,sent,failed,skippedorbounced),limitis 1 to 200 (100 by default), andbookmarkis the one the page before answered.pause_mailer_issuepauses an issue being prepared or sent: nobody else is mailed until it is resumed.resume_mailer_issuesends the rest, from where it stopped: a paused issue, or one held because the month's emails ran out once the month has room again.cancel_mailer_issueends an issue that has not finished: readers already mailed stay mailed. Each takes anissue_id.
Subscribers and consent
get_mailer_subscriberslists the contacts by their newsletter consent, with where it came from and whether the address is suppressed. It takes an optionalsearch(part of a name or an address),state(subscribed, the default,unsubscribed,pendingorall),skipandlimit(1 to 200, 50 by default).set_mailer_consentsubscribes or unsubscribes up to 500 contacts you picked (contact_ids,subscribed). Subscribing is an import and needsattest_text, your statement of how these people asked to receive the newsletter, kept with each contact. Someone who unsubscribed or complained is never subscribed again this way.get_mailer_suppressionslists the addresses no newsletter goes to: hard bounces, repeated soft bounces, complaints, unsubscribes and the ones you added.mailer_lift_suppressiontakes oneemailoff the list. Only a bounce or one you added can be lifted: an unsubscribe or a complaint is the reader's to undo, by subscribing again.
The schedule
mailer_set_schedulesends a newsletter on a schedule:template_id,days(0 is Sunday to 6, Saturday),time(HH:MM, 24 hour),timezone(an IANA name such asEurope/Berlin, UTC by default) andenabled(falsepauses it). They become a workflow with a schedule trigger (Monday at nine is0 9 * * 1) and one Send issue step, and it answers theworkflow_id. A schedule counts against your Workflows plan, and the first one switches Workflows Free on. A change made in Workflows shows in the newsletter's Schedule tab.
From your website
Neither method makes a subscriber at once: the address is recorded as waiting, and gets a mail to confirm. Nobody receives an issue before they press its link.
mailer_subscribeis the public method behind the form on your site, called with no session:form_token(the token the form was published with, which names the workspace and the tags a sign up may get),email, an optionalname,tags(among the ones the form allows),hp(a field that must stay empty: a form that fills it is dropped quietly),captchawhen the server asks for one, andttoken, the human check token the form's page fetches when it opens (the same call withboot: trueand the form token answers it; it must be at least 3 seconds and at most 2 hours old). The boot call takeslang(the page's<html lang>) andvisitor_lang(the browser's) too, and answers the form's words, with their language and direction (lang,dir,words), in the first of the two that names a language the dashboard speaks, else in English; a refused boot call carries them too. A sign up takespage_langandvisitor_langthe same way, and the confirmation is written in the first that names a language, else in the workspace's newsletters' language, else the owner's. It checks the tokens, the hidden field and the rate limits, and answers the same way whether the address was new or already on the list. The form's own script calls it for you: mark a formdata-xuda-subscribe, with an email field (type="email"or namedemail), an optional name, and tags fromdata-xuda-tagsor checkboxes namedtags; or put an empty element markeddata-xuda-subscribe-boxwhere a plain form should be drawn.mailer_add_subscribersigns a reader up from your site's own code, with your site's key, through the SDK'sxuda.mailer.subscribe(email, { name, tags, lang }):email, an optionalname, up to fivetags,source(website, the default,site_apporapi) andlang, the language of the page the reader signed up on, which the confirmation is written in.
What is refused
The dashboard says each of these in words next to the control. In the method's answer they are a negative code with a sentence in data:
- Only the owner of a workspace sends from it. Newsletter is switched off in the workspace, or the plan's number of newsletters is reached.
- A section the plan does not hold: an AI or article section past the plan's number, Products for each reader on Free, a line for each reader below Growth, your own mailbox on Free, or the Xuda line taken off the footer below Growth.
- The newsletter is not ready: no subject, no section, no postal address, products with no store of this workspace, or a mailbox that cannot send.
- The month's emails would run short and no
first_nwas given, or nobody in the audience is subscribed. - A schedule fired again within 20 hours of the newsletter's last issue (Send now is not held), or the readers already got enough mail this week.
- More than 5 in every 100 of an issue's first 200 mails bounced hard, and at least three did: the issue is paused, and says so.
- There are not enough AI credits for an AI section, WebPilot is off for an article section, or a Drive file of the issue is gone or no longer public.