---
title: "client.Subscriptions"
description: "Every method in this namespace: its signature, its parameters, what it returns and an example."
url: "https://nextmail.sh/docs/go/reference/subscriptions"
area: "Go"
category: "Reference"
---

# client.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.

### `Subscriptions.List`

List subscriptions

```go
List(ctx context.Context, opts ...nextmail.RequestOption) (nextmail.Object, error)
```

Returns 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. `nextmail.WithSuggested(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.

Scopes: `threads:read`.

**Parameters**

- `nextmail.WithStatus` (`...string`): `active`, `kept` or `unsubscribed`. Defaults to `active`.
- `nextmail.WithQ` (`string`): Searches the sender name and address.
- `nextmail.WithSort` (`string`): `recent`, `most`, `emails`, `read`, `unread` or `name`. Defaults to `recent`.
- `nextmail.WithSuggested` (`bool`): Only the senders worth unsubscribing from, the rows whose `suggested` is true.
- `nextmail.WithLimit` (`int`): Rows per page, 1 to 200, defaulting to 50.
- `nextmail.WithOffset` (`int`): How many rows to skip.
- `nextmail.WithAddress` (`string`): Only the subscriptions delivered to this address.
- `nextmail.WithAPIKey` (`string`): Overrides the client's API key for this call only.

**Returns**

The `nextmail.Object` with `object` set to `list`, `data`, `total`, `counts` and `hasMore`, where `counts` holds how many are `active`, `kept` and `unsubscribed`.

**Example**

```go
page, err := client.Subscriptions.List(ctx, nextmail.WithSort("emails"), nextmail.WithLimit(20))
if err != nil {
	return err
}

for _, row := range page.Objects("data") {
	fmt.Printf("%s %d %d%% read %t\n", row.String("senderEmail"), row.Int("total"), row.Int("readPercent"), row.Bool("suggested"))
}
```

**Notes**

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

Also available in: API [`GET /subscriptions`](https://nextmail.sh/docs/api/reference/subscriptions#get-subscriptions); TypeScript [`nextmail.subscriptions.list()`](https://nextmail.sh/docs/sdk/reference/subscriptions#list); Python [`subscriptions.list()`](https://nextmail.sh/docs/python/reference/subscriptions#list); Ruby [`subscriptions.list`](https://nextmail.sh/docs/ruby/reference/subscriptions#list); PHP [`subscriptions->list`](https://nextmail.sh/docs/php/reference/subscriptions#list); Java [`subscriptions().list`](https://nextmail.sh/docs/java/reference/subscriptions#list); C# [`Subscriptions.ListAsync`](https://nextmail.sh/docs/csharp/reference/subscriptions#list); CLI [`nextmail subscriptions list`](https://nextmail.sh/docs/cli/reference/subscriptions#subscriptions-list).

### `Subscriptions.ListDomains`

List subscriptions by domain

```go
ListDomains(ctx context.Context, opts ...nextmail.RequestOption) (nextmail.Object, error)
```

Returns 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 `nextmail.WithSuggested(true)` lists the domains of the suggested senders.

Scopes: `threads:read`.

**Parameters**

- `nextmail.WithStatus` (`...string`): `active`, `kept` or `unsubscribed`. Defaults to `active`.
- `nextmail.WithQ` (`string`): Searches the sender name and address.
- `nextmail.WithSort` (`string`): `recent`, `most`, `emails`, `read`, `unread` or `name`. Defaults to `recent`.
- `nextmail.WithSuggested` (`bool`): Only the senders worth unsubscribing from, the rows whose `suggested` is true.
- `nextmail.WithLimit` (`int`): Rows per page, 1 to 200, defaulting to 50.
- `nextmail.WithOffset` (`int`): How many rows to skip.
- `nextmail.WithAddress` (`string`): Only the subscriptions delivered to this address.
- `nextmail.WithAPIKey` (`string`): Overrides the client's API key for this call only.

**Returns**

The `nextmail.Object` with `object` set to `list`, `data`, `total`, `counts` and `hasMore`.

**Example**

```go
page, err := client.Subscriptions.ListDomains(ctx, nextmail.WithSort("most"))
if err != nil {
	return err
}

