Integrations

CLI

Install the Ternwire command-line client and call every public API operation from a terminal or CI job.

On this page

The Ternwire CLI calls every public API operation from a terminal, a script, or a CI job. It requires Node.js 20.11 or later.

Install

npm install --global @ternwire/cli
ternwire --help

Set TERNWIRE_API_KEY in your shell. Credentials are read from the environment, never from a CLI flag or a persisted config file.

The CLI calls https://ternwire.com by default. To target a local or staging API, set TERNWIRE_API_ORIGIN or pass --base-url, for example --base-url http://localhost:3001. The origin must not contain /v1 and must use HTTPS unless it is localhost or a loopback address. --timeout-ms overrides the 30000 ms timeout.

Commands

ternwire emails send --data email.json --idempotency-key order-123-receipt
ternwire emails get msg_12345678
ternwire templates list --limit 50
ternwire templates create --data template.json
ternwire templates get template_12345678
ternwire templates replace template_12345678 --data template.json
ternwire templates delete template_12345678
ternwire attachments create --data attachment.json
ternwire attachments get att_12345678
ternwire attachments complete att_12345678
ternwire domains create --data domain.json
ternwire domains get domain_12345678
ternwire domains delete domain_12345678
ternwire webhooks create --data webhook.json
ternwire webhooks rotate endpoint_12345678
ternwire attempts get whattempt_12345678
ternwire attempts replay whattempt_12345678
ternwire tracking-settings get
ternwire tracking-settings update --data '{"openTracking": true}'

tracking-settings turns open and click tracking on or off for email you send from your app. Newsletters use marketing-settings instead.

Run ternwire --help for every command with its IDs, payload, and options.

Commands perform the named API operation immediately. Use --data - to read a JSON object from stdin. The CLI rejects extra arguments, unsupported options, missing IDs, missing payloads, and missing idempotency keys.

List commands print one page. --limit sets the page size (1-100, default 25) and --cursor takes the nextCursor of the previous output, which templates list returns inside page.

Newsletter commands

Audiences, subscriptions, contacts, contact imports, broadcasts, marketing settings, automations and contact events each have a command for every newsletter operation. They need a key with the newsletter scopes.

ternwire audiences create --data audience.json --idempotency-key newsletter-audience
ternwire audiences export audience_12345678 > contacts.csv
ternwire subscriptions request audience_12345678 --data signup.json --idempotency-key signup-ada
ternwire subscriptions unsubscribe audience_12345678 contact_12345678
ternwire contacts list --audienceId audience_12345678 --state confirmed
ternwire imports sources
ternwire imports upload audience_12345678 --file mailchimp-export.zip --idempotency-key mailchimp-move
ternwire imports upload audience_12345678 --file bounces.csv --status bounced --idempotency-key sendgrid-bounces
ternwire imports create --data import.json --idempotency-key import-2026-11
ternwire import-batches apply 0a1b2c3d4e5f60718293a4b5c6d7e8f9
ternwire import-batches get 0a1b2c3d4e5f60718293a4b5c6d7e8f9
ternwire broadcasts create --data broadcast.json --idempotency-key november-news
ternwire broadcasts preview broadcast_12345678
ternwire broadcasts test broadcast_12345678 --data test.json --idempotency-key november-news-test-1
ternwire broadcasts send broadcast_12345678 --idempotency-key november-news-send
ternwire broadcasts pause broadcast_12345678
ternwire broadcasts recipients broadcast_12345678 --limit 100
ternwire broadcasts engagement broadcast_12345678
ternwire broadcasts ab-test broadcast_12345678
ternwire broadcasts ab-test-winner broadcast_12345678 --data '{"variant":"Bold"}'
ternwire marketing-settings get
ternwire marketing-settings update --data tracking.json
ternwire automations create --data onboarding.json --idempotency-key onboarding-v1
ternwire automations test automation_12345678 --data '{"to":["me@example.com"],"step":0}' --idempotency-key onboarding-test-1
ternwire automations activate automation_12345678
ternwire automations stats automation_12345678
ternwire automations enrollments automation_12345678 --state exited
ternwire events create --data '{"email":"ada@example.com","name":"trial_started"}' --idempotency-key signup-4821

subscriptions unsubscribe takes the audience ID and then the contact ID. broadcasts send and broadcasts preview accept an optional --data. Without it, send starts at once and preview renders for a default contact. Pass {"scheduledAt": "2026-11-20T09:00:00+01:00"} to schedule a send. Pass {"locale": "sk"} to broadcasts preview or add "locale" to the broadcasts test data to see the localized template a contact with that locale gets. Reuse the same --idempotency-key when you retry a command whose outcome is unknown.

imports upload reads a CSV, TSV or ZIP export, up to your plan's contact limit, and prints {"batches": [...]}, with one batch per CSV. A large list goes up as several parts and reads as one batch, so run import-batches apply once for each batch and import-batches get until state is applied. Run a stopped upload again with the same --idempotency-key and it continues where it stopped. It recognizes the platform from the columns, or takes --source. --status says what a file with no status column holds, such as a suppression export. --consent defaults to pending, and --consent confirmed needs --policy-version. Nothing changes until you apply, so check errors, summary.statuses and summary.columns first. imports sources prints how to export from each platform.

marketing-settings update takes {"openTracking": true, "clickTracking": true} or either field alone. broadcasts engagement prints unique and total opens and clicks and the clicks per link. Read open and click tracking before you turn tracking on. It also says which broadcasts and automation emails a change reaches.

broadcasts ab-test prints the results of an A/B test. broadcasts ab-test-winner sends the named variant to the rest of the audience. Without --data it applies the winner metric to the results so far.

automations activate starts enrolling contacts into an automation, and automations pause holds its enrollments where they are. automations archive ends every active enrollment and cannot be undone. events create needs an --idempotency-key. Use one key per real occurrence, such as the ID of the signup that caused the event, so a retried command enrolls nobody twice.

subscriptions request always sends a confirmation email, and the contact stays pending until they click it. Preview and send a test copy before broadcasts send, because a send cannot be undone once copies reach the provider. audiences export prints CSV instead of JSON.

Confirmation

The delete commands, broadcasts send and broadcasts cancel ask before they run. Type yes to go ahead. Pass --yes to skip the question, for example in a script. Without a terminal to ask in, such as in CI or with input piped in, these commands stop with exit code 2 unless --yes is given.

Retries

Reads, deletes, replacements and commands that take --idempotency-key are retried up to twice after a 429, 502, 503 or 504, a timeout, or a connection error. The CLI waits as long as Retry-After asks. Other commands run once, so nothing is created twice. --timeout-ms limits each attempt.

Output and exit codes

Successful responses are JSON on stdout, and errors are JSON on stderr. Template deletion prints null. Error output includes the HTTP status, API error code, response body, and headers when available. When the API could not be reached, the error names the cause, such as ENOTFOUND or ECONNREFUSED, and a hint about what to check.

Exit codeMeaning
0Success
1Request or transport failure
2Incorrect usage

Webhook creation and rotation print the one-time signing secret. Store that output somewhere safe.

The CLI creates and completes attachment upload slots but does not upload file bytes, poll, or listen for webhooks. Use an SDK to verify inbound webhooks.