Skip to the documentation
CLI

nextmail audiences

Every command in this namespace, with its arguments, flags and examples.

Commands

Named lists of contacts. Every contact is in the default audience, and you make the rest.

Every command here also takes the global flags, such as --json, --profile and --dry-run. See the global flags

nextmail audiences list

List one page of the workspace audiences

Scopesaudiences:readNeeds a sign-inAliasesls

Usage

nextmail audiences list [flags]

Returns one page of the audiences in the workspace, with the default audience first and the rest newest first. Paging is keyset: --limit takes 1 to 100 and defaults to 25, and nextCursor goes back as --cursor while hasMore is true, so every audience is reachable.

builtin tells the default audience apart from the ones you made. It is default on exactly one row per workspace, the audience that holds every contact, and null on everything else. Branch on builtin rather than on the name, which anybody can change.

contactCount is counted at the moment of the read, so two reads either side of a contacts.create disagree by one.

Add --all to walk every page: a table on a terminal, one JSON object per line when piped or with --ndjson, and one { items, hasMore, nextCursor } document with --json. --max <n> stops after that many items.

Flags

--limit <n>

Rows per page, a whole number from 1 to 100. The server defaults to 25.

Default25
--cursor <value>

The nextCursor from the previous page, an audience id. One that names no audience in the workspace is a 400 invalid_cursor.

--all

Fetch every page and stream the items as they arrive.

--max <n>

Stop after this many items. Implies --all.

--ndjson

Print every item as one JSON object per line. Implies --all

Examples

nextmail audiences list
Walk every page and stop after 100 items
nextmail audiences list --all --max 100
One JSON object per line when piped
nextmail audiences list --all > audiences.ndjson

Also available in

API
GET /audiences
TypeScript
nextmail.audiences.list()
Python
audiences.list()
Ruby
audiences.list
PHP
audiences->list
Go
Audiences.List
Java
audiences().list
C#
Audiences.ListAsync

nextmail audiences growth

Read how audiences grew over a time window

Scopesaudiences:readNeeds a sign-in

Usage

nextmail audiences growth [flags]

Returns the numbers behind the growth chart on the Audiences page in one request. For each audience it reports total, the contacts in it now, before, how many of those joined before the window, added, how many joined inside it, subscribed, how many of them are still subscribed, unsubscribed, how many unsubscribed inside the window through a broadcast link, and buckets, when they joined and unsubscribed, cut to grain. totals sums the audiences read.

An audience records the date each contact joined it and never the date one left. A series therefore counts the contacts still in the list today by the date they joined, and it never falls: a contact who joined inside the window and was removed since is not in it at all. Read it as the growth of the list as it stands, not as a history of every change.

totals.contacts counts each person once, however many of the audiences they are in. totals.memberships adds the lists up, and the default audience holds every contact, so a person in two other audiences counts three times there. totals.subscribed counts each person still subscribed to at least one of the audiences read, which is who a broadcast to them would reach, and totals.unsubscribed adds up the unsubscribes inside the window. totals.busiest is the bucket with the most joins, or null.

buckets is sparse and oldest first: a bucket in which nobody joined or unsubscribed has no entry, so a chart must fill the gaps. grain sets the bucket width and the key shape, YYYY-MM-DD, YYYY-MM-DDTHH or YYYY-MM-DDTHH:MM, and --offset-minutes shifts the boundaries so days break where the reader's day does. The window starts at the beginning of its oldest bucket, reported as since, and ends now, reported as until.

Flags

--audience-ids <a,b>Repeatable

Up to 50 audience ids to read, sent comma separated. Leave it out, or pass an empty array, to read every audience in the workspace, the default one included. An id that is not an audience of this workspace is a 404 audience_not_found on --audience-ids, and more than 50 is a 422.

--days <n>

Window length in days, from 1 to 1095, defaulting to 30.

Default30
--minutes <n>

Window length in minutes, from 1 to 1576800. Takes precedence over days, and only useful below a day with a finer grain.

--grain <value>

Bucket width: minute, hour or day, defaulting to day.

Default"day"
--offset-minutes <n>

