Skip to the documentation
PHP

$client->broadcasts

Every method in this namespace: its signature, its parameters, what it returns and an example.

Methods

One message sent to everybody in one or more audiences, a personalised copy for each person, with unsubscribe handled for you.

broadcasts->preview

Count who a broadcast to some audiences would reach

Scopesaudiences:read
Signature
preview(array $body, ?string $apiKey = null): array

Returns the numbers send would work from, without sending or writing anything: recipients, the people a broadcast to these audiences would reach now, unsubscribed, the contacts skipped because they have unsubscribed, and suppressed, the subscribed contacts skipped because their address is on the suppression list. A contact in several of the audiences counts once.

The count is taken at the moment of the call, so contacts who join or leave before a send change it. Only audienceIds, excludeAudienceIds and segmentId are sent, so you can pass the same array you are about to give send.

Parameters

audienceIdsstring[]Required

1 to 10 audience ids. One that names no audience in the workspace is a 404 audience_not_found, and All contacts, which no broadcast can go to, is a 422 audience_is_everyone.

excludeAudienceIdsstring[]

Up to 10 audiences whose members are left out of the count, as send leaves them out.

segmentIdstring

A saved segment that narrows the count to the contacts that match it, as send narrows the broadcast.

apiKeystring

Overrides the client's API key for this call only.

Returns

An array with audienceIds as sent, recipients, unsubscribed and suppressed.

Example

$draft = [    'audienceIds' => ['aud_4c1b8e2a7d9f05c36b4e8a71', 'aud_7e3d9a1c5b2f84e06d9a3c51'],    'from' => 'Acme <news@acme.com>',    'subject' => 'The September release',    'text' => 'Hi {{firstName|there}}, here is what changed this month.',]; $reach = $client->broadcasts->preview($draft); echo $reach['recipients'], ' will get it, ', $reach['unsubscribed'], ' unsubscribed, ', $reach['suppressed'], ' suppressed', PHP_EOL; if ($reach['recipients'] > 0) {    $client->broadcasts->send($draft);}

Notes

  • Needs only audiences:read, so a key that cannot send can still show somebody the count.

  • The SDK retries it after a network failure or a retryable status, since it changes nothing.

Also available in

API
POST /broadcasts/preview
TypeScript
nextmail.broadcasts.preview()
Python
broadcasts.preview()
Ruby
broadcasts.preview
Go
Broadcasts.Preview
Java
broadcasts().preview
C#
Broadcasts.PreviewAsync
CLI
nextmail broadcasts preview

broadcasts->send

Send one message to everybody in one or more audiences

Scopesemails:sendaudiences:read
Signature
send(array $body, ?string $idempotencyKey = null, ?string $apiKey = null): array

Creates a broadcast: one message sent to every contact in the audiences you name, as a separate copy for each person. Every copy has exactly one recipient and no cc or bcc, so nobody sees who else it went to, and every copy is an ordinary email with its own msg_ id, events, tracking and webhooks. emails->list with broadcastId: lists them. Copies are not filed in the Sent folder, because the broadcast is the record.

The call returns straight away with the broadcast queued, or scheduled when you pass scheduledAt, and the sending happens in the background, 50 people at a time. Poll get to follow status and counts as it goes.

Who gets it: every contact in at least one of audienceIds, counted once however many of them hold it, except a person who has unsubscribed and an address on the suppression list. audienceIds cannot name All contacts, the built-in audience of everyone the workspace has written to, because most of them never asked for its mail: that is a 422 audience_is_everyone. A contact added to one of the audiences after this call but before the sending reaches it is included. counts.recipients is the estimate taken at the call, and preview returns the same count without sending.

subject, html and text take merge fields, filled in from each contact: firstName, lastName, name, email and unsubscribeUrl, each written between double braces. Each takes a fallback after a bar, so {{firstName|there}} reads there for a contact with no name. The first name is the first word of the contact's name and the last name is the rest. A custom field of the contact is written {{attributes.plan}} for the key plan, takes a fallback the same way, and reads as nothing when the contact has no such field and no fallback is given. Values are escaped in html, and any other {{…}} is left as written. With template, those five values are passed as props, but only the ones the template declares, except unsubscribeUrl, which every template receives.

Every copy carries the one-click unsubscribe headers mail clients and the large mailbox providers look for. A body or a template that does not place the unsubscribeUrl merge field itself gets a short footer with the link, in English, which also names the sender and shows the postal address once marketingPostalAddress is set through settings->update. Following the link unsubscribes the person from all of the workspace's marketing mail: every audience they are in shows unsubscribedAt, suppressions->listUnsubscribes lists them, and later broadcasts and automation emails skip them, even after they are added to an audience again. Their contact and mail sent to them one message at a time are not affected.

The whole send is checked against the plan's monthly sends before anything is written. A broadcast the allowance cannot cover throws 429 send_quota_exceeded and leaves nothing behind, and each copy counts as one send.

Parameters

audienceIdsstring[]Required

1 to 10 audience ids such as aud_9f2c4b7e1a0d63d84c5f2e7b. A contact in several of them gets one copy. An id that names no audience in the workspace is a 404 audience_not_found and All contacts is a 422 audience_is_everyone, and either way nothing is sent.

fromstring|arrayRequired

Sender as news@acme.com, Acme <news@acme.com> or an array with email and name. It must be an address the key may send as, otherwise 403 from_address_forbidden.

replyTostring|array

Where replies go, the same for every copy.

subjectstring

Required unless a template supplies it, at most 998 characters. Takes merge fields.

htmlstring

HTML body, at most 1,000,000 characters, with merge fields. Without the unsubscribeUrl merge field in it an unsubscribe footer is added.

textstring

