nextmail.subscriptions
Every method in this namespace: its signature, its parameters, what it returns and an example.
Methods
The newsletters and mailing lists the mailbox receives: list them by sender or by domain, unsubscribe, and move what they send.
nextmail.subscriptions.list()
List subscriptions
list(options?: SubscriptionListOptions): Promise<SubscriptionListResource>Resolves the newsletters and mailing lists the mailbox receives, as the Subscriptions page of the app shows them: one row per sender and the address it writes to, found from the List-Unsubscribe header of the mail it sends. Each row says how much mail the sender sent, how much of it is unread, readPercent (the share of it you read, 0 to 100) and how much arrived in the last 30 days, how it lets you unsubscribe, and the rule that keeps moving its new mail when there is one.
suggested marks an active sender worth leaving: it can be unsubscribed, sent at least 5 emails, wrote in the last 30 days and has 10% or less of its mail read. suggested: true lists only those.
status is active, the default, kept for the ones you chose to keep with keep, or unsubscribed. q searches the sender, and sort is recent, most, emails (most mail overall), read (least read first), unread or name. Paging is by offset: total counts every match and hasMore says whether another page follows.
A key limited to particular addresses lists only the subscriptions delivered to them, and address narrows the list to one address.
Parameters
options.statusSubscriptionStatusactive,keptorunsubscribed. Defaults toactive.options.qstringSearches the sender name and address.
options.sortSubscriptionSortrecent,most,emails,read,unreadorname. Defaults torecent.options.suggestedbooleanOnly the senders worth unsubscribing from, the rows whose
suggestedis true.options.limitnumberRows per page, 1 to 200, defaulting to 50.
options.offsetnumberHow many rows to skip.
options.addressstringOnly the subscriptions delivered to this address.
options.signalAbortSignalCancels the request.
options.apiKeystringOverrides the client's API key for this call only.
Returns
SubscriptionListResource, { object: 'list', data, total, counts, hasMore }, where counts holds how many are active, kept and unsubscribed.
Example
const page = await nextmail.subscriptions.list({ sort: 'emails', limit: 20 }) for (const row of page.data) console.log(row.senderEmail, row.total, `${row.readPercent}% read`, row.suggested)Notes
Read only, so the SDK retries it after a network failure like any other read.
Also available in
nextmail.subscriptions.listDomains()
List subscriptions by domain
listDomains(options?: SubscriptionListOptions): Promise<SubscriptionDomainListResource>Resolves the same subscriptions as list, one row per sender domain with the counts of its senders added up, so a company that writes from several addresses is one row. unsubscribable counts the senders on the domain that can be unsubscribed without a person opening a page, which is what unsubscribeDomain acts on, and readPercent is the share of the domain's mail you read.
It takes the same filters as list, and suggested: true lists the domains of the suggested senders.
Parameters
options.statusSubscriptionStatusactive,keptorunsubscribed. Defaults toactive.options.qstringSearches the sender name and address.
options.sortSubscriptionSortrecent,most,emails,read,unreadorname. Defaults torecent.options.suggestedbooleanOnly the senders worth unsubscribing from, the rows whose
suggestedis true.options.limitnumberRows per page, 1 to 200, defaulting to 50.
options.offsetnumberHow many rows to skip.
options.addressstringOnly the subscriptions delivered to this address.
options.signalAbortSignalCancels the request.
options.apiKeystringOverrides the client's API key for this call only.
Returns
SubscriptionDomainListResource, { object: 'list', data, total, counts, hasMore }.
Example
const page = await nextmail.subscriptions.listDomains({ sort: 'most' }) for (const row of page.data) console.log(row.domain, row.senders, row.unsubscribable)Notes
Read only, so the SDK retries it after a network failure like any other read.
Also available in
nextmail.subscriptions.keep()
Keep subscriptions you want
keep(ids: Array<string>, body?: SubscriptionKeep, options?: RequestScope): Promise<SubscriptionBatchKeepResource>Marks active subscriptions as ones you want, as Keep on the Subscriptions page does: they move from active to kept, are never suggested again and are left alone by unsubscribeDomain. kept: false puts kept subscriptions back to active.
updated holds the subscriptions that changed. A subscription already in that state, or one you unsubscribed from, comes back in skipped, and an id that is unknown or delivered to an address the key does not reach in missing.
Parameters
idsArray<string>Required1 to 100 subscription ids from
list. A repeated id counts once.body.keptbooleantruekeeps them,falseputs them back to active. Defaults to true.options.signalAbortSignalCancels the request.
options.apiKeystringOverrides the client's API key for this call only.
Returns
SubscriptionBatchKeepResource, { object: 'subscription_batch_keep', kept, updated, skipped, missing }, each list holding subscription ids.
Example
const result = await nextmail.subscriptions.keep(['sub_7d2c1f0a9b3e4c5d6e7f8a9b']) console.log(`${result.updated.length} kept`)Notes
The SDK retries it after a network failure, which is safe because keeping a kept subscription changes nothing.
Also available in
nextmail.subscriptions.unsubscribe()
Unsubscribe from a sender
unsubscribe(id: string, body?: SubscriptionUnsubscribe, options?: RequestScope): Promise<UnsubscribeResultResource>Unsubscribes the way the sender asks for it: a one-click request to its unsubscribe address when it offers one, otherwise an unsubscribe email sent from the address the mail arrived at. A sender that only offers a page cannot be unsubscribed by a program, so method is link and url is the page a person has to open. bin also moves every conversation from the sender to the Bin, and archive archives them instead. bin wins when both are true.
A sender that gives no way to unsubscribe is a 422 unsubscribe_unsupported, and one whose one-click request failed with no address to write to is a 502 unsubscribe_refused. A subscription delivered to an address the key does not reach is a 404.
Parameters
idstringRequiredThe subscription, from
list.body.binbooleanAlso move every conversation from the sender to the Bin. Defaults to false.
body.archivebooleanAlso archive every conversation from the sender. Defaults to false.
options.signalAbortSignalCancels the request.
options.apiKeystringOverrides the client's API key for this call only.
Returns
UnsubscribeResultResource, { object: 'unsubscribe', subscriptionId, method, url, binned, archived }.
Example
const result = await nextmail.subscriptions.unsubscribe('sub_7d2c1f0a9b3e4c5d6e7f8a9b', { bin: true }) if (result.method === 'link') console.log('Open', result.url)Notes
The SDK does not retry it, because a second call can send a second unsubscribe email.
Also available in
nextmail.subscriptions.unsubscribeMany()
Unsubscribe from up to 100 senders in one call
unsubscribeMany(ids: Array<string>, body?: SubscriptionUnsubscribe, options?: RequestScope): Promise<SubscriptionBatchUnsubscribeResource>Unsubscribes from each subscription in ids the way unsubscribe does for one, as Unsubscribe on a selection of the Subscriptions page does, and reports the rest instead of failing. unsubscribed holds the ones done with a one-click request or an unsubscribe email.
A sender that only unsubscribes on its own page comes back in links with the url a person has to open, and stays active until somebody does. skipped holds the ones already unsubscribed (already_unsubscribed) or that give no way to unsubscribe (no_method), failed the ones whose sender did not accept it, and missing the ids that are unknown or delivered to an address the key does not reach.
archive also archives every conversation from the senders that were unsubscribed, and bin moves them to the Bin instead.
Parameters
idsArray<string>Required1 to 100 subscription ids from
list, for example the rows whosesuggestedis true. A repeated id counts once.body.archivebooleanAlso archive every conversation from the senders. Defaults to false.
body.binbooleanAlso move every conversation from the senders to the Bin. Defaults to false.
options.signalAbortSignalCancels the request.
options.apiKeystringOverrides the client's API key for this call only.
Returns
SubscriptionBatchUnsubscribeResource, { object: 'subscription_batch_unsubscribe', unsubscribed, links, skipped, failed, missing, binned, archived }. links holds { id, url } and skipped holds { id, reason }.
Example
const page = await nextmail.subscriptions.list({ suggested: true })const result = await nextmail.subscriptions.unsubscribeMany(page.data.map((row) => row.id), { archive: true }) console.log(`${result.unsubscribed.length} unsubscribed, ${result.archived} archived`) for (const step of result.links) console.log('Open', step.url)Notes
A partial result resolves rather than rejects, so read
links,skipped,failedandmissingto see what stayed.The SDK does not retry it, because a second call can send unsubscribe emails again.
Also available in
nextmail.subscriptions.unsubscribeDomain()
Unsubscribe from a whole domain
unsubscribeDomain(domain: string, body?: SubscriptionDomainUnsubscribe, options?: RequestScope): Promise<DomainUnsubscribeResultResource>Unsubscribes from every sender on a domain that can be unsubscribed without a person opening a page, with a one-click request or an unsubscribe email, as the domain view of the Subscriptions page does. unsubscribed counts the senders it worked for, skipped the senders that only offer a page and failed the ones that did not accept it.
Senders you kept with keep are left alone. bin also moves their conversations to the Bin, archive archives them instead, and address keeps it to the subscriptions delivered to one address. A key limited to particular addresses acts only on the subscriptions delivered to them.
Parameters
domainstringRequiredThe sender domain, from
listDomains.body.binbooleanAlso move the conversations to the Bin. Defaults to false.
body.archivebooleanAlso archive the conversations. Defaults to false.
body.addressstringOnly the subscriptions delivered to this address.
options.signalAbortSignalCancels the request.
options.apiKeystringOverrides the client's API key for this call only.
Returns
DomainUnsubscribeResultResource, { object: 'domain_unsubscribe', domain, unsubscribed, skipped, failed, binned, archived }.
Example
const result = await nextmail.subscriptions.unsubscribeDomain('news.acme.com') console.log(`${result.unsubscribed} unsubscribed, ${result.skipped} need a person`)Notes
The SDK does not retry it, because a second call can send unsubscribe emails again.
Also available in
- API
POST /subscriptions/domains/{domain}/unsubscribe- Python
subscriptions.unsubscribe_domain()- Ruby
subscriptions.unsubscribe_domain- PHP
subscriptions->unsubscribeDomain- Go
Subscriptions.UnsubscribeDomain- Java
subscriptions().unsubscribeDomain- C#
Subscriptions.UnsubscribeDomainAsync- CLI
openemail subscriptions unsubscribe-domain
nextmail.subscriptions.move()
Move what a sender sent
move(id: string, body: SubscriptionMove, options?: RequestScope): Promise<SubscriptionMoveResultResource>Moves every conversation from the sender to the archive, the Bin or a label, as the Subscriptions page does. destination is archive, bin or label, and label needs labelId, or the call is a 422 label_not_found.
With future, the default, a rule keeps doing it to new mail from the sender to that address, which also needs rules:write. ruleName names that rule. future: false drops a rule made that way before, when the key holds rules:write.
Parameters
idstringRequiredThe subscription, from
list.body.destinationSubscriptionDestinationRequiredarchive,binorlabel.body.labelIdstringThe label to file under, for
label.body.futurebooleanKeep doing it to new mail with a rule. Defaults to true.
body.ruleNamestringA name for that rule.
options.signalAbortSignalCancels the request.
options.apiKeystringOverrides the client's API key for this call only.
Returns
SubscriptionMoveResultResource, { object: 'subscription_move', subscriptionId, moved, ruleId }.
Example
const result = await nextmail.subscriptions.move('sub_7d2c1f0a9b3e4c5d6e7f8a9b', { destination: 'archive' }) console.log(result.moved, result.ruleId)Notes
The SDK retries it after a network failure, which is safe because moving the same mail again changes nothing and the rule is updated rather than added twice.
Also available in
nextmail.subscriptions.moveMany()
Move what up to 100 senders sent
moveMany(ids: Array<string>, body: SubscriptionMoveMany, options?: RequestScope): Promise<SubscriptionBatchMoveResource>Moves every conversation from each subscription in ids to the archive, the Bin or a label, the way move does for one, as Archive on a selection of the Subscriptions page does. destination is archive, bin or label, and label needs labelId, or the call is a 422 label_not_found.
With future, the default, a rule per sender keeps doing it to new mail, which also needs rules:write. moved counts the conversations moved across every sender, updated holds the subscriptions whose mail moved, failed the ones that could not be moved and missing the ids that are unknown or delivered to an address the key does not reach.
Parameters
idsArray<string>Required1 to 100 subscription ids from
list. A repeated id counts once.body.destinationSubscriptionDestinationRequiredarchive,binorlabel.body.labelIdstringThe label to file under, for
label.body.futurebooleanKeep doing it to new mail with a rule per sender. Defaults to true.
options.signalAbortSignalCancels the request.
options.apiKeystringOverrides the client's API key for this call only.
Returns
SubscriptionBatchMoveResource, { object: 'subscription_batch_move', moved, updated, failed, missing }.
Example
const result = await nextmail.subscriptions.moveMany(['sub_7d2c1f0a9b3e4c5d6e7f8a9b', 'sub_0c3e2a91d4b7f6058e1a2b3c'], { destination: 'archive', future: false }) console.log(`${result.moved} conversations archived`)Notes
The SDK retries it after a network failure, which is safe because moving the same mail again changes nothing and each rule is updated rather than added twice.