Minutes east of UTC to cut the buckets in, from -840 to 840, defaulting to 0. Pass -new Date().getTimezoneOffset() for the local zone.

Default0

Examples

nextmail audiences growth
With optional flags
nextmail audiences growth --days 90 --grain day
Print the raw JSON
nextmail audiences growth --json

Also available in

API
GET /audiences/growth
TypeScript
nextmail.audiences.growth()
Python
audiences.growth()
Ruby
audiences.growth
PHP
audiences->growth
Go
Audiences.Growth
Java
audiences().growth
C#
Audiences.GrowthAsync

nextmail audiences get

Read one audience by id

Scopesaudiences:readNeeds a sign-inAliasesshowview

Usage

nextmail audiences get <id> [flags]

Returns a single audience in the same shape as list, with a fresh contactCount. This is the cheap way to watch a count move without pulling the contacts behind it.

The id is the one from list or create, such as aud_9f2c4b7e1a0d63d84c5f2e7b. An id from another workspace is a 404 rather than a 403, since the API never tells you that something exists somewhere you cannot see.

Arguments

<id>Required

Audience id such as aud_9f2c4b7e1a0d63d84c5f2e7b.

Examples

nextmail audiences get aud_9f2c4b7e1a0d63d84c5f2e7b
Print the raw JSON
nextmail audiences get aud_9f2c4b7e1a0d63d84c5f2e7b --json

Also available in

API
GET /audiences/{id}
TypeScript
nextmail.audiences.get()
Python
audiences.get()
Ruby
audiences.get
PHP
audiences->get
Go
Audiences.Get
Java
audiences().get
C#
Audiences.GetAsync

nextmail audiences create

Create an audience

Scopesaudiences:writeNeeds a sign-inAliasesnewadd

Usage

nextmail audiences create --name <value> [flags]
nextmail audiences create --data <json|@file|-> [flags]

Makes a new, empty audience in the workspace and returns it with its id. name is trimmed and must then be 1 to 120 characters. description is optional free text for whoever reads the list later.

The audience comes back with builtin null and contactCount zero. Only the default audience carries a builtin, and it cannot be made or copied here.

Names are not checked for duplicates, so two calls with the same name make two audiences. Fill it with audiences.addContact, one contact at a time, and the contacts must already be in the book.

Flags

--name <value>

Display name, trimmed, 1 to 120 characters. Not unique. Required, here or in --data.

--description <value>

What the audience is for. Leave it out to create the audience without one.

--show-on-preferences

True lists the audience by name on the email preferences page the unsubscribe link opens, where its members can leave or rejoin it. Left out or false, it stays private.

Defaultfalse
--data <json|@file|->

The whole body as JSON, inline, from a file with @path, or - for standard input. Flags override its keys.

Examples

The required values only
nextmail audiences create --name 'Product updates'
With optional flags
nextmail audiences create --name 'Product updates' --description 'Customers who asked to hear about releases'
Read the whole body from a JSON file
nextmail audiences create --data @audience.json

Also available in

API
POST /audiences
TypeScript
nextmail.audiences.create()
Python
audiences.create()
Ruby
audiences.create
PHP
audiences->create
Go
Audiences.Create
Java
audiences().create
C#
Audiences.CreateAsync

nextmail audiences update

Rename an audience or change its description

Scopesaudiences:writeNeeds a sign-inAliasesedit

Usage

nextmail audiences update <id> [flags]

Changes the fields you send and leaves the rest alone. A key you leave out keeps its stored value and an explicit null clears it, so { description: null } empties the description while {} changes nothing.

The default audience can be renamed like any other, and renaming it does not change builtin or what it holds. builtin itself cannot be set, moved or cleared from here.

The id never changes, and membership is untouched.

Arguments

<id>Required

Audience id such as aud_9f2c4b7e1a0d63d84c5f2e7b.

Flags

--name <value>

New display name, trimmed, 1 to 120 characters.

--description <value>

New description. Null clears it.

--show-on-preferences

True lists the audience by name on the email preferences page the unsubscribe link opens, where its members can leave or rejoin it. False keeps it private.