Plain text body, at most 1,000,000 characters, with merge fields. Without the unsubscribeUrl merge field in it an unsubscribe line is added.

templatearray

A stored template instead of html and text, never beside them, as an array with id and optionally version, props and slots. The merge values reach it as props it declares, such as firstName and unsubscribeUrl.

trackingarray

Open and link tracking for every copy, as an array with opens and clicks, each true or false. A field left out follows the address it is sent from when that address set it, and is on otherwise.

tagsarray

Up to 8 tags as an array of names to values, keys of 1 to 64 letters, digits, _ or -, values up to 256 characters. Every copy carries them, plus broadcast_id, which the server adds.

excludeAudienceIdsstring[]

Up to 10 audiences whose members are left out, even when they are in one of audienceIds, such as the customers who already bought. All contacts may be named here.

segmentIdstring

A saved segment, from segments->create, that narrows the audiences: only the contacts that match its conditions get a copy. Its conditions are read when the broadcast is sent or scheduled and kept with it. An id that names no segment is a 404 segment_not_found.

utmarray

Campaign tags added to every http and https link in the body, with source, medium, campaign, term and content, sent as utm_source and the rest. A link that already carries one keeps its own, and the unsubscribe link never gets them.

abTestarray

An A/B test, an array with variants, 2 to 4 arrays that each replace the subject, or the html and or text, of the broadcast, so an empty one keeps it, testPercent (5 to 50, 20 unless set), the share of people that get a variant, metric, opens or clicks, which picks the winner, and waitMinutes (30 to 4320, 240 unless set) before it is picked. Everybody else then gets the winning variant, and a template broadcast can only vary the subject.

scheduledAtstring|DateTimeInterface

A DateTimeInterface, an ISO 8601 instant or a duration such as PT2H or P1D, in the future and at most 365 days out. A DateTimeInterface goes out as an ISO 8601 instant in UTC. Left out, the sending starts straight away.

idempotencyKeystring

Your own key, 1 to 255 characters of letters, digits, _, ., : or -. Left out, the SDK makes one for the call, so its own retries never send twice. Sending the same key again answers with the broadcast it created instead of a new one. The same key with a different body is a 422 idempotency_key_reuse.

apiKeystring

Sends with this key instead of the client's.

Returns

An array, the broadcast as get returns it plus replayed, with id (brd_ plus 24 hex), status queued or scheduled, audienceIds, from, subject, scheduledAt, createdAt and counts, whose recipients is the estimate and whose other counts start at 0.

Example

$broadcast = $client->broadcasts->send([    'audienceIds' => ['aud_4c1b8e2a7d9f05c36b4e8a71'],    'from' => ['email' => 'news@acme.com', 'name' => 'Acme'],    'subject' => '{{firstName|Hello}}, the September release is out',    'html' => '<p>Hi {{firstName|there}},</p><p>Here is what changed.</p><p><a href="{{unsubscribeUrl}}">Unsubscribe</a></p>',    'text' => "Hi {{firstName|there}},\n\nHere is what changed.\n\nUnsubscribe: {{unsubscribeUrl}}",    'tags' => ['campaign' => 'release-2026-09'],    'scheduledAt' => new \DateTimeImmutable('+2 hours'),], idempotencyKey: 'release-2026-09'); echo $broadcast['id'], ' ', $broadcast['status'], ', about ', $broadcast['counts']['recipients'], ' people', PHP_EOL;

Notes

  • Safe to retry. Every call carries an Idempotency-Key, yours or one the SDK makes, so a retry after a network failure answers with the broadcast the first attempt created, with replayed: true, instead of sending again. Keys are scoped to the API key or app that sent them. Reusing a key with a different body is a 422 idempotency_key_reuse.

  • Refusals: 422 no_recipients when the audiences are empty or everybody in them has unsubscribed or is suppressed, 422 audience_is_everyone when one of them is All contacts, 409 domain_not_sendable when the from domain cannot sign mail yet, 422 on template.* when the template does not resolve.

  • No attachments, cc, bcc, translation or encryption. A body from html or text and a template together are refused.

  • A test key (oe_test_) creates a broadcast whose copies are marked sent and delivered to nobody, like any test send.

Also available in

API
POST /broadcasts
TypeScript
nextmail.broadcasts.send()
Python
broadcasts.send()
Ruby
broadcasts.send
Go
Broadcasts.Send
Java
broadcasts().send
C#
Broadcasts.SendAsync
CLI
nextmail broadcasts send

broadcasts->list

List one page of broadcasts, newest first

Scopesemails:readPages through results
Signature
list(    ?string $audienceId = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): Page

Returns one page of the broadcasts in the workspace, newest first, each with live counts. audienceId: keeps the ones that were sent to that audience, alone or beside others.

Paging is keyset: limit: takes 1 to 100 and defaults to 25, and nextCursor, the id of the last broadcast on the page, goes back as cursor: while hasMore is true. Send the same audienceId: with every page. listAll and iterate do that walk for you.

The individual messages are not here. List the copies of one broadcast with emails->list and broadcastId:.

Parameters

audienceIdstring

Only the broadcasts that included this audience. An id that names no audience answers an empty page.

limitint

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

cursorstring

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

apiKeystring

Overrides the client's API key for this call only.

Returns

A Page of arrays with items, hasMore and nextCursor. Each item has id, status, audienceIds, from, subject, counts and the timestamps.

Example

$page = $client->broadcasts->list(audienceId: 'aud_4c1b8e2a7d9f05c36b4e8a71', limit: 10); foreach ($page as $broadcast) {    $counts = $broadcast['counts'];     echo $broadcast['createdAt'], ' ', $broadcast['subject'], ' ', $broadcast['status'], ' ', $counts['sent'], '/', $counts['recipients'], PHP_EOL;}