fmt.Println(page.String("object"))
```

**Notes**

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

Also available in: API [`GET /subscriptions/domains`](https://nextmail.sh/docs/api/reference/subscriptions#get-subscriptions-domains); TypeScript [`nextmail.subscriptions.listDomains()`](https://nextmail.sh/docs/sdk/reference/subscriptions#listDomains); Python [`subscriptions.list_domains()`](https://nextmail.sh/docs/python/reference/subscriptions#listDomains); Ruby [`subscriptions.list_domains`](https://nextmail.sh/docs/ruby/reference/subscriptions#listDomains); PHP [`subscriptions->listDomains`](https://nextmail.sh/docs/php/reference/subscriptions#listDomains); Java [`subscriptions().listDomains`](https://nextmail.sh/docs/java/reference/subscriptions#listDomains); C# [`Subscriptions.ListDomainsAsync`](https://nextmail.sh/docs/csharp/reference/subscriptions#listDomains); CLI [`nextmail subscriptions list-domains`](https://nextmail.sh/docs/cli/reference/subscriptions#subscriptions-list-domains).

### `Subscriptions.Keep`

Keep subscriptions you want

```go
Keep(ctx context.Context, ids []string, body nextmail.Body, opts ...nextmail.RequestOption) (nextmail.Object, error)
```

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`.

Scopes: `threads:write`.

**Parameters**

- `ids` (`[]string`, required): 1 to 100 subscription ids from `List`. A repeated id counts once.
- `kept` (`bool`): `true` keeps them, `false` puts them back to active. Defaults to true.
- `nextmail.WithAPIKey` (`string`): Overrides the client's API key for this call only.

**Returns**

The `nextmail.Object` with `object` set to `subscription_batch_keep`, `kept`, `updated`, `skipped` and `missing`, each list holding subscription ids.

**Example**

```go
result, err := client.Subscriptions.Keep(ctx, []string{"sub_7d2c1f0a9b3e4c5d6e7f8a9b"}, nil)
if err != nil {
	return err
}

fmt.Printf("%d kept\n", len(result.Strings("updated")))
```

**Notes**

- The SDK retries it after a network failure, which is safe because keeping a kept subscription changes nothing.

