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. Campaign tasks need these scopes:
The examples also create a test list, which needs
lists:write and lists:delete. The shell examples need Bash and jq.
A campaign is a draft until it is sent, and only a draft can be changed or deleted. A draft shows whether it is ready to send and, when it is not, each issue in the way.
Draft and Test a Campaign
Save this file ascampaign.html. A campaign’s HTML must use {{ unsubscribe_url }} or {{ unsubscribe_link }}; see unsubscribe link:
campaign.html
news@example.com, and your own inbox in place of me@example.com. The script creates an empty test list, so the campaign has no audience, and sends only a test.
campaigns get shows whether a draft is ready and lists each issue as code: message, such as a missing sender, list, subject, preview text or design. Fix them with campaigns update, which sends only the flags you give. --list-id replaces the campaign’s lists, --from replaces the sender address and name together, and --subject "" and --preheader "" clear those fields.
campaigns test sends to up to 5 addresses, with placeholders for the contact’s fields. A campaign with issues is refused, and each issue is listed. Every issue blocks a test except unsubscribe_link_missing. The output shows the addresses the mail server accepted and refused, and the command exits with code 1 when any address was refused. When the server’s answer could not be read, the test may have gone out, so check the inboxes before you send another.
The API allows 50 test emails a UTC day for each account, one for each address of each test. A test that would pass that limit is refused with daily test send limit reached and exit code 8.
Choose the Audience
A campaign’s audience is the lists and segments it sends to, and the lists and segments whose contacts get no message from it, even when a list or segment it sends to reaches them.campaigns create and campaigns update set each part with its own flag:
Every flag but
--list-id needs CLI v0.4.0 or later, as do --clear-lists, --clear-segments, --clear-exclude-lists and --clear-exclude-segments.
- Each flag can be used more than once, and each value splits on commas.
- A campaign uses at most 50 lists and 10 segments, included and excluded together, counting an ID given twice once. More fail before any request, with exit code 4 and
--list-id and --exclude-list-id take at most 50 lists in all, got <n>or--segment-id and --exclude-segment-id take at most 10 segments in all, got <n>. The CLI counts the IDs a command gives; the API checks the sets it stores. - On
update, each flag replaces its part of the audience, and a part that no flag names is kept.--clear-lists,--clear-segments,--clear-exclude-listsand--clear-exclude-segmentsempty a part, and each cannot be combined with the flag of its part. The API refuses a campaign left with no list and no segment to send to; see Audience. campaigns getshows the audience by ID in itsLists,Segments,Excluded ListsandExcluded Segmentsrows. CSV output has the columnslist_ids,segment_ids,exclude_list_idsandexclude_segment_ids.
building while AhaSend finds its members; see segment states. While a segment of the audience is building, campaigns create, campaigns duplicate and a campaigns update that changes the audience wait for it, and can fail with HTTP 409, The campaign's audience is being updated. Try again in a minute., and exit code 1. The API keeps no answer to such a request for its idempotency key, so run the same command again, with the same --idempotency-key or a new one. ahasend segments get shows a segment’s state. A send is refused instead, as the next section describes.
Send or Schedule a Campaign
campaigns send sends a draft now, or at the time given with --schedule: an RFC 3339 time or a relative one such as 2h. The API takes a time more than a minute ahead. The campaign then goes through audience validation and review before it sends; follow its status with campaigns get.
campaigns send asks for confirmation first, as prompts describes. The prompt asks whether to send the campaign to its audience, and names the campaign and the send time in your local time zone. A declined prompt sends nothing.
A campaign with issues is refused with exit code 4, and each issue is listed. With --output json, the issues are in the issues array of the API’s error body.
The text_unchecked issue means the API could not check the subject, the preview text and the design right now, and it clears on its own. On CLI v0.4.0 or later, outside JSON output, a refusal that holds it ends with a line that says to run the command again:
--idempotency-key, a refusal included, and gives it again to a run with the same key for 24 hours; see Idempotency. The line therefore asks for a new key when the send had --idempotency-key; without the flag, it ends at run the command again. On a refused campaigns test, the line does not ask for a new key.
While a segment of the campaign, included or excluded, is building or failed, the API refuses the send with HTTP 400, and the command exits with code 4. A building segment becomes ready by itself. A failed one is built again by any ahasend segments update; see segment states. Once ahasend segments get shows the segment ready, run the send again, with a new --idempotency-key if the refused send had one.
To stop a validating or scheduled campaign, return it to draft with campaigns unschedule. It does not ask for confirmation. A campaign that has queued mail cannot be unscheduled. To change the send time of a scheduled campaign, unschedule it and send it again.
Read Results
campaigns stats shows a campaign’s live counters, its rates and its stored report. The report is recounted from time to time, so check again later for new numbers.
campaigns recipients needs exactly one of --status and --bounce-classification. --status takes a status that campaigns stats counts, in any case, and --bounce-classification takes a bounce classification that campaigns stats counts, other than Unknown. campaigns list --status draft lists the campaigns in one status.
On CLI v0.4.0 or later, each recipient shows the list or the segment the campaign reached it through: a recipient reached through a list has its list and no segment, and one reached through a segment has its segment and no list. Table output has a Segment column after List, plain output shows the segment’s ID and name, and CSV output has the columns segment_id and segment_name after list_name.
AhaML Designs
Campaigns and campaign templates read and write the design of the Simple Editor as AhaML, as transactional templates do.campaigns get --markup writes only the design’s AhaML to stdout, and campaigns update --markup-file writes it back. These flags need CLI v0.4.0 or later.
campaigns templates get --markup and campaigns templates update --markup-file do the same for a campaign template. campaigns create and campaigns templates create also take --markup-file, which makes the editor simple. On campaigns update, --markup-file replaces a simple design, and a campaign with no design yet takes it and becomes simple. The templates commands describe what --markup writes, when it fails, and the Markup, Markup Error and Markup Warnings rows.
Campaign Templates
Campaign templates are designs that a campaign can copy withcampaigns create --campaign-template-id. A campaign template has no draft, subject or sender: changes apply at once, and campaigns already made from it keep their own copies. A campaign can be made from a template only once the template has HTML.
Continue the script. These commands make a campaign template from campaign.html, start a draft campaign from it, and delete both.
--campaign-template-id cannot be combined with --editor, --markup-file, --mjml-file, --html-file or --text-file.
Delete the Test Campaign
Finish the script by deleting the draft campaign, then the test list. The API refuses to delete a list while a campaign that still needs it refers to it.ahasend campaigns list --status draft, ahasend campaigns templates list and ahasend lists list --name "Docs test", and delete each with campaigns delete, campaigns templates delete or lists delete. Delete the campaigns before the list.
The API also refuses to delete a campaign or a list while a segment refers to it, and names those segments; see delete a segment.
campaigns delete and campaigns templates delete ask for confirmation first; see prompts. To copy a campaign in any status into a new draft, use campaigns duplicate. The copy gets the campaign’s design, subject, preview text, sender, reply-to, and the lists and segments of its audience that still exist; a segment that is building can make the copy fail, as Choose the Audience describes. Without --name, the copy is named “Copy of” and the campaign’s name.
Command Flags
These flags come from the CLI’s--help. All commands also accept the global flags.