Notes

  • A key limited to particular addresses or domains lists only the broadcasts sent from an address or domain it holds.

Also available in

API
GET /broadcasts
TypeScript
nextmail.broadcasts.list()
Python
broadcasts.list()
Ruby
broadcasts.list
Go
Broadcasts.List
Java
broadcasts().list
C#
Broadcasts.ListAsync
CLI
nextmail broadcasts list

broadcasts->listAll

Collect every broadcast into one array

Scopesemails:readPages through results
Signature
listAll(    ?string $audienceId = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): array

Follows nextCursor from page to page and returns every broadcast in the workspace, newest first, or every one sent to audienceId: when you pass it. limit sets the page size of each request, not the total.

Parameters

audienceIdstring

Only the broadcasts that included this audience.

limitint

Page size per request, from 1 to 100, defaulting to 25 on the server.

cursorstring

A broadcast id to start after.

apiKeystring

Overrides the client's API key for every page of this walk.

Returns

A list of arrays holding every broadcast across all pages, each shaped like an item of list.

Example

$broadcasts = $client->broadcasts->listAll(limit: 100); $sent = array_sum(array_map(static fn(array $broadcast): int => $broadcast['counts']['sent'], $broadcasts)); echo $sent, ' copies sent across every broadcast', PHP_EOL;

Notes

  • A failure on any page throws out of the whole call.

  • Every row carries live counts, so collecting a long history reads the copies of every broadcast in it. Use iterate to stop early.

  • A key limited to particular addresses or domains lists only the broadcasts sent from an address or domain it holds.

Also available in

API
GET /broadcasts
TypeScript
nextmail.broadcasts.listAll()
Python
broadcasts.list_all()
Ruby
broadcasts.list_all
Go
Broadcasts.ListAll
Java
broadcasts().listAll
C#
Broadcasts.ListAllAsync

broadcasts->iterate

Stream broadcasts one at a time, newest first

Scopesemails:readPages through results
Signature
iterate(    ?string $audienceId = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): Generator

Returns a Generator that yields broadcasts one at a time, newest first, and requests the next page only once the current one is drained. Breaking out of the loop stops the requests, so this is the cheap way to find the latest broadcast that matches something the filters cannot express.

Parameters

audienceIdstring

Only the broadcasts that included this audience.

limitint

Page size per request, from 1 to 100, defaulting to 25 on the server.

cursorstring

A broadcast id to start after.

apiKeystring

Overrides the client's API key for every page of this walk.

Returns

A Generator that yields one broadcast array per step.

Example

use Nextmail\Constants\BroadcastStatuses; foreach ($client->broadcasts->iterate() as $broadcast) {    if ($broadcast['status'] === BroadcastStatuses::SENDING) {        echo 'Still going: ', $broadcast['id'], ', ', $broadcast['counts']['queued'], ' waiting', PHP_EOL;         break;    }}

Notes

  • The generator is lazy, so an abandoned loop costs only the pages you consumed.

  • A key limited to particular addresses or domains lists only the broadcasts sent from an address or domain it holds.

Also available in

API
GET /broadcasts
TypeScript
nextmail.broadcasts.iterate()
Python
broadcasts.iterate()
Ruby
broadcasts.iterate
Go
Broadcasts.Iterate
Java
broadcasts().iterate
C#
Broadcasts.IterateAsync

broadcasts->get

Read one broadcast and how far it has got

Scopesemails:read
Signature
get(string $id, ?string $apiKey = null): array

Returns one broadcast with counts read live from its copies, which makes this the call to poll while it sends.

status moves from scheduled or queued to sending and settles on sent once every copy handed over has gone out or failed. It reads sending for as long as copies are still waiting, even after the last person was reached and completedAt was set. cancelled and failed are the other two ends, and on failed lastError says why: the from address can no longer be sent from, the template stopped resolving, the plan ran out part way, the sending itself kept failing, or not one copy could be written.

counts.recipients is the estimate taken when it was created. created is the copies written, one per person reached, skipped the people passed over because their address was suppressed by then, and failedToQueue the people whose copy could not be written. queued, sending, sent, failed and cancelled count the copies by the state each one is in now.

Parameters

idstringRequired

A brd_ id from send or list.

apiKeystring

Overrides the client's API key for this call only.

Returns

An array with id, status, mode, source, audienceIds, from, subject, counts, lastError, scheduledAt, startedAt, completedAt, cancelledAt, createdAt and updatedAt.

Example

use Nextmail\Constants\BroadcastStatuses; $broadcast = $client->broadcasts->get('brd_5a8c1e3f7b2d94a06c8e1f3b'); while ($broadcast['status'] === BroadcastStatuses::QUEUED || $broadcast['status'] === BroadcastStatuses::SENDING) {    echo $broadcast['counts']['sent'], ' of ', $broadcast['counts']['recipients'], ' sent', PHP_EOL;     sleep(10);     $broadcast = $client->broadcasts->get($broadcast['id']);} echo $broadcast['status'], ' ', $broadcast['lastError'] ?? '', PHP_EOL;

Notes

  • A missing broadcast throws a NotFoundException, whose isNotFound() is true, with errorCode broadcast_not_found. An id from another workspace is a 404 too.

  • For who each copy went to and what happened to it, use listRecipients, getRecipient reads one copy with its content, and stats sums it up.

  • A key limited to particular addresses or domains reads only broadcasts sent from an address or domain it holds. Any other id throws an ApiException with errorCode broadcast_not_found, as if the broadcast did not exist.

Also available in