--data <json|@file|->

The whole patch as JSON, inline, from a file with @path, or - for standard input. Flags override its keys.

Examples

With optional flags
nextmail audiences update aud_9f2c4b7e1a0d63d84c5f2e7b --name 'Release notes'
Print the raw JSON
nextmail audiences update aud_9f2c4b7e1a0d63d84c5f2e7b --name 'Release notes' --json

Also available in

API
PATCH /audiences/{id}
TypeScript
nextmail.audiences.update()
Python
audiences.update()
Ruby
audiences.update
PHP
audiences->update
Go
Audiences.Update
Java
audiences().update
C#
Audiences.UpdateAsync

nextmail audiences delete

Delete an audience and keep its contacts

Scopesaudiences:writeNeeds a sign-in
Asks you to confirm
Aliasesrmdelremove

Usage

nextmail audiences delete <id> [flags]

Deletes the audience and drops every membership it held, in one transaction. The contacts themselves are not touched: they stay in the address book, in the default audience, and in any other audience they were in.

The default audience cannot be deleted. The call is refused with 409 audience_immutable on id, because it is what makes the book readable as a list. Delete the contacts instead if you mean to empty it.

There is no undo, and a new audience with the same name comes back empty.

Arguments

<id>Required

Audience id such as aud_9f2c4b7e1a0d63d84c5f2e7b. Not the default audience.

Examples

nextmail audiences delete aud_9f2c4b7e1a0d63d84c5f2e7b
Skip the confirmation, for scripts
nextmail audiences delete aud_9f2c4b7e1a0d63d84c5f2e7b --yes

Also available in

API
DELETE /audiences/{id}
TypeScript
nextmail.audiences.delete()
Python
audiences.delete()
Ruby
audiences.delete
PHP
audiences->delete
Go
Audiences.Delete
Java
audiences().delete
C#
Audiences.DeleteAsync

nextmail audiences empty

Take every contact out of an audience and keep the audience

Scopesaudiences:writeNeeds a sign-in
Asks you to confirm

Usage

nextmail audiences empty <id> [flags]

Removes every membership of the audience in one transaction and resolves with the audience as it now stands, contactCount 0, plus removed, the number of contacts taken out. The audience keeps its id, name and description, so anything that points at it still works. The contacts are not touched: each one stays in the address book, in the default audience and in every other audience it is in.

The default audience cannot be emptied. The call is refused with 409 audience_immutable on id, because that audience holds every contact for as long as it is a contact.

There is no undo. The app asks the person to confirm before it empties a list, but this call asks nothing: it needs no verification code, whether it is made with an API key or with the OAuth access token of an app the person connected. Check the id before you call it.

Arguments

<id>Required

Audience id such as aud_9f2c4b7e1a0d63d84c5f2e7b. Not the default audience.

Examples

nextmail audiences empty aud_9f2c4b7e1a0d63d84c5f2e7b
Skip the confirmation, for scripts
nextmail audiences empty aud_9f2c4b7e1a0d63d84c5f2e7b --yes

Also available in

API
POST /audiences/{id}/empty
TypeScript
nextmail.audiences.empty()
Python
audiences.empty()
Ruby
audiences.empty
PHP
audiences->empty
Go
Audiences.Empty
Java
audiences().empty
C#
Audiences.EmptyAsync

nextmail audiences list-contacts

List one page of the contacts in one audience

Scopesaudiences:readNeeds a sign-in

Usage

nextmail audiences list-contacts <id> [flags]

Returns one page of the contacts in the audience. The rows are the contacts themselves, not membership records, so they carry email, name, source, notes, lastSeenAt, createdAt and updatedAt, plus addedAt, the date the contact joined this audience, and unsubscribedAt, when it unsubscribed from a broadcast sent to this audience, or null while it is subscribed. An unsubscribed contact stays in the audience and broadcasts to it skip it.

By default the order is the one contacts.list uses: the contacts most recently written to first, and those never written to last. sort picks another order, q searches names and addresses, source keeps only contacts saved by hand or only those recorded from the composer, and statuses keeps only the subscribed or only the unsubscribed. These are the controls on the audience page in the app.