Also available in: API [`POST /subscriptions/batch-keep`](https://nextmail.sh/docs/api/reference/subscriptions#post-subscriptions-batch-keep); TypeScript [`nextmail.subscriptions.keep()`](https://nextmail.sh/docs/sdk/reference/subscriptions#keep); Python [`subscriptions.keep()`](https://nextmail.sh/docs/python/reference/subscriptions#keep); Ruby [`subscriptions.keep`](https://nextmail.sh/docs/ruby/reference/subscriptions#keep); PHP [`subscriptions->keep`](https://nextmail.sh/docs/php/reference/subscriptions#keep); Java [`subscriptions().keep`](https://nextmail.sh/docs/java/reference/subscriptions#keep); C# [`Subscriptions.KeepAsync`](https://nextmail.sh/docs/csharp/reference/subscriptions#keep); CLI [`nextmail subscriptions keep`](https://nextmail.sh/docs/cli/reference/subscriptions#subscriptions-keep).

### `Subscriptions.Unsubscribe`

Unsubscribe from a sender

```go
Unsubscribe(ctx context.Context, id string, body nextmail.Body, opts ...nextmail.RequestOption) (nextmail.Object, error)
```

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.

Scopes: `threads:write`.

**Parameters**

- `id` (`string`, required): The subscription, from `List`.
- `bin` (`bool`): Also move every conversation from the sender to the Bin. Defaults to false.
- `archive` (`bool`): Also archive every conversation from the sender. Defaults to false.
- `nextmail.WithAPIKey` (`string`): Overrides the client's API key for this call only.

**Returns**

The `nextmail.Object` with `object` set to `unsubscribe`, `subscriptionId`, `method`, `url`, `binned` and `archived`.

**Example**

```go
result, err := client.Subscriptions.Unsubscribe(ctx, "sub_7d2c1f0a9b3e4c5d6e7f8a9b", nextmail.Body{"bin": true})
if err != nil {
	return err
}

fmt.Println(result.String("method"), result.String("url"))
```

**Notes**

- The SDK does not retry it, because a second call can send a second unsubscribe email.

Also available in: API [`POST /subscriptions/{id}/unsubscribe`](https://nextmail.sh/docs/api/reference/subscriptions#post-subscriptions-id-unsubscribe); TypeScript [`nextmail.subscriptions.unsubscribe()`](https://nextmail.sh/docs/sdk/reference/subscriptions#unsubscribe); Python [`subscriptions.unsubscribe()`](https://nextmail.sh/docs/python/reference/subscriptions#unsubscribe); Ruby [`subscriptions.unsubscribe`](https://nextmail.sh/docs/ruby/reference/subscriptions#unsubscribe); PHP [`subscriptions->unsubscribe`](https://nextmail.sh/docs/php/reference/subscriptions#unsubscribe); Java [`subscriptions().unsubscribe`](https://nextmail.sh/docs/java/reference/subscriptions#unsubscribe); C# [`Subscriptions.UnsubscribeAsync`](https://nextmail.sh/docs/csharp/reference/subscriptions#unsubscribe); CLI [`nextmail subscriptions unsubscribe`](https://nextmail.sh/docs/cli/reference/subscriptions#subscriptions-unsubscribe).

### `Subscriptions.UnsubscribeMany`

Unsubscribe from up to 100 senders in one call

```go
UnsubscribeMany(ctx context.Context, ids []string, body nextmail.Body, opts ...nextmail.RequestOption) (nextmail.Object, error)
```

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.

Scopes: `threads:write`.

**Parameters**

- `ids` (`[]string`, required): 1 to 100 subscription ids from `List`, for example the rows whose `suggested` is true. A repeated id counts once.
- `archive` (`bool`): Also archive every conversation from the senders. Defaults to false.
- `bin` (`bool`): Also move every conversation from the senders to the Bin. Defaults to false.
- `nextmail.WithAPIKey` (`string`): Overrides the client's API key for this call only.

**Returns**

The `nextmail.Object` with `object` set to `subscription_batch_unsubscribe`, `unsubscribed`, `links`, `skipped`, `failed`, `missing`, `binned` and `archived`. Each entry of `links` is a map with `id` and `url`, and each entry of `skipped` a map with `id` and `reason`.

**Example**

```go
page, err := client.Subscriptions.List(ctx, nextmail.WithSuggested(true))
if err != nil {
	return err
}

ids := []string{}

for _, row := range page.Objects("data") {
	ids = append(ids, row.String("id"))
}

result, err := client.Subscriptions.UnsubscribeMany(ctx, ids, nextmail.Body{"archive": true})
if err != nil {
	return err
}

fmt.Printf("%d unsubscribed, %d archived\n", len(result.Strings("unsubscribed")), result.Int("archived"))

for _, step := range result.Objects("links") {
	fmt.Println("Open", step.String("url"))
}
```

**Notes**

- A partial result is returned rather than an error, so read `links`, `skipped`, `failed` and `missing` to see what stayed.
- The SDK does not retry it, because a second call can send unsubscribe emails again.

Also available in: API [`POST /subscriptions/batch-unsubscribe`](https://nextmail.sh/docs/api/reference/subscriptions#post-subscriptions-batch-unsubscribe); TypeScript [`nextmail.subscriptions.unsubscribeMany()`](https://nextmail.sh/docs/sdk/reference/subscriptions#unsubscribeMany); Python [`subscriptions.unsubscribe_many()`](https://nextmail.sh/docs/python/reference/subscriptions#unsubscribeMany); Ruby [`subscriptions.unsubscribe_many`](https://nextmail.sh/docs/ruby/reference/subscriptions#unsubscribeMany); PHP [`subscriptions->unsubscribeMany`](https://nextmail.sh/docs/php/reference/subscriptions#unsubscribeMany); Java [`subscriptions().unsubscribeMany`](https://nextmail.sh/docs/java/reference/subscriptions#unsubscribeMany); C# [`Subscriptions.UnsubscribeManyAsync`](https://nextmail.sh/docs/csharp/reference/subscriptions#unsubscribeMany); CLI [`nextmail subscriptions unsubscribe-many`](https://nextmail.sh/docs/cli/reference/subscriptions#subscriptions-unsubscribe-many).

### `Subscriptions.UnsubscribeDomain`

Unsubscribe from a whole domain

```go
UnsubscribeDomain(ctx context.Context, domain string, body nextmail.Body, opts ...nextmail.RequestOption) (nextmail.Object, error)
```

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.

Scopes: `threads:write`.

**Parameters**

- `domain` (`string`, required): The sender domain, from `ListDomains`.
- `bin` (`bool`): Also move the conversations to the Bin. Defaults to false.
- `archive` (`bool`): Also archive the conversations. Defaults to false.
- `address` (`string`): Only the subscriptions delivered to this address.
- `nextmail.WithAPIKey` (`string`): Overrides the client's API key for this call only.

**Returns**

The `nextmail.Object` with `object` set to `domain_unsubscribe`, `domain`, `unsubscribed`, `skipped`, `failed`, `binned` and `archived`.

**Example**

```go
result, err := client.Subscriptions.UnsubscribeDomain(ctx, "news.acme.com", nil)
if err != nil {
	return err
}

fmt.Println(result.Int("unsubscribed"), result.Int("skipped"))
```

**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`](https://nextmail.sh/docs/api/reference/subscriptions#post-subscriptions-domains-domain-unsubscribe); TypeScript [`nextmail.subscriptions.unsubscribeDomain()`](https://nextmail.sh/docs/sdk/reference/subscriptions#unsubscribeDomain); Python [`subscriptions.unsubscribe_domain()`](https://nextmail.sh/docs/python/reference/subscriptions#unsubscribeDomain); Ruby [`subscriptions.unsubscribe_domain`](https://nextmail.sh/docs/ruby/reference/subscriptions#unsubscribeDomain); PHP [`subscriptions->unsubscribeDomain`](https://nextmail.sh/docs/php/reference/subscriptions#unsubscribeDomain); Java [`subscriptions().unsubscribeDomain`](https://nextmail.sh/docs/java/reference/subscriptions#unsubscribeDomain); C# [`Subscriptions.UnsubscribeDomainAsync`](https://nextmail.sh/docs/csharp/reference/subscriptions#unsubscribeDomain); CLI [`nextmail subscriptions unsubscribe-domain`](https://nextmail.sh/docs/cli/reference/subscriptions#subscriptions-unsubscribe-domain).

### `Subscriptions.Move`

Move what a sender sent

```go
Move(ctx context.Context, id string, body nextmail.Body, opts ...nextmail.RequestOption) (nextmail.Object, error)
```

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`.

Scopes: `threads:write`.

**Parameters**

- `id` (`string`, required): The subscription, from `List`.
- `destination` (`string`, required): `archive`, `bin` or `label`.
- `labelId` (`string`): The label to file under, for `label`.
- `future` (`bool`): Keep doing it to new mail with a rule. Defaults to true.
- `ruleName` (`string`): A name for that rule.
- `nextmail.WithAPIKey` (`string`): Overrides the client's API key for this call only.

**Returns**

The `nextmail.Object` with `object` set to `subscription_move`, `subscriptionId`, `moved` and `ruleId`.

**Example**

```go
result, err := client.Subscriptions.Move(ctx, "sub_7d2c1f0a9b3e4c5d6e7f8a9b", nextmail.Body{"destination": "archive"})
if err != nil {
	return err
}

fmt.Println(result.Int("moved"), result.String("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: API [`POST /subscriptions/{id}/move`](https://nextmail.sh/docs/api/reference/subscriptions#post-subscriptions-id-move); TypeScript [`nextmail.subscriptions.move()`](https://nextmail.sh/docs/sdk/reference/subscriptions#move); Python [`subscriptions.move()`](https://nextmail.sh/docs/python/reference/subscriptions#move); Ruby [`subscriptions.move`](https://nextmail.sh/docs/ruby/reference/subscriptions#move); PHP [`subscriptions->move`](https://nextmail.sh/docs/php/reference/subscriptions#move); Java [`subscriptions().move`](https://nextmail.sh/docs/java/reference/subscriptions#move); C# [`Subscriptions.MoveAsync`](https://nextmail.sh/docs/csharp/reference/subscriptions#move); CLI [`nextmail subscriptions move`](https://nextmail.sh/docs/cli/reference/subscriptions#subscriptions-move).

### `Subscriptions.MoveMany`

Move what up to 100 senders sent

```go
MoveMany(ctx context.Context, ids []string, body nextmail.Body, opts ...nextmail.RequestOption) (nextmail.Object, error)
```

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.

Scopes: `threads:write`.

**Parameters**

- `ids` (`[]string`, required): 1 to 100 subscription ids from `List`. A repeated id counts once.
- `destination` (`string`, required): `archive`, `bin` or `label`.
- `labelId` (`string`): The label to file under, for `label`.
- `future` (`bool`): Keep doing it to new mail with a rule per sender. Defaults to true.
- `nextmail.WithAPIKey` (`string`): Overrides the client's API key for this call only.

**Returns**

The `nextmail.Object` with `object` set to `subscription_batch_move`, `moved`, `updated`, `failed` and `missing`.

**Example**

```go
result, err := client.Subscriptions.MoveMany(
	ctx,
	[]string{"sub_7d2c1f0a9b3e4c5d6e7f8a9b", "sub_0c3e2a91d4b7f6058e1a2b3c"},
	nextmail.Body{"destination": "archive", "future": false},
)
if err != nil {
	return err
}

fmt.Printf("%d conversations archived\n", result.Int("moved"))
```

**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.

Also available in: API [`POST /subscriptions/batch-move`](https://nextmail.sh/docs/api/reference/subscriptions#post-subscriptions-batch-move); TypeScript [`nextmail.subscriptions.moveMany()`](https://nextmail.sh/docs/sdk/reference/subscriptions#moveMany); Python [`subscriptions.move_many()`](https://nextmail.sh/docs/python/reference/subscriptions#moveMany); Ruby [`subscriptions.move_many`](https://nextmail.sh/docs/ruby/reference/subscriptions#moveMany); PHP [`subscriptions->moveMany`](https://nextmail.sh/docs/php/reference/subscriptions#moveMany); Java [`subscriptions().moveMany`](https://nextmail.sh/docs/java/reference/subscriptions#moveMany); C# [`Subscriptions.MoveManyAsync`](https://nextmail.sh/docs/csharp/reference/subscriptions#moveMany); CLI [`nextmail subscriptions move-many`](https://nextmail.sh/docs/cli/reference/subscriptions#subscriptions-move-many).