API
GET /broadcasts/{id}
TypeScript
nextmail.broadcasts.get()
Python
broadcasts.get()
Ruby
broadcasts.get
Go
Broadcasts.Get
Java
broadcasts().get
C#
Broadcasts.GetAsync
CLI
nextmail broadcasts get

broadcasts->stats

Read how a broadcast performed

Scopesemails:read
Signature
stats(    string $id,    ?string $grain = null,    ?int $offsetMinutes = null,    ?int $days = null,    ?int $minutes = null,    ?string $apiKey = null,): array

Returns the totals and a series for one broadcast. totals counts copies sent, delivered, bounced, complained (reported as spam) and failed, pending for the ones still waiting, and people who opened, clicked and unsubscribed, with opens and clicks as event counts. series is sparse and oldest first: one bucket per grain in which something happened, counting each person once at the first time it happened to them, so it adds up to the totals.

Pass days: or minutes: to also read what happened lately. window then counts the copies delivered, bounced, reported as spam, opened, clicked and unsubscribed inside it, and series keeps only its buckets, while totals still covers the whole broadcast. Without either, window is null.

Parameters

idstringRequired

A brd_ id from send or list.

grainstring

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

offsetMinutesint

Minutes east of UTC to cut the buckets in, from -840 to 840. Pass intdiv((int) date('Z'), 60) for the zone PHP is set to.

daysint

Reads a window of this many days too, from 1 to 1095. It starts at the beginning of its first grain bucket and ends now.

minutesint

The window in minutes, from 1 to 1576800, which wins over days when both are sent.

apiKeystring

Overrides the client API key for this call only.

Returns

An array with broadcastId, grain, totals, window and series, each bucket of series an array with bucket, delivered, opened, clicked and unsubscribed. window is an array with since, delivered, bounced, complained, opened, clicked and unsubscribed, or null when no window was asked for. links lists the links clicked most, clients the mail clients and countries the countries people opened it from, and abTest how each variant of an A/B test did and which one won, or null without a test.

Example

$stats = $client->broadcasts->stats('brd_5a8c1e3f7b2d94a06c8e1f3b', grain: 'day', days: 7);$totals = $stats['totals']; $rate = $totals['sent'] > 0 ? $totals['opened'] / $totals['sent'] : 0; echo round($rate * 100), '% of the people sent it opened it', PHP_EOL; foreach ($stats['series'] as $bucket) {    echo $bucket['bucket'], ': ', $bucket['opened'], ' opened, ', $bucket['clicked'], ' clicked', PHP_EOL;}

Notes

  • Read only, so the SDK retries it after a network failure like any other read.

  • A key limited to particular addresses or domains reads only broadcasts sent from an address or domain it holds. Any other id throws an ApiException with errorCode broadcast_not_found, as if the broadcast did not exist.

Also available in

API
GET /broadcasts/{id}/stats
TypeScript
nextmail.broadcasts.stats()
Python
broadcasts.stats()
Ruby
broadcasts.stats
Go
Broadcasts.Stats
Java
broadcasts().stats
C#
Broadcasts.StatsAsync
CLI
nextmail broadcasts stats

broadcasts->analytics

Read how broadcasts did over a time window

Scopesemails:read
Signature
analytics(    array|string|null $broadcastIds = null,    ?int $days = null,    ?int $minutes = null,    ?string $grain = null,    ?int $offsetMinutes = null,    ?string $apiKey = null,): array

Returns the numbers behind the Analytics tab of the Broadcasts page in one request: how the live broadcasts sent inside a window did, added up in totals and cut to grain in series, and one row per broadcast in broadcasts so they can be compared.

A copy counts when it was sent inside the window, and everything that happened to it afterwards counts with it, so an open today of a copy sent last week is in a 30 day window but not in a 1 day one. Test mode broadcasts are left out. totals and series add up the broadcasts named in broadcastIds:, or every one when it is left out, while broadcasts always lists every broadcast in the window, newest first.

series is sparse and oldest first: a bucket in which nothing happened has no entry, so a chart must fill the gaps. It counts each person once, at the first time it happened to them. grain: sets the bucket width and the key shape, YYYY-MM-DD, YYYY-MM-DDTHH or YYYY-MM-DDTHH:MM, and offsetMinutes: 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.

Parameters

broadcastIdsstring|string[]

Up to 50 broadcast ids for totals and series to add up, as an array or one comma-separated string, sent comma separated. Leave it out, or pass an empty array, for every broadcast in the window. An id with no copy in the window adds nothing, and more than 50 is a 422.

daysint

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

minutesint

Window length in minutes, from 1 to 1576800, which wins over days when both are sent.

grainstring

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

offsetMinutesint

Minutes east of UTC to cut the buckets in, from -840 to 840, defaulting to 0. Pass intdiv((int) date('Z'), 60) for the zone PHP is set to.

apiKeystring

Overrides the client API key for this call only.

Returns

An array with object set to broadcast_analytics, since, until, grain, offsetMinutes, broadcastIds, totals, series and broadcasts. totals has broadcasts and the counts the totals of stats has, each entry of series is an array with bucket, sent, delivered, opened, clicked and unsubscribed, and each entry of broadcasts has id, subject, status, sentAt and the same counts.

Example

$analytics = $client->broadcasts->analytics(days: 90, offsetMinutes: intdiv((int) date('Z'), 60));$totals = $analytics['totals']; echo $totals['broadcasts'], ' broadcasts, ', $totals['opened'], ' people opened one', PHP_EOL; foreach ($analytics['broadcasts'] as $row) {    echo $row['subject'], ': ', $row['sent'], ' sent, ', $row['opened'], ' opened, ', $row['clicked'], ' clicked', PHP_EOL;}