Paging is keyset: --limit takes 1 to 200 and defaults to 50, and nextCursor goes back as --cursor while hasMore is true, so every contact in the audience is reachable however large it grows. Send the same q, source, sort and statuses with every page.

Reading the default audience here returns the whole address book.

Add --all to walk every page: a table on a terminal, one JSON object per line when piped or with --ndjson, and one { items, hasMore, nextCursor } document with --json. --max <n> stops after that many items.

Arguments

<id>Required

Audience id such as aud_9f2c4b7e1a0d63d84c5f2e7b.

Flags

--limit <n>

Rows per page, a whole number from 1 to 200. The server defaults to 50.

Default50
--cursor <value>

The nextCursor from the previous page. Never build one yourself; one that names no contact in this audience is a 400 invalid_cursor.

--q <value>

Narrows to contacts whose name or address matches, up to 200 characters. When nothing matches exactly the search allows for a typo instead.

--source <value>

Narrows to contacts recorded that way: manual for one somebody saved, auto for one recorded by a send from the app composer, form for one a sign-up form added.

--sort <value>

How the page is ordered. last-heard-newest, the default, puts the contacts most recently written to first and those never written to last, last-heard-oldest reverses it, added-newest and added-oldest order by addedAt, and name is alphabetical without case, with a contact that has no name sorting by its address.

Default"last-heard-newest"
--statuses <a,b>Repeatable

Keeps only subscribed members, only unsubscribed ones, or both. Leave it out, or name both, for everyone in the audience. AUDIENCE_MEMBER_STATUSES holds the values.

--all

Fetch every page and stream the items as they arrive.

--max <n>

Stop after this many items. Implies --all.

--ndjson

Print every item as one JSON object per line. Implies --all

Examples

The required values only
nextmail audiences list-contacts aud_9f2c4b7e1a0d63d84c5f2e7b
With optional flags
nextmail audiences list-contacts aud_9f2c4b7e1a0d63d84c5f2e7b --limit 200 --sort added-newest
Walk every page and stop after 100 items
nextmail audiences list-contacts aud_9f2c4b7e1a0d63d84c5f2e7b --all --max 100
One JSON object per line when piped
nextmail audiences list-contacts aud_9f2c4b7e1a0d63d84c5f2e7b --all > audiences.ndjson

Also available in

API
GET /audiences/{id}/contacts
TypeScript
nextmail.audiences.listContacts()
Python
audiences.list_contacts()
Ruby
audiences.list_contacts
PHP
audiences->listContacts
Go
Audiences.ListContacts
Java
audiences().listContacts
C#
Audiences.ListContactsAsync

nextmail audiences add-contact

Put a contact in an audience

Scopesaudiences:writeNeeds a sign-in

Usage

nextmail audiences add-contact <id> --email <value> [flags]
nextmail audiences add-contact <id> --data <json|@file|-> [flags]

Adds one contact to one audience and returns the membership, with the contact it points at. The address is trimmed and lower cased before the lookup, and it has to be a contact in this workspace already: an address that is not in the book is refused with 422 contact_not_found on email. Save it with contacts.create first.

There is one membership per audience and contact, so adding somebody who is already in the audience returns the membership that is there, with its original addedAt, rather than adding a second one or failing. That makes the call safe to replay, and the SDK retries it after a network failure.

Adding to the default audience is accepted and changes nothing, since every contact is already in it.

Arguments

<id>Required

Audience id such as aud_9f2c4b7e1a0d63d84c5f2e7b.

Flags

--email <value>

The address of a contact already in the workspace book, matched case insensitively. Required, here or in --data.

--data <json|@file|->

The whole body as JSON, inline, from a file with @path, or - for standard input. Flags override its keys.

Examples

nextmail audiences add-contact aud_9f2c4b7e1a0d63d84c5f2e7b --email grace@example.com
Read the whole body from a JSON file
nextmail audiences add-contact aud_9f2c4b7e1a0d63d84c5f2e7b --data @audience.json

Also available in

