$client->subscriptions
이 네임스페이스의 모든 메서드: 시그니처, 매개변수, 반환값과 예시.
메서드
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
list( ?string $status = null, ?string $q = null, ?string $sort = null, ?int $limit = null, ?int $offset = null, ?string $address = null, ?string $apiKey = null,): arrayReturns 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 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.
status: is active, the default, or unsubscribed. q: searches the sender, and sort: is recent, most, 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.
매개변수
statusstringactiveorunsubscribed. Defaults toactive.qstringSearches the sender name and address.
sortstringrecent,most,unreadorname, also inOpenEmail\Constants\SubscriptionSorts. Defaults torecent.limitintRows per page, 1 to 200, defaulting to 50.
offsetintHow many rows to skip.
addressstringOnly the subscriptions delivered to this address.
apiKeystringOverrides the client's API key for this call only.
반환값
An array, not a Page, with object set to list, data, total, counts and hasMore, where counts holds how many are active and unsubscribed.
예시
use OpenEmail\Constants\SubscriptionSorts; $subscriptions = $client->subscriptions->list(sort: SubscriptionSorts::MOST, limit: 20); foreach ($subscriptions['data'] as $row) { echo $row['senderEmail'], ' ', $row['total'], ' messages, ', $row['unread'], ' unread, ', $row['method'], PHP_EOL;} echo $subscriptions['counts']['unsubscribed'], ' already unsubscribed', PHP_EOL;참고
Read only, so the SDK retries it after a network failure like any other read.
다른 사용처
- API
GET /subscriptions- TypeScript
subscriptions.list()- Python
subscriptions.list()- Ruby
subscriptions.list- CLI
openemail subscriptions list
subscriptions->listDomains
List subscriptions by domain
listDomains( ?string $status = null, ?string $q = null, ?string $sort = null, ?int $limit = null, ?int $offset = null, ?string $address = null, ?string $apiKey = null,): arrayReturns the same subscriptions as subscriptions->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 subscriptions->unsubscribeDomain acts on.
It takes the same filters as subscriptions->list.
매개변수
statusstringactiveorunsubscribed. Defaults toactive.qstringSearches the sender name and address.
sortstringrecent,most,unreadorname. Defaults torecent.limitintRows per page, 1 to 200, defaulting to 50.
offsetintHow many rows to skip.
addressstringOnly the subscriptions delivered to this address.
apiKeystringOverrides the client's API key for this call only.
반환값
An array, not a Page, with object set to list, data, total, counts and hasMore.
예시
$domains = $client->subscriptions->listDomains(sort: 'most'); foreach ($domains['data'] as $row) { echo $row['domain'], ': ', $row['senders'], ' senders, ', $row['unsubscribable'], ' can be unsubscribed here', PHP_EOL;}참고
Read only, so the SDK retries it after a network failure like any other read.
다른 사용처
subscriptions->unsubscribe
Unsubscribe from a sender
unsubscribe(string $id, ?array $body = null, ?string $apiKey = null): arrayUnsubscribes 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 set to true also moves every conversation from the sender to the Bin.
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.
매개변수
idstring필수The subscription, from
subscriptions->list.binboolAlso move every conversation from the sender to the Bin. Defaults to false.
apiKeystringOverrides the client's API key for this call only.
반환값
An array with object set to unsubscribe, subscriptionId, method, url and binned.
예시
$result = $client->subscriptions->unsubscribe('sub_7d2c1f0a9b3e4c5d6e7f8a9b', ['bin' => true]); if ($result['method'] === 'link') { echo 'Open ', $result['url'], ' to finish unsubscribing', PHP_EOL;} else { echo 'Unsubscribed by ', $result['method'], ', ', $result['binned'], ' conversations binned', PHP_EOL;}참고
The SDK does not retry it, because a second call can send a second unsubscribe email.
다른 사용처
subscriptions->unsubscribeDomain
Unsubscribe from a whole domain
unsubscribeDomain(string $domain, ?array $body = null, ?string $apiKey = null): arrayUnsubscribes 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.
bin set to true also moves their conversations to the Bin, 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.
매개변수
domainstring필수The sender domain, from
subscriptions->listDomains.binboolAlso move the conversations to the Bin. Defaults to false.
addressstringOnly the subscriptions delivered to this address.
apiKeystringOverrides the client's API key for this call only.
반환값
An array with object set to domain_unsubscribe, domain, unsubscribed, skipped, failed and binned.
예시
$result = $client->subscriptions->unsubscribeDomain('news.acme.com', ['address' => '[email protected]']); echo $result['unsubscribed'], ' unsubscribed, ', $result['skipped'], ' need a person, ', $result['failed'], ' failed', PHP_EOL;참고
The SDK does not retry it, because a second call can send unsubscribe emails again.
다른 사용처
subscriptions->move
Move what a sender sent
move(string $id, array $body, ?string $apiKey = null): arrayMoves 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.
매개변수
idstring필수The subscription, from
subscriptions->list.destinationstring필수archive,binorlabel, also inOpenEmail\Constants\SubscriptionDestinations.labelIdstringThe label to file under, for
label.futureboolKeep doing it to new mail with a rule. Defaults to true.
ruleNamestringA name for that rule.
apiKeystringOverrides the client's API key for this call only.
반환값
An array with object set to subscription_move, subscriptionId, moved and ruleId.
예시
use OpenEmail\Constants\SubscriptionDestinations; $result = $client->subscriptions->move('sub_7d2c1f0a9b3e4c5d6e7f8a9b', [ 'destination' => SubscriptionDestinations::LABEL, 'labelId' => 'newsletters', 'ruleName' => 'File Acme news',]); echo $result['moved'], ' conversations moved, rule ', $result['ruleId'] ?? 'none', PHP_EOL;참고
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.