Notes

  • Read only, so the SDK retries it after a network failure like any other read.

  • opened, clicked and unsubscribed count people, while opens and clicks count events.

  • A key limited to particular addresses or domains reads only broadcasts sent from an address or domain it holds, and the rest are left out as if they did not exist.

Also available in

API
GET /broadcasts/analytics
TypeScript
nextmail.broadcasts.analytics()
Python
broadcasts.analytics()
Ruby
broadcasts.analytics
Go
Broadcasts.Analytics
Java
broadcasts().analytics
C#
Broadcasts.AnalyticsAsync
CLI
nextmail broadcasts analytics

broadcasts->listRecipients

List who a broadcast went to and what happened to each copy

Scopesemails:readPages through results
Signature
listRecipients(    string $id,    ?string $filter = null,    ?string $q = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): Page

Returns one page of the people a broadcast went to, one row per copy, sorted by address. Each row says the copy's status, when it was sent and delivered, whether it bounced or was reported as spam, how often it was opened and clicked, and whether the person unsubscribed from one of the broadcast's audiences after it went out.

Opens and clicks leave out image proxies and link scanners, and stay 0 when the broadcast went out with tracking off. emailId is the copy's msg_ id, which getRecipient reads with its content and emails->get reads as a sent email.

Parameters

idstringRequired

A brd_ id from send or list.

filterstring

Keeps one group: pending, sent, delivered, opened, not_opened (sent and never opened), clicked, bounced, complained, failed (failed or cancelled) or unsubscribed. Nextmail\Constants\BroadcastRecipientFilters names them.

qstring

Searches the address and the name, ignoring case.

limitint

Page size, from 1 to 200. The server defaults to 50.

cursorstring

The nextCursor of the previous page. Send the same filter: and q: with it.

apiKeystring

Overrides the client API key for this call only.

Returns

A Page of arrays with items, hasMore and nextCursor. Each item has emailId, contactId, email, name, status, sentAt, deliveredAt, bouncedAt, complainedAt, failure, opens, firstOpenAt, clicks, firstClickAt and unsubscribedAt.

Example

use Nextmail\Constants\BroadcastRecipientFilters; $page = $client->broadcasts->listRecipients('brd_5a8c1e3f7b2d94a06c8e1f3b', filter: BroadcastRecipientFilters::BOUNCED); foreach ($page as $copy) {    echo $copy['email'], ' bounced at ', $copy['bouncedAt'], PHP_EOL;}

Notes

  • A missing broadcast throws an ApiException with errorCode broadcast_not_found.

  • A key limited to particular addresses or domains reads only broadcasts sent from an address or domain it holds. Any other id throws an ApiException with errorCode broadcast_not_found, as if the broadcast did not exist.

Also available in

API
GET /broadcasts/{id}/recipients
TypeScript
nextmail.broadcasts.listRecipients()
Python
broadcasts.list_recipients()
Ruby
broadcasts.list_recipients
Go
Broadcasts.ListRecipients
Java
broadcasts().listRecipients
C#
Broadcasts.ListRecipientsAsync
CLI
nextmail broadcasts list-recipients

broadcasts->listAllRecipients

Collect everybody a broadcast went to into one array

Scopesemails:readPages through results
Signature
listAllRecipients(    string $id,    ?string $filter = null,    ?string $q = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): array

Walks every page of listRecipients and returns every copy of the broadcast, sorted by address. One request per page, with the same filter: and q: on each.

Parameters

idstringRequired

A brd_ id from send or list.

filterstring

Keeps one group: pending, sent, delivered, opened, not_opened (sent and never opened), clicked, bounced, complained, failed (failed or cancelled) or unsubscribed. Nextmail\Constants\BroadcastRecipientFilters names them.

qstring

Searches the address and the name, ignoring case.

limitint

Page size for each request, from 1 to 200. The server defaults to 50.

cursorstring

Starts the walk after this cursor instead of the first page.

apiKeystring

Overrides the client API key for every page of this walk.

Returns

A list of arrays holding every copy that matches, each shaped like an item of listRecipients.

Example

use Nextmail\Constants\BroadcastRecipientFilters; $unopened = $client->broadcasts->listAllRecipients('brd_5a8c1e3f7b2d94a06c8e1f3b', filter: BroadcastRecipientFilters::NOT_OPENED); echo implode(PHP_EOL, array_column($unopened, 'email')), PHP_EOL;

Notes

  • If any page fails the call throws and the rows already fetched are discarded.

  • A key limited to particular addresses or domains reads only broadcasts sent from an address or domain it holds. Any other id throws an ApiException with errorCode broadcast_not_found, as if the broadcast did not exist.

Also available in

API
GET /broadcasts/{id}/recipients
TypeScript
nextmail.broadcasts.listAllRecipients()
Python
broadcasts.list_all_recipients()
Ruby
broadcasts.list_all_recipients
Go
Broadcasts.ListAllRecipients
Java
broadcasts().listAllRecipients
C#
Broadcasts.ListAllRecipientsAsync

broadcasts->iterateRecipients

Walk everybody a broadcast went to, one copy at a time

Scopesemails:readPages through results
Signature
iterateRecipients(    string $id,    ?string $filter = null,    ?string $q = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): Generator

Returns a Generator that yields every copy of the broadcast one at a time, fetching the next page only when the loop asks for it, sorted by address. Breaking out of the loop stops the requests.

Parameters

idstringRequired

A brd_ id from send or list.

filterstring

Keeps one group: pending, sent, delivered, opened, not_opened (sent and never opened), clicked, bounced, complained, failed (failed or cancelled) or unsubscribed. Nextmail\Constants\BroadcastRecipientFilters names them.

qstring

Searches the address and the name, ignoring case.

limitint

Page size for each request, from 1 to 200. The server defaults to 50.

cursorstring