API
POST /audiences/{id}/contacts
TypeScript
nextmail.audiences.addContact()
Python
audiences.add_contact()
Ruby
audiences.add_contact
PHP
audiences->addContact
Go
Audiences.AddContact
Java
audiences().addContact
C#
Audiences.AddContactAsync

nextmail audiences remove-contact

Take a contact out of an audience

Scopesaudiences:writeNeeds a sign-in
Asks you to confirm

Usage

nextmail audiences remove-contact <id> <email> [flags]

Drops one membership and leaves everything else alone. The contact stays in the address book, in the default audience and in every other audience it was in. The address is trimmed and lower cased, and the SDK URL encodes it for the path.

A contact that is not in this audience is a 404, so a typo cannot report a removal that never happened.

The default audience cannot be thinned. Removing a contact from it is refused with 409 audience_immutable, because it holds every contact by definition. Use contacts.delete when you mean the contact to go.

Arguments

<id>Required

Audience id such as aud_9f2c4b7e1a0d63d84c5f2e7b. Not the default audience.

<email>Required

The contact's address, matched case insensitively.

Examples

nextmail audiences remove-contact aud_9f2c4b7e1a0d63d84c5f2e7b grace@example.com
Skip the confirmation, for scripts
nextmail audiences remove-contact aud_9f2c4b7e1a0d63d84c5f2e7b grace@example.com --yes

Also available in

API
DELETE /audiences/{id}/contacts/{email}
TypeScript
nextmail.audiences.removeContact()
Python
audiences.remove_contact()
Ruby
audiences.remove_contact
PHP
audiences->removeContact
Go
Audiences.RemoveContact
Java
audiences().removeContact
C#
Audiences.RemoveContactAsync

nextmail audiences add-contacts

Put up to 200 existing contacts in an audience in one call

Scopesaudiences:writeNeeds a sign-in

Usage

nextmail audiences add-contacts <id> --emails <a,b> [flags]
nextmail audiences add-contacts <id> --data <json|@file|-> [flags]

Adds many contacts to one audience in one transaction and reports what happened to each address. Each address is trimmed and lower cased, a repeat counts once, and each has to be a contact in this workspace already.

Nothing is refused for one address. An address that is not a contact is returned in missing and the others are still added, and a contact that is in the audience already is counted in unchanged and keeps its original addedAt. added counts the contacts that joined in this call.

This never creates a contact. To save new addresses and put them in the audience in the same call, use importContacts. Adding to the default audience succeeds with added: 0, since every contact is already in it.

Arguments

<id>Required

Audience id such as aud_9f2c4b7e1a0d63d84c5f2e7b.

Flags

--emails <a,b>Repeatable

From 1 to 200 addresses of contacts already in the workspace book, matched case insensitively. An empty array or more than 200 is a 422 invalid_parameter on emails, and an empty or overlong address is the same error on that entry, such as emails.2. Required, here or in --data.

--data <json|@file|->

The whole body as JSON, inline, from a file with @path, or - for standard input. Flags override its keys.

Examples

nextmail audiences add-contacts aud_9f2c4b7e1a0d63d84c5f2e7b --emails grace@example.com,ada@example.com,nobody@example.com
Read the whole body from a JSON file
nextmail audiences add-contacts aud_9f2c4b7e1a0d63d84c5f2e7b --data @audience.json

Also available in

API
POST /audiences/{id}/contacts/batch
TypeScript
nextmail.audiences.addContacts()
Python
audiences.add_contacts()
Ruby
audiences.add_contacts
PHP
audiences->addContacts
Go
Audiences.AddContacts
Java
audiences().addContacts
C#
Audiences.AddContactsAsync

nextmail audiences remove-contacts

Take up to 200 contacts out of an audience in one call

Scopesaudiences:writeNeeds a sign-in
Asks you to confirm

Usage

nextmail audiences remove-contacts <id> --emails <a,b> [flags]
nextmail audiences remove-contacts <id> --data <json|@file|-> [flags]

Removes many contacts from one audience in one transaction and reports what happened to each address. Each address is trimmed and lower cased and a repeat counts once. The contacts stay in the address book, in the default audience and in every other audience they are in.

