ahasend messages send --template-id sends.
These commands need CLI v0.3.0 or later. Check your version with
ahasend --version, and upgrade if it is older.Prerequisites
Authenticate with a full API key. Template tasks need these scopes:messages send --template-id needs only the send scope of the sender’s domain, not a templates scope. The shell examples need Bash and jq.
Drafts, Publishing and Versions
Changes to a template go to its draft, the same draft the dashboard edits. Sends use the published copy, so publish the draft with--publish or templates publish before you send. A template created without --publish has only a draft, and sends of it fail until you publish it.
On CLI v0.4.0 or later, templates get shows the template’s working copy: its draft while it has one, and its published copy otherwise. Has Draft says which one it shows. templates update changes this copy, so a change builds on what templates get shows. templates get --published shows the published copy, the one sends use. templates list lists each template as its published copy.
Every publish is kept as a version. A template keeps its 50 most recent versions, and you can restore any of them into the draft.
Create, Publish and Send a Test Template
Save this file aswelcome.html:
welcome.html
hello@example.com. The send uses sandbox mode, so nothing is delivered.
templates get shows the draft. templates get --published shows the published copy, with the variables a send must supply. The template supplies the content, so messages send --template-id takes no content flags; --from and --subject default to the template’s sender and subject. Pass variable values with --global-substitutions or a --recipients file, as the messages commands describe.
Each variable shows its kind and whether a send must give it a value. A value shows no kind, as first_name (required). A condition, which only shows or hides part of the email, shows as vip (condition; optional). A list, whose section repeats for each element, shows the fields each element gives, as items (list of name/price; required), or tags (list; optional) when the section uses none. Variable kinds need CLI v0.4.0 or later; see kinds of variables.
Content comes from files. --markup-file sets the design of a simple template as AhaML, --mjml-file the MJML of an advanced template, and --html-file the HTML of an html template; you cannot combine them. --text-file sets the plain text version, which is otherwise made from the HTML. Give --editor when there is no markup, MJML or HTML file. The editor cannot change after you create the template.
Update the Draft
Continue the script.update sends only the flags you give. Every field but the name goes to the draft; a new name applies at once.
templates get shows the draft with the new subject, and templates get --published shows the published copy without it. update --publish publishes the whole draft, including changes made in the dashboard; on its own it only publishes. To drop a draft instead, run ahasend templates draft discard "$TEMPLATE_ID" --force.
Other update flags:
--subject ""and--preheader ""clear those fields.--fromreplaces the sender address and name together.--clear-fromremoves the sender and the reply-to.--reply-toneeds a template that has a sender.--clear-reply-toremoves the reply-to.--regenerate-textmakes the text version again from the HTML.
AhaML Designs
The design of a simple template reads and writes as AhaML (AhaSend Markup), the text form of a Simple Editor design.templates get --markup writes only the design’s AhaML to stdout, so you can save it, edit it, and write it back with --markup-file. These flags need CLI v0.4.0 or later.
--markup writes the AhaML exactly as the API returned it; to a terminal, it escapes control characters. It cannot be used with --output. It fails with exit code 1 when there is no AhaML to write: for an advanced or html design, for a design with no content, and when the API could not give the design as AhaML.
On create, --markup-file makes the editor simple, and --editor advanced and --editor html cannot be used with it. On update, it replaces the design of a simple template. --text-file and --regenerate-text can be used with it. An empty file is rejected.
Without --markup, templates get shows the AhaML of a simple design in its Markup row. When the API could not give the design as AhaML, Markup Error says why, as <code>: <message>, such as html_block: ... for a design that holds an HTML block. templates versions get shows the same two rows. In CSV output, the columns markup and markup_error follow mjml, and the output of one template, such as from templates get, ends with a markup_warnings column.
A write that carries AhaML shows the API’s warnings about it in a Markup Warnings row, one per line, with the place in the AhaML when there is one:
List and Restore Versions
Continue the script.versions list shows each published version, newest first, without its content. The script reads the ID of the oldest version, its first publish, from the JSON output’s data array, then shows and restores that version:
--publish, a version that the publish checks refuse is refused before the restore, and the draft is left as it was.
Delete the Test Template
Finish the script by deleting the template it created. Sends of a deleted template fail.ahasend templates list and delete it with templates delete.
templates delete, templates draft discard and templates versions restore ask for confirmation first; see prompts.
Command Flags
These flags come from the CLI’s--help. All commands also accept the global flags.