Starts after this cursor instead of the first page.

apiKeystring

Overrides the client API key for every page of this walk.

Returns

A Generator that yields one copy per step, each shaped like an item of listRecipients.

Example

use Nextmail\Constants\BroadcastRecipientFilters; $copies = $client->broadcasts->iterateRecipients('brd_5a8c1e3f7b2d94a06c8e1f3b', filter: BroadcastRecipientFilters::CLICKED); foreach ($copies as $copy) {    echo $copy['email'], ' clicked ', $copy['clicks'], ' times', PHP_EOL;}

Notes

  • Memory stays flat however large the broadcast, because only one page is held at a time.

  • A key limited to particular addresses or domains reads only broadcasts sent from an address or domain it holds. Any other id throws an ApiException with errorCode broadcast_not_found, as if the broadcast did not exist.

Also available in

API
GET /broadcasts/{id}/recipients
TypeScript
nextmail.broadcasts.iterateRecipients()
Python
broadcasts.iterate_recipients()
Ruby
broadcasts.iterate_recipients
Go
Broadcasts.IterateRecipients
Java
broadcasts().iterateRecipients
C#
Broadcasts.IterateRecipientsAsync

broadcasts->getRecipient

Read one person's copy of a broadcast

Scopesemails:read
Signature
getRecipient(string $id, string $emailId, ?string $apiKey = null): array

Returns one copy: the same row listRecipients gives, plus the subject, html and text exactly as that person received them, with the merge fields filled in and their own unsubscribe link. The HTML is from before open and click tracking was added.

Parameters

idstringRequired

A brd_ id from send or list.

emailIdstringRequired

The emailId of the copy, from listRecipients.

apiKeystring

Overrides the client API key for this call only.

Returns

An array with emailId, contactId, email, name, status, sentAt, deliveredAt, bouncedAt, complainedAt, failure, opens, firstOpenAt, clicks, firstClickAt and unsubscribedAt, plus subject, html and text.

Example

$copy = $client->broadcasts->getRecipient('brd_5a8c1e3f7b2d94a06c8e1f3b', 'msg_01dad25067bc4dac966d515d'); echo $copy['subject'], ', delivered ', $copy['deliveredAt'] ?? 'not yet', PHP_EOL;echo $copy['text'], PHP_EOL;

Notes

  • An emailId that is not a copy of this broadcast throws an ApiException with errorCode recipient_not_found.

  • A key limited to particular addresses or domains reads only broadcasts sent from an address or domain it holds. Any other id throws an ApiException with errorCode broadcast_not_found, as if the broadcast did not exist.

Also available in

API
GET /broadcasts/{id}/recipients/{emailId}
TypeScript
nextmail.broadcasts.getRecipient()
Python
broadcasts.get_recipient()
Ruby
broadcasts.get_recipient
Go
Broadcasts.GetRecipient
Java
broadcasts().getRecipient
C#
Broadcasts.GetRecipientAsync
CLI
nextmail broadcasts get-recipient

broadcasts->cancel

Stop a broadcast that is scheduled, queued or still sending

Scopesemails:send
Signature
cancel(string $id, ?string $apiKey = null): array

Stops a broadcast that is scheduled, queued or sending, including one that has reached everybody while some copies are still waiting to go. Nobody else is added, and every copy still waiting is cancelled. A copy already being handed over finishes, and copies that have gone cannot be recalled, so counts.sent keeps them and counts.cancelled shows what was stopped.

Once every copy has gone out there is nothing left to stop, and the call throws 409 broadcast_not_cancellable. A failed broadcast with copies still waiting can be cancelled to stop them, and one with nothing waiting is refused the same way. Cancelling a broadcast that is already cancelled returns it as it stands, so the call is safe to repeat, and the SDK retries it after a network failure.

Parameters

idstringRequired

The brd_ id to cancel.

apiKeystring

Cancels with this key instead of the client's.

Returns

An array, the broadcast as get returns it in its new state: status cancelled with cancelledAt set and the copies counted by where each one ended up.

Example

$scheduled = $client->broadcasts->send([    'audienceIds' => ['aud_4c1b8e2a7d9f05c36b4e8a71'],    'from' => 'news@acme.com',    'subject' => 'Doors open on Friday',    'text' => 'Hi {{firstName|there}}, doors open at nine.',    'scheduledAt' => 'P1D',]); $cancelled = $client->broadcasts->cancel($scheduled['id']); echo $cancelled['status'], ', ', $cancelled['counts']['cancelled'], ' copies stopped', PHP_EOL;

Notes

  • Cancelling a scheduled broadcast before scheduledAt sends nothing at all.

  • A cancelled broadcast stays cancelled. There is no resume, so send again to the audiences that still need it.

  • A key limited to particular addresses or domains cancels only broadcasts sent from an address or domain it holds. Any other id throws an ApiException with errorCode broadcast_not_found, as if the broadcast did not exist.

Also available in

API
POST /broadcasts/{id}/cancel
TypeScript
nextmail.broadcasts.cancel()
Python
broadcasts.cancel()
Ruby
broadcasts.cancel
Go
Broadcasts.Cancel
Java
broadcasts().cancel
C#
Broadcasts.CancelAsync
CLI
nextmail broadcasts cancel

broadcasts->createDraft

Save a broadcast as a draft without sending it

Scopesemails:sendaudiences:read
Signature
createDraft(array $body, ?string $apiKey = null): array

Saves a broadcast with status draft. Nothing is sent, nothing counts against the plan and the audiences may still be empty, so a draft can be written over several sittings. update changes it, sendDraft sends it or schedules it, and get returns what it holds in content.

The body takes the fields send takes, except scheduledAt, which belongs to sendDraft. Only from is required. The sender, the audiences and a template are checked as they are saved.