Nothing is refused for one address, which is where this differs from removeContact. A contact that is not in this audience is returned in notInAudience, an address that is not a contact at all in missing, and the rest are still removed. removed counts the contacts taken out in this call.

The default audience cannot be thinned. The call is refused with 409 audience_immutable on id, because that audience holds every contact by definition. Use contacts.delete when you mean a contact to go.

Arguments

<id>Required

Audience id such as aud_9f2c4b7e1a0d63d84c5f2e7b. Not the default audience.

Flags

--emails <a,b>Repeatable

From 1 to 200 addresses, matched case insensitively. An empty array or more than 200 is a 422 invalid_parameter on emails, and an empty or overlong address is the same error on that entry, such as emails.2. Required, here or in --data.

--data <json|@file|->

The whole body as JSON, inline, from a file with @path, or - for standard input. Flags override its keys.

Examples

nextmail audiences remove-contacts aud_9f2c4b7e1a0d63d84c5f2e7b --emails grace@example.com,ada@example.com
Read the whole body from a JSON file
nextmail audiences remove-contacts aud_9f2c4b7e1a0d63d84c5f2e7b --data @audience.json
Skip the confirmation, for scripts
nextmail audiences remove-contacts aud_9f2c4b7e1a0d63d84c5f2e7b --emails grace@example.com,ada@example.com --yes

Also available in

API
POST /audiences/{id}/contacts/batch-remove
TypeScript
nextmail.audiences.removeContacts()
Python
audiences.remove_contacts()
Ruby
audiences.remove_contacts
PHP
audiences->removeContacts
Go
Audiences.RemoveContacts
Java
audiences().removeContacts
C#
Audiences.RemoveContactsAsync

nextmail audiences import-contacts

Import up to 500 addresses into an audience, creating contacts as needed

Scopesaudiences:writecontacts:writeNeeds a sign-in

Usage

nextmail audiences import-contacts <id> --contacts <json|@file|-> [flags]
nextmail audiences import-contacts <id> --data <json|@file|-> [flags]

Does what the CSV import on an audience page does, without the file. Each row is an address, an optional name and optional custom fields, and the whole call runs in one transaction.

An address that is not a contact yet is saved as one, with source set to manual, and joins the default audience as every new contact does. An address that is a contact already is reused as it stands: its name is kept, and a name sent here only fills one that is empty. Every imported contact ends up in this audience. Importing an address whose contact was deleted brings it back.

A row whose address is not well formed is skipped rather than failing the call. It is counted in skipped and its address is returned in invalid exactly as you sent it, and every other row is still imported. Rows with the same address count once.

Arguments

<id>Required

Audience id such as aud_9f2c4b7e1a0d63d84c5f2e7b. The default audience is accepted and saves the contacts without putting them in any other list.

Flags

--contacts <json|@file|->

From 1 to 500 rows, each { email, name, attributes }. email is required, at most 320 characters, and trimmed and lower cased. name is optional, at most 200 characters, and used for a new contact or for an existing one whose name is empty. attributes is optional and holds custom fields, keys that start with a letter and hold up to 64 letters, digits and underscores, with values of at most 500 characters. A value replaces the field of that name, an empty one is ignored, and the fields a row leaves out keep their values. An empty array, more than 500 rows, an empty email or any other key in a row is a 422. JSON shaped as Array<AudienceImportRow>, inline or from a file with @path. Required, here or in --data.

--data <json|@file|->

The whole body as JSON, inline, from a file with @path, or - for standard input. Flags override its keys.

Examples

nextmail audiences import-contacts aud_9f2c4b7e1a0d63d84c5f2e7b --contacts @contacts.json
Read the whole body from a JSON file
nextmail audiences import-contacts aud_9f2c4b7e1a0d63d84c5f2e7b --data @audience.json

Also available in

API
POST /audiences/{id}/import
TypeScript
nextmail.audiences.importContacts()
Python
audiences.import_contacts()
Ruby
audiences.import_contacts
PHP
audiences->importContacts
Go
Audiences.ImportContacts
Java
audiences().importContacts
C#
Audiences.ImportContactsAsync