Parameters

fromstring|arrayRequired

Sender as news@acme.com or Acme <news@acme.com>, or an array with email and name. It must be an address the key may send as, otherwise 403 from_address_forbidden.

audienceIdsstring[]

Up to 10 audience ids. Left out or empty, the draft has no audience yet and sendDraft refuses it until update gives it one.

excludeAudienceIdsstring[]

Up to 10 audiences whose members are left out, even when they are in one of audienceIds.

segmentIdstring

A saved segment that narrows the audiences when the draft is sent. It has to exist when the draft is saved and again when it is sent.

replyTostring|array

Where replies go, the same for every copy.

subjectstring

At most 998 characters, with merge fields. Needed before sending unless a template supplies it.

htmlstring

HTML body, at most 1,000,000 characters, with merge fields.

textstring

Plain text body, at most 1,000,000 characters, with merge fields.

templatearray

A stored template instead of html and text, with id and, optionally, version, props and slots.

trackingarray

Open and link tracking for every copy, with opens and clicks.

tagsarray<string, string>

Up to 8 tags every copy carries.

utmarray

Campaign tags added to every http and https link in the body, with source, medium, campaign, term and content, sent as utm_source and the rest. A link that already carries one keeps its own, and the unsubscribe link never gets them.

abTestarray

An A/B test, as send takes it.

apiKeystring

Overrides the client's API key for this call only.

Returns

An array, the broadcast with status draft, counts at 0 and the saved fields in content.

Example

$draft = $client->broadcasts->createDraft([    'from' => 'Acme <news@acme.com>',    'audienceIds' => ['aud_4c1b8e2a7d9f05c36b4e8a71'],    'subject' => 'The October release',    'text' => 'Hi {{firstName|there}}, here is what changed this month.',    'utm' => ['source' => 'newsletter', 'medium' => 'email', 'campaign' => 'october-release'],]); echo $draft['id'], ' ', $draft['status'], PHP_EOL;

Notes

Also available in

API
POST /broadcasts/drafts
TypeScript
nextmail.broadcasts.createDraft()
Python
broadcasts.create_draft()
Ruby
broadcasts.create_draft
Go
Broadcasts.CreateDraft
Java
broadcasts().createDraft
C#
Broadcasts.CreateDraftAsync
CLI
nextmail broadcasts create-draft

broadcasts->update

Change a draft, or a scheduled broadcast before it starts

Scopesemails:sendaudiences:read
Signature
update(string $id, array $patch, ?string $apiKey = null): array

A partial update: a field you leave out keeps what it holds, and null clears replyTo, html, text, template or utm. Sending any of html, text or template replaces the body as a whole.

A draft takes every change and stays a draft. A scheduled broadcast takes changes until its sending starts, and each change is checked the way send checks a new one, so counts.recipients is counted again. scheduledAt moves a scheduled broadcast to another time. Once a broadcast is queued, sending or finished, the call throws 409 broadcast_not_editable.

Parameters

idstringRequired

The brd_ id of a draft or of a scheduled broadcast.

audienceIdsstring[]

The new audiences, replacing the old list, up to 10.

excludeAudienceIdsstring[]

The new list of audiences whose members are left out.

segmentIdstring|null

A saved segment that narrows the audiences. Null takes it away.

fromstring|array

A new sender the key may send as.

replyTostring|array|null

Where replies go. null takes it away.

subjectstring

A new subject, with merge fields.

htmlstring|null

A new HTML body.

textstring|null

A new plain text body.

templatearray|null

A stored template instead of html and text.

trackingarray

Open and link tracking for every copy.

tagsarray<string, string>

The new tags, replacing the old ones.

utmarray|null

New campaign tags for the links. null takes them away.

abTestarray|null

A new A/B test, as send takes it. null takes it away.

scheduledAtstring|\DateTimeInterface

A new start for a scheduled broadcast: an ISO 8601 instant or a duration such as PT2H. A draft refuses it with 422 invalid_parameter, since sendDraft schedules a draft.

apiKeystring

Overrides the client's API key for this call only.

Returns

An array, the broadcast as it stands after the change, with content.

Example

$draft = $client->broadcasts->createDraft(['from' => 'news@acme.com', 'subject' => 'Draft']); $updated = $client->broadcasts->update($draft['id'], [    'audienceIds' => ['aud_4c1b8e2a7d9f05c36b4e8a71'],    'subject' => 'Doors open on Friday',    'text' => 'Hi {{firstName|there}}, doors open at nine.',]); echo $updated['status'], ' ', $updated['subject'], PHP_EOL;

Notes

Also available in

API
PATCH /broadcasts/{id}
TypeScript
nextmail.broadcasts.update()
Python
broadcasts.update()
Ruby
broadcasts.update
Go
Broadcasts.Update
Java
broadcasts().update
C#
Broadcasts.UpdateAsync
CLI
nextmail broadcasts update

broadcasts->sendDraft

Send a draft now, or schedule it

Scopesemails:sendaudiences:read
Signature
sendDraft(string $id, ?array $body = null, ?string $apiKey = null): array

Turns a draft into a broadcast that goes out: queued straight away, or scheduled when you pass scheduledAt. The draft is checked the way send checks a new broadcast, so it needs an audience, a body, a subject or a template that supplies one, somebody to reach, and room in the plan for every copy.

A broadcast that is not a draft throws 409 broadcast_not_draft, so calling it twice never sends twice.

Parameters

idstringRequired

The brd_ id of the draft.

scheduledAtstring|\DateTimeInterface

An ISO 8601 instant or a duration such as PT2H, in the future and at most 365 days out. Left out, the sending starts straight away.

apiKeystring

Overrides the client's API key for this call only.

Returns

An array, the broadcast with status queued or scheduled and counts.recipients estimated at the call.

Example

$draft = $client->broadcasts->createDraft([    'from' => 'Acme <news@acme.com>',    'audienceIds' => ['aud_4c1b8e2a7d9f05c36b4e8a71'],    'subject' => 'Doors open on Friday',    'text' => 'Hi {{firstName|there}}, doors open at nine.',]); $sent = $client->broadcasts->sendDraft($draft['id'], ['scheduledAt' => 'PT2H']); echo $sent['status'], ' ', $sent['scheduledAt'], PHP_EOL;

Notes

Also available in

API
POST /broadcasts/{id}/send
TypeScript
nextmail.broadcasts.sendDraft()
Python
broadcasts.send_draft()
Ruby
broadcasts.send_draft
Go
Broadcasts.SendDraft
Java
broadcasts().sendDraft
C#
Broadcasts.SendDraftAsync
CLI
nextmail broadcasts send-draft

broadcasts->duplicate

Copy a broadcast into a new draft

Scopesemails:sendaudiences:read
Signature
duplicate(string $id, ?string $apiKey = null): array

Makes a new draft from any broadcast, with the same sender, audiences, left-out audiences, subject, body or template, tracking, tags and campaign tags. The time it was scheduled for is not copied. The original is not changed, and nothing is sent until sendDraft.

Parameters

idstringRequired

The brd_ id to copy.

apiKeystring

Overrides the client's API key for this call only.

Returns

An array, the new draft with its own brd_ id, status draft and content.

Example

$copy = $client->broadcasts->duplicate('brd_5e8a2c1f9b3d74e06a5c2f81'); echo $copy['id'], ' ', $copy['status'], PHP_EOL;

Notes

Also available in

API
POST /broadcasts/{id}/duplicate
TypeScript
nextmail.broadcasts.duplicate()
Python
broadcasts.duplicate()
Ruby
broadcasts.duplicate
Go
Broadcasts.Duplicate
Java
broadcasts().duplicate
C#
Broadcasts.DuplicateAsync
CLI
nextmail broadcasts duplicate

broadcasts->resend

Send a broadcast again to the people who did not open it

Scopesemails:sendaudiences:read
Signature
resend(string $id, ?array $body = null, ?string $apiKey = null): array

Creates a new broadcast with the same content for the people the first one reached and who have not opened it, optionally under a new subject. Somebody who has unsubscribed since, or whose address is now suppressed, is skipped. The new broadcast carries content.resendOf, and counts against the plan like any send.

The first broadcast has to have finished going out and to have tracked opens. Otherwise the call throws 409 resend_unavailable.

Parameters

idstringRequired

The brd_ id of the broadcast that went out.

subjectstring

A new subject for the second try, with merge fields. Left out, the first subject is used.

scheduledAtstring|\DateTimeInterface

When to start, in the future and at most 365 days out. Left out, the sending starts straight away.

apiKeystring

Overrides the client's API key for this call only.

Returns

An array, the new broadcast, queued or scheduled, with counts.recipients holding the people who had not opened.

Example

$second = $client->broadcasts->resend('brd_5e8a2c1f9b3d74e06a5c2f81', [    'subject' => 'In case you missed it: doors open on Friday',    'scheduledAt' => 'P2D',]); echo $second['id'], ' ', $second['counts']['recipients'], PHP_EOL;

Notes

Also available in

API
POST /broadcasts/{id}/resend
TypeScript
nextmail.broadcasts.resend()
Python
broadcasts.resend()
Ruby
broadcasts.resend
Go
Broadcasts.Resend
Java
broadcasts().resend
C#
Broadcasts.ResendAsync
CLI
nextmail broadcasts resend

broadcasts->sendTest

Send a test copy of a broadcast to yourself or a few people

Scopesemails:send
Signature
sendTest(array $body, ?string $apiKey = null): array

Sends one copy of a broadcast to up to five addresses, to read it before it goes to an audience. It goes to the account address of the person the key or app acts for, the workspace owner for an API key, unless to names others. The merge fields are filled from the contact that has the address when there is one and from a sample name otherwise, the subject starts with [Test], the unsubscribe footer is added as it would be and its link does nothing. Opens and clicks are not tracked, and utm is applied to the links.

No broadcast is created and nobody joins an audience. Each copy counts as one send.

Parameters

fromstring|arrayRequired

The sender, an address the key may send as.

toarray

1 to 5 addresses. Left out, the test goes to the account address of the person the key or app acts for.

replyTostring|array

Where replies go.

subjectstring

Required unless a template supplies it, with merge fields.

htmlstring

HTML body with merge fields.

textstring

Plain text body with merge fields.

templatearray

A stored template instead of html and text.

utmarray

Campaign tags added to the links, as the broadcast would add them.

apiKeystring

Overrides the client's API key for this call only.

Returns

An array with the msg_ id of each copy in emailIds and the addresses in to.

Example

$test = $client->broadcasts->sendTest([    'from' => 'Acme <news@acme.com>',    'to' => ['me@acme.com'],    'subject' => '{{firstName|Hello}}, doors open on Friday',    'html' => '<p>Hi {{firstName|there}}, doors open at nine.</p>',]); echo implode(', ', $test['emailIds']), PHP_EOL;

Notes

  • The SDK does not retry it, since a retry would send the test again.

Also available in

API
POST /broadcasts/test
TypeScript
nextmail.broadcasts.sendTest()
Python
broadcasts.send_test()
Ruby
broadcasts.send_test
Go
Broadcasts.SendTest
Java
broadcasts().sendTest
C#
Broadcasts.SendTestAsync
CLI
nextmail broadcasts send-test