Skip to the documentation
PHP

$client->webhooks

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

Methods

Endpoints that receive signed mailbox events: register, change, test and remove them, rotate their secrets, read and replay their delivery log, and follow their audit log and delivery numbers. Nextmail::verifyWebhookSignature checks each delivery.

webhooks->list

List the webhook endpoints in the workspace

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

Returns one page of the webhook endpoints registered on the key's workspace, newest first. webhooks->listAll collects every page and webhooks->iterate walks them lazily.

Signing secrets are never part of a read. Only webhooks->create and webhooks->rotateSecret return secret, so a lost secret cannot be recovered from here. An endpoint that names no events, such as one created without eventTypes, receives the default email.* set and reports eventTypes as ['*'] rather than an empty array.

Read enabled, disabledReason and consecutiveFailures as the health summary. An endpoint the server switched off after 100 consecutive failed deliveries shows enabled false with disabledAt and a reason, while one you disabled yourself through webhooks->update has both of those null.

Parameters

qstring

Narrows to endpoints whose URL, description, id, events, or one of the addresses and domains they name matches, up to 200 characters. Every word has to appear in one of them, ignoring case and accents, and when nothing matches exactly the search allows for a typo instead.

limitint

Page size, from 1 to 100. The server defaults to 25.

cursorstring

The nextCursor of the previous page. Leave it out for the first page.

apiKeystring

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

Returns

A Page of endpoint arrays, with items, hasMore and nextCursor. Each item has id, url, description, eventTypes, enabled, disabledAt, disabledReason, consecutiveFailures, addressAllowlist, domainAllowlist, includeContent, includeRaw, retryPolicy, lastDeliveryAt, previousSecretExpiresAt and createdAt.

Example

$page = $client->webhooks->list(); foreach ($page as $endpoint) {    $health = $endpoint['enabled']        ? $endpoint['consecutiveFailures'] . ' failures in a row'        : 'off, ' . ($endpoint['disabledReason'] ?? 'switched off by hand');     echo $endpoint['url'], ': ', implode(', ', $endpoint['eventTypes']), ', ', $health, PHP_EOL;}

Notes

  • A narrowed key reads every endpoint, and may write one whose own addressAllowlist and domainAllowlist sit inside what the key holds. A write that would take an endpoint wider than the key is 422 capability_unsupported on addressAllowlist.

  • lastDeliveryAt moves on failed attempts as well as successful ones, so it shows the endpoint is being called, not that it is healthy.

  • The cursor is opaque and holds where the last row sat in this order, so a row deleted or edited between pages never breaks the walk: the next page starts at the first row that sorts after it. A cursor this list did not hand out is a 400 invalid_cursor.

Also available in

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

webhooks->listAll

Collect every webhook endpoint into one array

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

Walks every page of webhooks->list and returns all webhook endpoints in one array, newest first. One request per page.

Parameters

qstring

Narrows to endpoints whose URL, description, id, events, or one of the addresses and domains they name matches, up to 200 characters. Every word has to appear in one of them, ignoring case and accents, and when nothing matches exactly the search allows for a typo instead.

limitint

Page size for each request, from 1 to 100. The server defaults to 25.

cursorstring

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

apiKeystring

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

Returns

A list of endpoint arrays holding every webhook endpoint.

Example

$endpoints = $client->webhooks->listAll(); $switchedOff = array_filter($endpoints, static fn(array $endpoint): bool => $endpoint['disabledAt'] !== null); echo count($endpoints), ' endpoints, ', count($switchedOff), ' switched off by the server', PHP_EOL;

Notes

  • If any page fails, the exception is thrown and the webhook endpoints already fetched are discarded.

Also available in

API
GET /webhooks
TypeScript
webhooks.listAll()
Python
webhooks.list_all()
Ruby
webhooks.list_all
Go
Webhooks.ListAll
Java
webhooks().listAll
C#
Webhooks.ListAllAsync

webhooks->iterate

Stream the webhook endpoints one at a time

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

Returns a Generator that yields webhook endpoints one at a time, newest first, and requests the next page only once the current one is used up. Nothing is fetched until the loop starts, and breaking out of the foreach stops the requests.

Parameters

qstring

Narrows to endpoints whose URL, description, id, events, or one of the addresses and domains they name matches, up to 200 characters. Every word has to appear in one of them, ignoring case and accents, and when nothing matches exactly the search allows for a typo instead. Sent with every page.

limitint

Page size for each request, from 1 to 100. The server defaults to 25.

cursorstring

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

apiKeystring

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

Returns

A Generator that yields one endpoint array per step.

Example

foreach ($client->webhooks->iterate() as $endpoint) {    if (!$endpoint['enabled'] && $endpoint['disabledAt'] !== null) {        echo $endpoint['url'], ' was switched off: ', $endpoint['disabledReason'], PHP_EOL;    }}

Notes

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

Also available in

API
GET /webhooks
TypeScript
webhooks.iterate()
Python
webhooks.iterate()
Ruby
webhooks.iterate
Go
Webhooks.Iterate
Java
webhooks().iterate
C#
Webhooks.IterateAsync

webhooks->get

Read one webhook endpoint by id

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

Returns a single endpoint with its URL, subscription list, enabled state and delivery health. The signing secret is never part of a read. It appears only in the responses of webhooks->create and webhooks->rotateSecret, and a lost one is replaced with webhooks->rotateSecret rather than read back.

An id from another workspace answers exactly like one that never existed, with 404 resource_not_found, so a 404 does not tell you whether the endpoint was deleted or was never yours.

consecutiveFailures resets to 0 on any successful delivery and when webhooks->update sets enabled to true. When it reaches 100 the server disables the endpoint, fills in disabledAt and disabledReason, and emails the workspace owner and every member whose role can read webhooks.

Parameters

idstringRequired

Endpoint id, whe_ followed by 24 hex characters.

apiKeystring

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

Returns

An array with id, url, description, eventTypes, enabled, disabledAt, disabledReason, consecutiveFailures, addressAllowlist, domainAllowlist, includeContent, includeRaw, retryPolicy, lastDeliveryAt, previousSecretExpiresAt and createdAt. No secret.

Example

$endpoint = $client->webhooks->get('whe_3f9c2a7b1e4d8f60a5c7b92d'); echo $endpoint['url'], $endpoint['enabled'] ? ' is on' : ' is off', ', last called ', $endpoint['lastDeliveryAt'] ?? 'never', PHP_EOL; if ($endpoint['eventTypes'] === ['*']) {    echo 'It receives the default email events', PHP_EOL;}

Notes

  • eventTypes of ['*'] means the endpoint named none, so it receives the default email.* set. email.replied, domain.*, suppression.*, file.*, form.*, automation.*, contact.*, sending.*, connector.*, task.*, approval.*, booking.*, broadcast.* and address.* sit outside that set and have to be named explicitly. automation.webhook and email.routed are never named: an automation step, an address or a route sends them to the endpoints it names, whatever eventTypes holds.

  • A GET is retried automatically on network failure and on 408, 429, 500, 502, 503 and 504 responses, up to the client's maxRetries.

Also available in

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

webhooks->create

Register an HTTPS endpoint for mailbox events

Scopeswebhooks:write
Signature
create(array $body, ?string $apiKey = null): array

Registers a receiver URL and subscribes it to events on the key's workspace. The endpoint starts enabled, so the next matching event is delivered to it straight away. Leave eventTypes out, or pass an empty array, and the endpoint receives the default set, which is the email.* events other than email.replied and email.routed. Every family outside it has to be named: email.replied, domain.*, suppression.*, file.*, form.*, automation.*, contact.*, sending.*, connector.*, task.*, approval.*, booking.*, broadcast.* and address.*. Reads report an unnamed subscription as ['*'].

By default an endpoint hears about every address the workspace owns. addressAllowlist and domainAllowlist narrow it, exactly as the same two lists narrow an API key: name whole domains, single addresses, or both. An event reaches the endpoint when the address or domain it concerns is covered, and address.* follows the address it names, as the email.* events do. Events that name no address at all, such as suppression.removed, reach every endpoint whatever its lists say. form.*, automation.*, contact.*, sending.*, connector.*, task.*, approval.*, booking.* and broadcast.* are the exception: sign-ups, automations, contacts, the sending lanes, connectors, tasks, booking pages and broadcasts belong to the whole workspace, so an endpoint limited to some addresses or domains never receives them. automation.webhook and email.routed are the two events no endpoint names. A webhook step of an automation sends automation.webhook only to the endpoint the step names, and an address or route that hands its mail to a webhook sends email.routed only to the endpoint it names in webhookId and to the taps of the address, whatever events those endpoints list and whatever their allowlists hold.

This response is the only place the full secret ever appears. Every later read omits it, so store it before doing anything else, and if it is lost call webhooks->rotateSecret. The secret is whsec_ followed by 43 base64url characters, and the HMAC key is the whole string including the prefix, so pass it to Nextmail::verifyWebhookSignature exactly as returned.

url must be https. localhost, hosts ending .localhost, .internal or .local, and IP literals in loopback, private, link local, carrier grade NAT, multicast or unique local ranges are refused with 422 invalid_webhook_url. The host is resolved again on every delivery, and an attempt to a name that resolves into one of those ranges is recorded as failed without being sent. Deliveries never follow redirects, so register the final address.

Parameters

urlstringRequired

The https receiver URL. Another scheme or a blocked host is 422 invalid_webhook_url. Stored in normalised form, so the url read back can differ cosmetically.

eventTypesstring[]

Events to subscribe to, also in Nextmail\Constants\WebhookEvents. Omit it, or send [], for the default email.* set: email.received, email.sent, email.failed, email.cancelled, email.scheduled, email.queued, email.delivered, email.delivery_delayed, email.bounced, email.complained, email.suppressed, email.opened, email.clicked and email.downloaded. email.replied, domain.verified, domain.sending_changed, domain.deleted, domain.access_granted, domain.access_revoked, suppression.added, suppression.removed, file.uploaded, file.deleted, form.submitted, form.confirmed, automation.entered, automation.exited, automation.paused, automation.resumed, contact.created, contact.updated, contact.deleted, contact.unsubscribed, contact.resubscribed, sending.paused, sending.resumed, connector.connected, connector.disconnected, connector.needs_attention, task.run.completed, task.run.failed, task.run.cancelled, approval.requested, booking.created, booking.confirmed, booking.rescheduled, booking.cancelled, broadcast.sending, broadcast.sent, broadcast.failed, broadcast.cancelled, address.expired, address.access_granted and address.access_revoked are outside that set and have to be named. automation.webhook and email.routed are never named here: a webhook step sends the first to the endpoint the step names, and an address or route sends the second to the endpoint it names in webhookId and to the taps of the address.

descriptionstring

Free text note, at most 200 characters.

addressAllowliststring[]

Single addresses this endpoint hears about. An event is delivered when the address it concerns is on this list, or when its domain is in domainAllowlist. Leave both empty and the endpoint hears about every address the workspace owns. At most 50, and an address this workspace does not own is 422 invalid_parameter.

domainAllowliststring[]

Whole domains this endpoint hears about, including addresses added to them later. A domain also carries its own domain.* events. At most 25. An address whose domain is already listed here is dropped from addressAllowlist when the endpoint is saved, so the two lists never overlap.

includeRawbool

True gives every email.received event this endpoint gets a link to the message source, as data.raw with url, size, source and expiresAt: the bytes exactly as they arrived when the address keeps originals, and otherwise the message rebuilt the way a mail app downloads it. The link works for an hour from each attempt without a key. Turning it on needs threads:read as well as webhooks:write. Defaults to false.

retryPolicystring

standard, the default, tries a failed delivery up to 8 times over about 27 and a half hours. extended tries it up to 16 times over about 3 days: as it happens, then after 1 minute, then after twice the last wait each time until the wait reaches 12 hours, then every 12 hours. Both are in Nextmail\Constants\WebhookRetryPolicies. The policy is read at every attempt, so a change also applies to events already waiting for a retry.

includeContentbool

True puts the message itself into every email.received event this endpoint gets, as data.content: the text, the HTML up to 512 KiB, and each attachment with a link that downloads it for an hour without a key. Turning it on needs threads:read as well as webhooks:write. Defaults to false.

apiKeystring

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

Returns

An array for the endpoint plus the plaintext secret: id, url, description, eventTypes, enabled, disabledAt, disabledReason, consecutiveFailures, addressAllowlist, domainAllowlist, includeContent, includeRaw, retryPolicy, lastDeliveryAt, createdAt and secret.

Example

use Nextmail\Constants\WebhookEvents; $endpoint = $client->webhooks->create([    'url' => 'https://hooks.acme.com/nextmail',    'eventTypes' => [WebhookEvents::EMAIL_BOUNCED, WebhookEvents::EMAIL_COMPLAINED, WebhookEvents::EMAIL_REPLIED],    'description' => 'Bounces, complaints and replies',    'domainAllowlist' => ['acme.com'],]); file_put_contents('.webhook-secret', $endpoint['secret']); echo 'Created ', $endpoint['id'], ' for ', implode(', ', $endpoint['eventTypes']), PHP_EOL;

Notes

  • Verify each delivery with Nextmail::verifyWebhookSignature($payload, $headers, $secret), passing the raw request body, such as file_get_contents('php://input'), and the request headers as an array, $_SERVER or a PSR-7 request. It checks the X-Webhook-Signature HMAC-SHA256 over the timestamp, a dot and the raw body in constant time, rejects a timestamp more than 300 seconds off, throws a WebhookSignatureException on failure and returns the event as an array with id, type, createdAt and data.

  • Each attempt is one POST with a 5 second timeout. A failure worth repeating (no answer, 408, 425, 429 or a 5xx) is tried again after 1 minute, 5 minutes, 30 minutes, 2 hours, 5 hours, 10 hours and 10 hours, up to 8 attempts over about 27 and a half hours on the standard retry policy and up to 16 over about 3 days on extended, each wait varied by up to 10% and stretched when your server's Retry-After asks for longer, up to 6 hours. A 410 Gone switches the endpoint off. webhooks->listDeliveries shows every attempt with its number. An event whose last attempt fails is kept as a dead letter for 30 days, which webhooks->listDeadLetters reads and webhooks->replayDeadLetters sends again once your receiver is fixed.

  • A workspace holds 10 endpoints by default, and support can raise that for a workspace that needs more. The next one past the limit is 422 workspace_limit_reached. A narrowed key may create an endpoint, but only one whose own lists sit inside what the key holds. Anything wider is 422 capability_unsupported on addressAllowlist.

  • Not retried automatically, so a network failure can leave an endpoint created with a secret you never saw. Check webhooks->list before creating it again.

Also available in

API
POST /webhooks
TypeScript
webhooks.create()
Python
webhooks.create()
Ruby
webhooks.create
Go
Webhooks.Create
Java
webhooks().create
C#
Webhooks.CreateAsync
CLI
nextmail webhooks create

webhooks->update

Change an endpoint URL, events or enabled state

Scopeswebhooks:write
Signature
update(string $id, array $patch, ?string $apiKey = null): array

Patches the URL, subscription list, description, enabled flag, message content and source settings or retry policy of one endpoint. Every field is optional, and an empty patch is accepted and changes nothing you can read back. A new url goes through the same https and host checks as webhooks->create, and 'description' => null clears the note.

eventTypes replaces the subscription set wholesale, so send the complete list you want rather than a delta. An empty array does not unsubscribe: it puts the endpoint back on the default email.* set. To stop deliveries, set enabled to false instead. As with webhooks->create, email.replied and every family outside that set, address.* included, have to be named, while automation.webhook and email.routed are never named: an automation step, an address or a route sends them to the endpoints it names.

addressAllowlist and domainAllowlist replace the endpoint's scope the same way, wholesale rather than as a delta. Send both empty to widen it back to every address the workspace owns. Each list is checked against the domains and addresses this workspace actually owns, and an unknown one is 422 invalid_parameter.

Writing enabled clears disabledAt and disabledReason either way, so an endpoint you switch off yourself reports both as null. Setting it back to true also resets consecutiveFailures to 0, which is how an endpoint the server disabled after 100 failures is brought back. Events that fire while an endpoint is disabled are never delivered to it later, but the events that failed before it was switched off are kept as dead letters, and webhooks->replayDeadLetters sends them again once it is back on.

Parameters

idstringRequired

Endpoint id, whe_ followed by 24 hex characters.

urlstring

Replacement https URL, checked against the same host rules as webhooks->create.

eventTypesstring[]

Complete replacement subscription set. [] means the default email.* set.

addressAllowliststring[]

Complete replacement list of single addresses this endpoint hears about. At most 50. Send [] on both lists to hear about every address again.

domainAllowliststring[]

Complete replacement list of whole domains this endpoint hears about, including addresses added to them later. At most 25.

includeContentbool

True puts the message itself into every email.received event this endpoint gets, as data.content: the text, the HTML up to 512 KiB, and each attachment with a link that downloads it for an hour without a key. Turning it on needs threads:read as well as webhooks:write. Leaving the field out leaves it alone.

includeRawbool

True gives every email.received event this endpoint gets a link to the message source, as data.raw with url, size, source and expiresAt: the bytes exactly as they arrived when the address keeps originals, and otherwise the message rebuilt the way a mail app downloads it. The link works for an hour from each attempt without a key. Turning it on needs threads:read as well as webhooks:write. Leaving the field out leaves it alone.

retryPolicystring

standard, the default, tries a failed delivery up to 8 times over about 27 and a half hours. extended tries it up to 16 times over about 3 days: as it happens, then after 1 minute, then after twice the last wait each time until the wait reaches 12 hours, then every 12 hours. Both are in Nextmail\Constants\WebhookRetryPolicies. The policy is read at every attempt, so a change also applies to events already waiting for a retry.

descriptionstring|null

Replacement note of at most 200 characters, or null to clear it.

enabledbool

False stops deliveries. True resumes them and resets consecutiveFailures.

apiKeystring

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

Returns

An array for the endpoint as saved. The signing secret is untouched and not included.

Example

use Nextmail\Constants\WebhookEvents; $endpoint = $client->webhooks->update('whe_3f9c2a7b1e4d8f60a5c7b92d', [    'url' => 'https://hooks.acme.com/nextmail/v2',    'eventTypes' => [WebhookEvents::EMAIL_BOUNCED, WebhookEvents::EMAIL_COMPLAINED],    'enabled' => true,]); echo $endpoint['url'], ' now hears ', implode(', ', $endpoint['eventTypes']), PHP_EOL;

Notes

  • Read the current eventTypes first if you mean to add one, since a partial list silently unsubscribes the rest. The same applies to the two allowlists. Do not send back ['*'] as read: it is a 422 invalid_parameter, and [] is how to ask for the default set.

  • This route never touches the signing secret. Use webhooks->rotateSecret for that.

  • Retried automatically on network failure and retryable statuses, since the same patch applied twice lands on the same row.

Also available in

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

webhooks->delete

Delete an endpoint and its delivery log

Scopeswebhooks:write
Signature
delete(string $id, ?string $apiKey = null): array

Removes the endpoint for good. Deliveries stop immediately, the signing secret is gone, and the delivery log for the endpoint is deleted with it, so read it with webhooks->listAllDeliveries first if you need it for an audit trail.

There is no undo and no soft delete. If the aim is only to pause deliveries, call webhooks->update with ['enabled' => false] and keep the endpoint, its secret and its log.

The response is a tombstone rather than an empty body, so a log line can name what went. Deleting frees a slot against the workspace's endpoint limit straight away.

Parameters

idstringRequired

Endpoint id, whe_ followed by 24 hex characters.

apiKeystring

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

Returns

An array with object set to webhook, the id and deleted set to true.

Example

$log = $client->webhooks->listAllDeliveries('whe_3f9c2a7b1e4d8f60a5c7b92d', limit: 100); file_put_contents('webhook-log.json', json_encode($log, JSON_PRETTY_PRINT)); $deleted = $client->webhooks->delete('whe_3f9c2a7b1e4d8f60a5c7b92d'); echo 'Deleted ', $deleted['id'], ' after saving ', count($log), ' deliveries', PHP_EOL;

Notes

  • Not idempotent: a second call on the same id is 404 resource_not_found, and the SDK does not retry it after a network failure.

  • A narrowed key may delete only an endpoint whose own allowlists sit inside what the key holds. Any other is 422 capability_unsupported on addressAllowlist.

Also available in

API
DELETE /webhooks/{id}
TypeScript
webhooks.delete()
Python
webhooks.delete()
Ruby
webhooks.delete
Go
Webhooks.Delete
Java
webhooks().delete
C#
Webhooks.DeleteAsync
CLI
nextmail webhooks delete

webhooks->rotateSecret

Issue a new signing secret for an endpoint

Scopeswebhooks:write
Signature
rotateSecret(string $id, ?string $apiKey = null): array

Generates a new signing secret and returns the endpoint plus the new plaintext secret. As with webhooks->create, this response is the only place that secret appears, so store it before anything else.

The old secret keeps working for 24 hours. Until then every delivery carries two v1 signatures in X-Webhook-Signature, one made with each secret, and Nextmail::verifyWebhookSignature passes when either matches, so a receiver that still holds the old secret keeps verifying while you give it the new one. previousSecretExpiresAt on the endpoint says when the old secret stops signing. Rotating again within those 24 hours keeps every secret retired in the window signing until its own 24 hours are up.

Give the receiver the returned secret within the day, then call webhooks->test to confirm it verifies.

Parameters

idstringRequired

Endpoint id, whe_ followed by 24 hex characters.

apiKeystring

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

Returns

An array for the full endpoint plus the new secret, formatted whsec_ followed by 43 base64url characters. previousSecretExpiresAt is when the old secret stops signing.

Example

$rotated = $client->webhooks->rotateSecret('whe_3f9c2a7b1e4d8f60a5c7b92d'); file_put_contents('.webhook-secret', $rotated['secret']); $check = $client->webhooks->test($rotated['id']); echo 'A test signed with the new secret: ', $check['delivery']['status'] ?? 'not recorded', PHP_EOL;

Notes

  • There is no request body and the success status is 200, not 201.

  • Not retried automatically. A lost response means a secret you never saw is already live, so rotate again: the secret your receiver holds keeps signing for 24 hours from the first rotation, which leaves time to deploy the one the second call returns.

  • Subscriptions, enabled state and consecutiveFailures are left as they were.

Also available in

API
POST /webhooks/{id}/rotate-secret
TypeScript
webhooks.rotateSecret()
Python
webhooks.rotate_secret()
Ruby
webhooks.rotate_secret
Go
Webhooks.RotateSecret
Java
webhooks().rotateSecret
C#
Webhooks.RotateSecretAsync
CLI
nextmail webhooks rotate-secret

webhooks->test

Send a synthetic event and report how delivery went

Scopeswebhooks:write
Signature
test(string $id, ?string $apiKey = null): array

Posts a signed synthetic email.sent event to the endpoint and waits for the attempt to finish before returning. The payload data holds test set to true and a note, and no mail is sent, so it is safe against a production receiver. It proves the URL is reachable and that your signature check accepts the current secret before real mail depends on it.

The outcome comes back as delivery, read from the newest row of the delivery log. status is delivered for any 2xx answer and failed otherwise, responseCode is the HTTP status or null when no response arrived, such as a DNS failure or the 5 second timeout, and error explains a failure. A 3xx counts as failed because redirects are never followed.

The event goes out whatever the endpoint subscribes to, and even when it is disabled. It is recorded like any delivery, so it appears in webhooks->listDeliveries and can be sent again with webhooks->replayDelivery, but it is tried once and leaves consecutiveFailures and lastDeliveryAt alone, so a failing test never counts toward the 100 that disable an endpoint. A 410 Gone answer does switch the endpoint off, as it would for a real event.

Parameters

idstringRequired

Endpoint id, whe_ followed by 24 hex characters.

apiKeystring

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

Returns

An array with object set to webhook_test, the endpoint id, and delivery holding status, responseCode, durationMs and error, or null when no delivery row could be read back.

Example

$result = $client->webhooks->test('whe_3f9c2a7b1e4d8f60a5c7b92d'); $delivery = $result['delivery']; if ($delivery === null) {    echo 'No delivery row was recorded', PHP_EOL;} elseif ($delivery['status'] === 'delivered') {    echo 'Delivered in ', $delivery['durationMs'], ' ms', PHP_EOL;} else {    echo 'Failed with ', $delivery['responseCode'] ?? 'no response', ': ', $delivery['error'], PHP_EOL;}

Notes

  • The call returns 200 when your receiver fails. Branch on $result['delivery']['status'], not on whether the call threw.

  • A 4xx from your receiver is a useful answer: the URL is reachable and the rejection came from your own handler, often its signature check.

  • Not retried automatically, since every call sends another request to your receiver.

  • If a real event reaches the same endpoint at the same moment, delivery can describe that attempt instead, because it reads the newest log row.

Also available in

API
POST /webhooks/{id}/test
TypeScript
webhooks.test()
Python
webhooks.test()
Ruby
webhooks.test
Go
Webhooks.Test
Java
webhooks().test
C#
Webhooks.TestAsync
CLI
nextmail webhooks test

webhooks->listDeliveries

List one page of delivery attempts for one endpoint

Scopeswebhooks:readPages through results
Signature
listDeliveries(    string $id,    ?string $status = null,    DateTimeInterface|string|null $since = null,    DateTimeInterface|string|null $until = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): Page

Returns one page of an endpoint's delivery log, newest first. Nothing is dropped from the log, so following nextCursor while hasMore is true reaches the endpoint's very first delivery, and webhooks->listAllDeliveries and webhooks->iterateDeliveries do that walk for you. status:, since: and until: narrow it the way the Deliveries tab of the app does: status: 'failed' is its "only failed" switch.

Each attempt is one POST with a 5 second timeout, and one event can appear several times: when the failure is worth repeating, a delivery on the standard retry policy is tried up to 8 times, as it happens and then after 1 minute, 5 minutes, 30 minutes, 2 hours, 5 hours, 10 hours and 10 hours, about 27 and a half hours in all, one on extended up to 16 times over about 3 days, and each webhooks->replayDelivery adds a row of its own. An event whose last attempt failed is also kept as a dead letter, which webhooks->listDeadLetters reads. attempt and maxAttempts say which try a row is, and eventId is the same across all of them, so this log distinguishes a retry from a new event. nextAttemptAt is when the automatic retry that follows a row is due, and null when none is waiting, so a failed row with a time in it is not the final word. status is delivered for a 2xx answer and failed for anything else, including a 3xx, since redirects are not followed.

responseCode null means no response arrived, such as a DNS or TLS failure or the timeout, which is a different fact from a receiver that answered. durationMs is null only when the attempt was never made because the server could not read the signing secret, and error then says so. The body that was sent and your server's answer are not part of this response, and webhooks->getDelivery returns both. webhooks->listWorkspaceDeliveries reads every endpoint at once.

Parameters

idstringRequired

Endpoint id, whe_ followed by 24 hex characters.

statusstring

failed keeps only the attempts that did not get a 2xx, the "only failed" view of the app, and delivered keeps the rest.

sincestring|DateTimeInterface

Only rows at or after this instant. A DateTimeInterface is sent as ISO 8601, and a string must already be one.

untilstring|DateTimeInterface

Only rows before this instant. It has to be later than since:, or the server answers 400 invalid_parameter.

limitint

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

cursorstring

The nextCursor from the previous page, passed back unchanged. Never build one yourself.

apiKeystring

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

Returns

A Page of delivery arrays, with items, hasMore and nextCursor. Each item has id, endpointId, eventType, eventId, status, responseCode, durationMs, attempt, maxAttempts, error, createdAt and nextAttemptAt.

Example

$failed = $client->webhooks->listDeliveries('whe_3f9c2a7b1e4d8f60a5c7b92d', status: 'failed', since: new \DateTimeImmutable('-1 day')); foreach ($failed as $delivery) {    $next = $delivery['nextAttemptAt'] === null ? 'no retry due' : 'retry at ' . $delivery['nextAttemptAt'];     echo $delivery['eventType'], ' attempt ', $delivery['attempt'], ' of ', $delivery['maxAttempts'], ': ', $delivery['responseCode'] ?? 'no response', ', ', $next, PHP_EOL;}

Notes

  • Synthetic events from webhooks->test appear here too, recorded as email.sent.

  • Each endpoint's copy of an event gets its own evt_ id, sent in the X-Webhook-Delivery header and as the payload id, and every retry and replay of that copy keeps it. One event fanned out to two endpoints arrives with two different ids, and a repeat to one endpoint arrives with the same one.

  • The cursor stays valid under every filter as long as each page sends the same status:, since: and until:, which webhooks->listAllDeliveries and webhooks->iterateDeliveries do for you.

  • A 404 resource_not_found means the endpoint id is wrong or belongs to another workspace, not that the log is empty. A cursor that names no delivery of this endpoint is a 400 invalid_cursor, and a since: or until: that does not parse is a 400 invalid_parameter.

Also available in

API
GET /webhooks/{id}/deliveries
TypeScript
webhooks.listDeliveries()
Python
webhooks.list_deliveries()
Ruby
webhooks.list_deliveries
Go
Webhooks.ListDeliveries
Java
webhooks().listDeliveries
C#
Webhooks.ListDeliveriesAsync
CLI
nextmail webhooks list-deliveries

webhooks->listAllDeliveries

Collect an endpoint's whole delivery log into one array

Scopeswebhooks:readPages through results
Signature
listAllDeliveries(    string $id,    ?string $status = null,    DateTimeInterface|string|null $since = null,    DateTimeInterface|string|null $until = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): array

Walks every page of an endpoint's delivery log and returns all of its attempts, newest first, under the same status:, since: and until: filters as webhooks->listDeliveries. The log is never pruned, so an endpoint that has been busy for a long time can hold a great many rows. Narrow it with a window, or prefer webhooks->iterateDeliveries when you can stop early.

Pages are keyset on createdAt and id, walking backwards in time. Attempts recorded after the walk starts are newer than its first page and are not included.

Parameters

idstringRequired

Endpoint id, whe_ followed by 24 hex characters.

statusstring

failed keeps only the attempts that did not get a 2xx, the "only failed" view of the app, and delivered keeps the rest.

sincestring|DateTimeInterface

Only rows at or after this instant. A DateTimeInterface is sent as ISO 8601, and a string must already be one.

untilstring|DateTimeInterface

Only rows before this instant. It has to be later than since:, or the server answers 400 invalid_parameter.

limitint

Page size for each request, 1 to 100. The server defaults to 25.

cursorstring

Starts the walk from this cursor instead of the newest row.

apiKeystring

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

Returns

A list of delivery arrays holding every matching attempt on the endpoint, newest first.

Example

$deliveries = $client->webhooks->listAllDeliveries('whe_3f9c2a7b1e4d8f60a5c7b92d', since: new \DateTimeImmutable('-7 days'), limit: 100); $failed = array_filter($deliveries, static fn(array $delivery): bool => $delivery['status'] === 'failed'); echo count($failed), ' of ', count($deliveries), ' attempts failed this week', PHP_EOL;

Notes

  • If any page fails, the exception is thrown and the attempts already fetched are discarded.

  • One request per page, so a large log takes many requests. Read it with webhooks->iterateDeliveries to stop as soon as you have what you need.

Also available in

API
GET /webhooks/{id}/deliveries
TypeScript
webhooks.listAllDeliveries()
Python
webhooks.list_all_deliveries()
Ruby
webhooks.list_all_deliveries
Go
Webhooks.ListAllDeliveries
Java
webhooks().listAllDeliveries
C#
Webhooks.ListAllDeliveriesAsync

webhooks->iterateDeliveries

Stream an endpoint's delivery attempts one at a time, newest first

Scopeswebhooks:readPages through results
Signature
iterateDeliveries(    string $id,    ?string $status = null,    DateTimeInterface|string|null $since = null,    DateTimeInterface|string|null $until = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): Generator

Returns a Generator over an endpoint's delivery log that yields attempts one at a time and fetches the next page only when the current one is used up, under the same status:, since: and until: filters as webhooks->listDeliveries. Nothing is requested until the loop starts, and breaking out of the foreach stops further requests, which makes it the right way to find the latest attempt of some kind without reading the whole history.

The walk ends when hasMore is false, when the server stops offering a cursor, or when it repeats one. Attempts recorded after the walk starts are newer than its cursor and are not yielded.

Parameters

idstringRequired

Endpoint id, whe_ followed by 24 hex characters.

statusstring

failed keeps only the attempts that did not get a 2xx, the "only failed" view of the app, and delivered keeps the rest.

sincestring|DateTimeInterface

Only rows at or after this instant. A DateTimeInterface is sent as ISO 8601, and a string must already be one.

untilstring|DateTimeInterface

Only rows before this instant. It has to be later than since:, or the server answers 400 invalid_parameter.

limitint

Page size per request, 1 to 100. The server defaults to 25.

cursorstring

Starts the walk from this cursor instead of the newest row.

apiKeystring

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

Returns

A Generator that yields one delivery array per step.

Example

foreach ($client->webhooks->iterateDeliveries('whe_3f9c2a7b1e4d8f60a5c7b92d', status: 'failed') as $delivery) {    if ($delivery['nextAttemptAt'] === null) {        echo 'Latest final failure: ', $delivery['id'], ' ', $delivery['error'], PHP_EOL;         break;    }}

Notes

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

Also available in

API
GET /webhooks/{id}/deliveries
TypeScript
webhooks.iterateDeliveries()
Python
webhooks.iterate_deliveries()
Ruby
webhooks.iterate_deliveries
Go
Webhooks.IterateDeliveries
Java
webhooks().iterateDeliveries
C#
Webhooks.IterateDeliveriesAsync

webhooks->getDelivery

Read one delivery attempt in full, with the body that was sent

Scopeswebhooks:read
Signature
getDelivery(string $id, string $deliveryId, ?string $apiKey = null): array

Returns one attempt from an endpoint's delivery log with what webhooks->listDeliveries leaves out. payload is the exact JSON body that was POSTed, an array with id, type, createdAt and data, and responseBody is the first 2,000 characters your server answered, or null when nothing came back or the answer was a redirect.

attempts lists every try of the same event on this endpoint, oldest first: the first attempt, the automatic retries and any replays, each with its own id, attempt, status, responseCode, error and createdAt. They share eventId, which is the payload id your receiver saw. nextAttemptAt is when the next automatic retry of the event is due, whichever attempt it follows, and null when none is waiting.

replayRefusal says whether webhooks->replayDelivery would accept this attempt before you call it: null when it would, and otherwise the code and message the replay would be refused with, such as webhook_disabled while the endpoint is switched off, or retry_in_progress while an automatic retry of the same event is being sent.

Parameters

idstringRequired

Endpoint id, whe_ followed by 24 hex characters.

deliveryIdstringRequired

Delivery id, whd_ followed by 24 hex characters, as webhooks->listDeliveries returns it.

apiKeystring

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

Returns

An array with the delivery fields (id, eventType, eventId, status, responseCode, durationMs, attempt, maxAttempts, error, createdAt, nextAttemptAt) plus endpointId, payload, responseBody, attempts and replayRefusal.

Example

$delivery = $client->webhooks->getDelivery('whe_3f9c2a7b1e4d8f60a5c7b92d', 'whd_8c1e4a7f2b9d3e6a0c5f1b28'); echo 'Event ', $delivery['payload']['id'], ' was tried ', count($delivery['attempts']), ' times', PHP_EOL;echo 'Your server answered: ', $delivery['responseBody'] ?? 'nothing', PHP_EOL; if ($delivery['replayRefusal'] !== null) {    echo 'A replay would be refused: ', $delivery['replayRefusal']['message'], PHP_EOL;}

Notes

  • A delivery id that belongs to another endpoint, even one in the same workspace, is 404 resource_not_found, exactly like one that never existed.

  • Your server's answer is cut at 2,000 characters when it is recorded, so a longer one reads back truncated.

  • A GET is retried automatically on network failure and on 408, 429, 500, 502, 503 and 504 responses, up to the client's maxRetries.

  • A narrowed key may read a delivery only on an endpoint whose own allowlists sit inside what the key holds, where holding one address never covers its whole domain, because the body names the addresses the event is about. Any other is 422 capability_unsupported on addressAllowlist. Over OAuth only the workspace owner, or a member whose role holds addresses:all, may read one, and any other member's token is 403 owner_only. That member's token is held to the domains the workspace has now, so it reads only a delivery of an endpoint with allowlists, and one with none is 422 capability_unsupported for it too.

Also available in

API
GET /webhooks/{id}/deliveries/{deliveryId}
TypeScript
webhooks.getDelivery()
Python
webhooks.get_delivery()
Ruby
webhooks.get_delivery
Go
Webhooks.GetDelivery
Java
webhooks().getDelivery
C#
Webhooks.GetDeliveryAsync
CLI
nextmail webhooks get-delivery

webhooks->replayDelivery

Send one stored event to the endpoint again, now

Scopeswebhooks:write
Signature
replayDelivery(string $id, string $deliveryId, ?string $apiKey = null): array

Posts the event behind a recorded attempt to the endpoint once more, straight away, and returns when that attempt has finished. The body is the one stored with the original, with the same id, type, createdAt and data, so a receiver that drops ids it has already handled treats the replay as the event it already knows. Only X-Webhook-Signature is new, because every POST is signed with the current secret at the moment it goes out, so a replay verifies after a webhooks->rotateSecret too.

It accepts a delivered attempt as well as a failed one. Replaying a success is how a receiver that lost its copy, or handled it wrongly, is brought back in step. Any attempt of the event will do, since they all carry the same event.

The replay is recorded in the log as a new delivery, attempt 1 of 1, and is never retried automatically. Before it goes out, the automatic retries of the same event that have not started are paused, so the receiver never gets two copies at once. When the replay is delivered they stay cancelled. When it fails they resume on their schedule. If an automatic retry of the event is being sent at that very moment, the replay sends nothing and is refused with 409 retry_in_progress, and if another replay of the same event is still being sent, it is refused with 409 replay_in_progress, so two copies never go out at once. The call returns 200 whatever your server answered, so branch on $replay['delivery']['status'] rather than on whether the call threw.

Parameters

idstringRequired

Endpoint id, whe_ followed by 24 hex characters.

deliveryIdstringRequired

Any attempt of the event to send again, whd_ followed by 24 hex characters.

apiKeystring

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

Returns

An array with object set to webhook_replay, id (the new delivery), endpointId, replayOf (the attempt you named), eventId, eventType, and delivery holding status, responseCode, durationMs and error.

Example

use Nextmail\Constants\WebhookReplayErrorCodes;use Nextmail\Exception\ConflictException; try {    $replay = $client->webhooks->replayDelivery('whe_3f9c2a7b1e4d8f60a5c7b92d', 'whd_8c1e4a7f2b9d3e6a0c5f1b28');     $delivered = $replay['delivery']['status'] === 'delivered';     echo 'Replay ', $replay['id'], $delivered ? ' delivered' : ' failed: ' . $replay['delivery']['error'], PHP_EOL;} catch (ConflictException $error) {    if ($error->errorCode === WebhookReplayErrorCodes::RETRY_IN_PROGRESS) {        echo 'A retry of this event is being sent right now', PHP_EOL;    } else {        echo 'Refused: ', $error->errorCode, PHP_EOL;    }}

Notes

  • Refused with 409 when nobody who wants the event would receive it: webhook_disabled while the endpoint is switched off, event_not_subscribed when it no longer listens for the event type, event_out_of_scope when its allowlists no longer cover the address the event is about, delivery_not_replayable when the attempt has no stored event, retry_in_progress while an automatic retry of the same event is being sent, and replay_in_progress while another replay of it is. The codes are in Nextmail\Constants\WebhookReplayErrorCodes. Wait a few seconds and check webhooks->getDelivery before replaying again, since that retry or replay may deliver it. webhooks->getDelivery reports the same answer in advance as replayRefusal. A synthetic event from webhooks->test replays whatever the endpoint subscribes to.

  • Not retried automatically, because a retry after a lost response would send the event again. A receiver that drops repeated ids handles that safely, but the SDK does not assume yours does.

  • A delivered replay resets consecutiveFailures, and a failed one does not add to it. A 410 Gone switches the endpoint off, as it does for an automatic delivery.

  • A delivered replay closes the open dead letter of the event, if it has one, and a failed one counts as its latest attempt. webhooks->replayDeadLetters sends up to 100 dead letters in one call.

  • A narrowed key may replay only on an endpoint whose own allowlists sit inside what the key holds. Any other is 422 capability_unsupported on addressAllowlist.

Also available in

API
POST /webhooks/{id}/deliveries/{deliveryId}/replay
TypeScript
webhooks.replayDelivery()
Python
webhooks.replay_delivery()
Ruby
webhooks.replay_delivery
Go
Webhooks.ReplayDelivery
Java
webhooks().replayDelivery
C#
Webhooks.ReplayDeliveryAsync
CLI
nextmail webhooks replay-delivery

webhooks->listDeadLetters

List one page of the events an endpoint gave up on

Scopeswebhooks:readPages through results
Signature
listDeadLetters(    string $id,    ?string $status = null,    DateTimeInterface|string|null $since = null,    DateTimeInterface|string|null $until = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): Page

Returns one page of an endpoint's dead letters, newest first. An event becomes a dead letter when its last automatic attempt fails: its retries ran out under the endpoint's retryPolicy, the receiver gave an answer that is not tried again (a 4xx other than 408, 425 and 429, or a 410 that also switches the endpoint off), or the endpoint was switched off before the next retry was due. Keeping dead letters changes nothing about how events are delivered.

status: is open by default, the dead letters still waiting for somebody to replay or discard them. replayed and discarded read the closed ones and all reads every one, and the four are in Nextmail\Constants\WebhookDeadLetterFilters. Each one names the event (eventId and eventType), how many times it was tried (attempts), what the last attempt got back (responseCode and error) and that attempt as deliveryId, whose stored body webhooks->getDelivery reads. A dead letter is deleted 30 days after the event was given up on, at expiresAt, whatever its status, while the delivery log keeps every attempt.

webhooks->replayDeadLetters sends open ones again and webhooks->discardDeadLetter closes one without sending it. webhooks->listAllDeadLetters and webhooks->iterateDeadLetters walk every page for you.

Parameters

idstringRequired

Endpoint id, whe_ followed by 24 hex characters.

statusstring

open, the default, keeps the dead letters still waiting for a decision. replayed and discarded keep the closed ones and all keeps every one.

sincestring|DateTimeInterface

Only dead letters given up on at or after this instant. A DateTimeInterface is sent as ISO 8601, and a string must already be one.

untilstring|DateTimeInterface

Only dead letters given up on before this instant. It has to be later than since:, or the server answers 400 invalid_parameter.

limitint

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

cursorstring

The nextCursor from the previous page, passed back unchanged. Never build one yourself.

apiKeystring

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

Returns

A Page of dead letter arrays, with items, hasMore and nextCursor. Each item has id, endpointId, eventId, eventType, status, attempts, responseCode, error, deliveryId, replayDeliveryId, diedAt, resolvedAt and expiresAt, and status is one of Nextmail\Constants\WebhookDeadLetterStatuses.

Example

$page = $client->webhooks->listDeadLetters('whe_3f9c2a7b1e4d8f60a5c7b92d', limit: 50); foreach ($page as $deadLetter) {    echo $deadLetter['eventType'], ' tried ', $deadLetter['attempts'], ' times, last answer ', $deadLetter['responseCode'] ?? 'none', ': ', $deadLetter['error'] ?? 'no error', PHP_EOL;}

Notes

  • A 404 resource_not_found means the endpoint id is wrong or belongs to another workspace, not that there are no dead letters. A cursor that names no dead letter of this endpoint is a 400 invalid_cursor.

  • Deleting the endpoint deletes its dead letters with it.

Also available in

API
GET /webhooks/{id}/dead-letters
TypeScript
webhooks.listDeadLetters()
Python
webhooks.list_dead_letters()
Ruby
webhooks.list_dead_letters
Go
Webhooks.ListDeadLetters
Java
webhooks().listDeadLetters
C#
Webhooks.ListDeadLettersAsync
CLI
nextmail webhooks list-dead-letters

webhooks->listAllDeadLetters

Collect an endpoint's dead letters into one array

Scopeswebhooks:readPages through results
Signature
listAllDeadLetters(    string $id,    ?string $status = null,    DateTimeInterface|string|null $since = null,    DateTimeInterface|string|null $until = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): array

Walks every page of an endpoint's dead letters and returns all of them, newest first, under the same status:, since: and until: filters as webhooks->listDeadLetters. A dead letter is deleted 30 days after its event was given up on, so the walk covers at most a month of failures.

Pages are keyset on diedAt and id, walking backwards in time. Dead letters recorded after the walk starts are newer than its first page and are not included.

Parameters

idstringRequired

Endpoint id, whe_ followed by 24 hex characters.

statusstring

open, the default, keeps the dead letters still waiting for a decision. replayed and discarded keep the closed ones and all keeps every one.

sincestring|DateTimeInterface

Only dead letters given up on at or after this instant. A DateTimeInterface is sent as ISO 8601, and a string must already be one.

untilstring|DateTimeInterface

Only dead letters given up on before this instant. It has to be later than since:, or the server answers 400 invalid_parameter.

limitint

Page size for each request, 1 to 100. The server defaults to 25.

cursorstring

Starts the walk from this cursor instead of the newest row.

apiKeystring

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

Returns

A list of dead letter arrays holding every matching dead letter of the endpoint, newest first.

Example

$open = $client->webhooks->listAllDeadLetters('whe_3f9c2a7b1e4d8f60a5c7b92d'); echo count($open), ' events are waiting to be replayed or discarded', PHP_EOL;

Notes

  • If any page fails, the exception is thrown and the dead letters already fetched are discarded.

Also available in

API
GET /webhooks/{id}/dead-letters
TypeScript
webhooks.listAllDeadLetters()
Python
webhooks.list_all_dead_letters()
Ruby
webhooks.list_all_dead_letters
Go
Webhooks.ListAllDeadLetters
Java
webhooks().listAllDeadLetters
C#
Webhooks.ListAllDeadLettersAsync

webhooks->iterateDeadLetters

Stream an endpoint's dead letters one at a time, newest first

Scopeswebhooks:readPages through results
Signature
iterateDeadLetters(    string $id,    ?string $status = null,    DateTimeInterface|string|null $since = null,    DateTimeInterface|string|null $until = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): Generator

Returns a Generator over an endpoint's dead letters that yields them one at a time and fetches the next page only when the current one is used up, under the same status:, since: and until: filters as webhooks->listDeadLetters. Nothing is requested until the loop starts, and breaking out of the foreach stops further requests.

The walk ends when hasMore is false, when the server stops offering a cursor, or when it repeats one. Dead letters recorded after the walk starts are newer than its cursor and are not yielded.

Parameters

idstringRequired

Endpoint id, whe_ followed by 24 hex characters.

statusstring

open, the default, keeps the dead letters still waiting for a decision. replayed and discarded keep the closed ones and all keeps every one.

sincestring|DateTimeInterface

Only dead letters given up on at or after this instant. A DateTimeInterface is sent as ISO 8601, and a string must already be one.

untilstring|DateTimeInterface

Only dead letters given up on before this instant. It has to be later than since:, or the server answers 400 invalid_parameter.

limitint

Page size per request, 1 to 100. The server defaults to 25.

cursorstring

Starts the walk from this cursor instead of the newest row.

apiKeystring

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

Returns

A Generator that yields one dead letter array per step.

Example

use Nextmail\Constants\WebhookDeadLetterFilters;use Nextmail\Constants\WebhookDeadLetterStatuses; foreach ($client->webhooks->iterateDeadLetters('whe_3f9c2a7b1e4d8f60a5c7b92d', status: WebhookDeadLetterFilters::ALL) as $deadLetter) {    if ($deadLetter['status'] === WebhookDeadLetterStatuses::REPLAYED) {        echo $deadLetter['eventId'], ' was replayed as ', $deadLetter['replayDeliveryId'], PHP_EOL;    }}

Notes

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

Also available in

API
GET /webhooks/{id}/dead-letters
TypeScript
webhooks.iterateDeadLetters()
Python
webhooks.iterate_dead_letters()
Ruby
webhooks.iterate_dead_letters
Go
Webhooks.IterateDeadLetters
Java
webhooks().iterateDeadLetters
C#
Webhooks.IterateDeadLettersAsync

webhooks->replayDeadLetters

Send an endpoint's open dead letters again, now

Scopeswebhooks:write
Signature
replayDeadLetters(string $id, ?array $body = null, ?string $apiKey = null): array

Sends open dead letters of the endpoint again, each through the same replay as webhooks->replayDelivery: the stored event goes out once, straight away, with its original id, type, createdAt and data and a fresh signature, and is never retried automatically. Name up to 100 in ids, or pass no body to send the 100 oldest open ones.

Each entry of data says in outcome what happened to one dead letter, one of Nextmail\Constants\WebhookDeadLetterReplayOutcomes. delivered closes it as replayed, with the replay in its replayDeliveryId. failed leaves it open with the new attempt as its last one, so it can be sent again later. refused sent nothing and leaves it open, and refusal holds the code and message a single replay is refused with (event_not_subscribed, event_out_of_scope, delivery_not_replayable, retry_in_progress or replay_in_progress), or resource_not_found for an id that is not a dead letter of this endpoint and dead_letter_resolved for one already closed. skipped was not reached by this call.

Replays go out five at a time. When five in a row fail the call skips the rest, so a receiver that is still down is not sent the whole backlog, and a call also stops starting new replays after about 20 seconds, or before it would use up the database work one request may do, so a long backlog can take a few calls. hasMore is true while open dead letters are left that this call did not send, so call again until it is false. Every replay is recorded in the delivery log as attempt 1 of 1 and in the activity of the endpoint.

Parameters

idstringRequired

Endpoint id, whe_ followed by 24 hex characters.

idsstring[]

Dead letter ids, dlq_ followed by 24 hex characters, at most 100. Leave it out to send the oldest open ones.

apiKeystring

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

Returns

An array with object set to list, hasMore, and data holding one entry per dead letter: object set to webhook_dead_letter_replay, id, outcome, deliveryId, delivery with status, responseCode, durationMs and error, and refusal with code and message.

Example

use Nextmail\Constants\WebhookDeadLetterReplayOutcomes; $delivered = static fn(array $entry): bool => $entry['outcome'] === WebhookDeadLetterReplayOutcomes::DELIVERED; do {    $result = $client->webhooks->replayDeadLetters('whe_3f9c2a7b1e4d8f60a5c7b92d');} while ($result['hasMore'] && array_filter($result['data'], $delivered) !== []); foreach ($result['data'] as $entry) {    if (!$delivered($entry)) {        echo $entry['id'], ' ', $entry['outcome'], ': ', $entry['refusal']['message'] ?? $entry['delivery']['error'] ?? 'not reached', PHP_EOL;    }}

Notes

  • Refused with 409 webhook_disabled while the endpoint is switched off, before anything is sent. Switch it back on with webhooks->update first.

  • Not retried automatically, because a retry after a lost response would send the events again. A receiver that drops repeated ids handles that safely, but the SDK does not assume yours does.

  • A narrowed key may replay only on an endpoint whose own allowlists sit inside what the key holds. Any other is 422 capability_unsupported on addressAllowlist.

Also available in

API
POST /webhooks/{id}/dead-letters/replay
TypeScript
webhooks.replayDeadLetters()
Python
webhooks.replay_dead_letters()
Ruby
webhooks.replay_dead_letters
Go
Webhooks.ReplayDeadLetters
Java
webhooks().replayDeadLetters
C#
Webhooks.ReplayDeadLettersAsync
CLI
nextmail webhooks replay-dead-letters

webhooks->discardDeadLetter

Close a dead letter without sending it

Scopeswebhooks:write
Signature
discardDeadLetter(string $id, string $deadLetterId, ?string $apiKey = null): array

Marks an open dead letter discarded, for an event that should not reach the receiver after all. Nothing is sent. The event stays in the delivery log, where webhooks->replayDelivery can still send it, and the dead letter is deleted 30 days after its event was given up on, like every other.

Discarding one that is already discarded returns it unchanged, and one that was replayed is refused with 409 dead_letter_resolved.

Parameters

idstringRequired

Endpoint id, whe_ followed by 24 hex characters.

deadLetterIdstringRequired

Dead letter id, dlq_ followed by 24 hex characters, as webhooks->listDeadLetters returns it.

apiKeystring

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

Returns

An array for the dead letter as saved, shaped like the items of webhooks->listDeadLetters, with status set to discarded and resolvedAt filled in.

Example

$deadLetter = $client->webhooks->discardDeadLetter('whe_3f9c2a7b1e4d8f60a5c7b92d', 'dlq_8c1e4a7f2b9d3e6a0c5f1b28'); echo $deadLetter['eventId'], ' ', $deadLetter['status'], ' at ', $deadLetter['resolvedAt'], PHP_EOL;

Notes

  • A 404 resource_not_found means the endpoint or the dead letter is not in this workspace, or the dead letter belongs to another endpoint.

  • Retried automatically on network failure and retryable statuses, since discarding twice lands on the same row.

Also available in

API
DELETE /webhooks/{id}/dead-letters/{deadLetterId}
TypeScript
webhooks.discardDeadLetter()
Python
webhooks.discard_dead_letter()
Ruby
webhooks.discard_dead_letter
Go
Webhooks.DiscardDeadLetter
Java
webhooks().discardDeadLetter
C#
Webhooks.DiscardDeadLetterAsync
CLI
nextmail webhooks discard-dead-letter

webhooks->listWorkspaceDeliveries

List one page of delivery attempts across every endpoint

Scopeswebhooks:readPages through results
Signature
listWorkspaceDeliveries(    array|string|null $endpointIds = null,    ?string $status = null,    DateTimeInterface|string|null $since = null,    DateTimeInterface|string|null $until = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): Page

Returns one page of the whole workspace's delivery log, newest first: the all-endpoints Deliveries tab of the app. Each row carries endpointId, so the endpoint an attempt went to is never lost. endpointIds: narrows it to some endpoints, and status:, since: and until: work exactly as they do on webhooks->listDeliveries.

Nothing is pruned, so following nextCursor while hasMore is true reaches the workspace's first delivery. webhooks->listAllWorkspaceDeliveries and webhooks->iterateWorkspaceDeliveries do that walk. The body that was sent is not here: read it with webhooks->getDelivery, passing the row's endpointId and id.

Parameters

endpointIdsstring|string[]

Endpoint ids to read, at most 50, as a list or one comma-separated string. Left out, every endpoint in the workspace.

statusstring

failed keeps only the attempts that did not get a 2xx, the "only failed" view of the app, and delivered keeps the rest.

sincestring|DateTimeInterface

Only rows at or after this instant. A DateTimeInterface is sent as ISO 8601, and a string must already be one.

untilstring|DateTimeInterface

Only rows before this instant. It has to be later than since:, or the server answers 400 invalid_parameter.

limitint

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

cursorstring

The nextCursor from the previous page, passed back unchanged. Never build one yourself.

apiKeystring

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

Returns

A Page of delivery arrays, with items, hasMore and nextCursor. Each item has id, endpointId, eventType, eventId, status, responseCode, durationMs, attempt, maxAttempts, error, createdAt and nextAttemptAt.

Example

$page = $client->webhooks->listWorkspaceDeliveries(status: 'failed', since: new \DateTimeImmutable('-1 hour')); foreach ($page as $delivery) {    echo $delivery['endpointId'], ' ', $delivery['eventType'], ' ', $delivery['error'] ?? '', PHP_EOL;}

Notes

  • An endpoint id in endpointIds: that belongs to no endpoint here simply matches nothing. A removed endpoint takes its deliveries with it.

  • The cursor stays valid under every filter as long as each page sends the same endpointIds:, status:, since: and until:, which webhooks->listAllWorkspaceDeliveries and webhooks->iterateWorkspaceDeliveries do for you.

  • The list carries no payloads, so a key narrowed to some addresses may read it. Opening a delivery with webhooks->getDelivery is where the narrowing applies.

Also available in

API
GET /webhooks/deliveries
TypeScript
webhooks.listWorkspaceDeliveries()
Python
webhooks.list_workspace_deliveries()
Ruby
webhooks.list_workspace_deliveries
Go
Webhooks.ListWorkspaceDeliveries
Java
webhooks().listWorkspaceDeliveries
C#
Webhooks.ListWorkspaceDeliveriesAsync
CLI
nextmail webhooks list-workspace-deliveries

webhooks->listAllWorkspaceDeliveries

Collect the workspace's whole delivery log into one array

Scopeswebhooks:readPages through results
Signature
listAllWorkspaceDeliveries(    array|string|null $endpointIds = null,    ?string $status = null,    DateTimeInterface|string|null $since = null,    DateTimeInterface|string|null $until = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): array

Walks every page of webhooks->listWorkspaceDeliveries under the same filters and returns every matching attempt, newest first. The log is never pruned, so give it a since: or endpointIds: unless you mean to read all of it, or use webhooks->iterateWorkspaceDeliveries to stop early.

Parameters

endpointIdsstring|string[]

Endpoint ids to read, at most 50, as a list or one comma-separated string. Left out, every endpoint in the workspace.

statusstring

failed keeps only the attempts that did not get a 2xx, the "only failed" view of the app, and delivered keeps the rest.

sincestring|DateTimeInterface

Only rows at or after this instant. A DateTimeInterface is sent as ISO 8601, and a string must already be one.

untilstring|DateTimeInterface

Only rows before this instant. It has to be later than since:, or the server answers 400 invalid_parameter.

limitint

Page size for each request, 1 to 100. The server defaults to 25.

cursorstring

Starts the walk from this cursor instead of the newest row.

apiKeystring

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

Returns

A list of delivery arrays holding every matching attempt, newest first.

Example

$deliveries = $client->webhooks->listAllWorkspaceDeliveries(    endpointIds: ['whe_3f9c2a7b1e4d8f60a5c7b92d', 'whe_8a1c4e7b2d9f3a60c5e1b7d4'],    since: new \DateTimeImmutable('-1 day'),    limit: 100,); $perEndpoint = []; foreach ($deliveries as $delivery) {    $perEndpoint[$delivery['endpointId']] = ($perEndpoint[$delivery['endpointId']] ?? 0) + 1;} print_r($perEndpoint);

Notes

  • If any page fails, the exception is thrown and the attempts already fetched are discarded.

Also available in

API
GET /webhooks/deliveries
TypeScript
webhooks.listAllWorkspaceDeliveries()
Python
webhooks.list_all_workspace_deliveries()
Ruby
webhooks.list_all_workspace_deliveries
Go
Webhooks.ListAllWorkspaceDeliveries
Java
webhooks().listAllWorkspaceDeliveries
C#
Webhooks.ListAllWorkspaceDeliveriesAsync

webhooks->iterateWorkspaceDeliveries

Stream the workspace's delivery attempts one at a time, newest first

Scopeswebhooks:readPages through results
Signature
iterateWorkspaceDeliveries(    array|string|null $endpointIds = null,    ?string $status = null,    DateTimeInterface|string|null $since = null,    DateTimeInterface|string|null $until = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): Generator

Returns a Generator over webhooks->listWorkspaceDeliveries under the same filters. It fetches a page only when the one before is used up and stops requesting when you break out of the foreach.

Parameters

endpointIdsstring|string[]

Endpoint ids to read, at most 50, as a list or one comma-separated string. Left out, every endpoint in the workspace.

statusstring

failed keeps only the attempts that did not get a 2xx, the "only failed" view of the app, and delivered keeps the rest.

sincestring|DateTimeInterface

Only rows at or after this instant. A DateTimeInterface is sent as ISO 8601, and a string must already be one.

untilstring|DateTimeInterface

Only rows before this instant. It has to be later than since:, or the server answers 400 invalid_parameter.

limitint

Page size per request, 1 to 100. The server defaults to 25.

cursorstring

Starts the walk from this cursor instead of the newest row.

apiKeystring

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

Returns

A Generator that yields one delivery array per step.

Example

foreach ($client->webhooks->iterateWorkspaceDeliveries(status: 'failed') as $delivery) {    echo 'Most recent failure: ', $delivery['endpointId'], ' ', $delivery['eventType'], ' at ', $delivery['createdAt'], PHP_EOL;     break;}

Notes

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

Also available in

API
GET /webhooks/deliveries
TypeScript
webhooks.iterateWorkspaceDeliveries()
Python
webhooks.iterate_workspace_deliveries()
Ruby
webhooks.iterate_workspace_deliveries
Go
Webhooks.IterateWorkspaceDeliveries
Java
webhooks().iterateWorkspaceDeliveries
C#
Webhooks.IterateWorkspaceDeliveriesAsync

webhooks->listActivity

List one page of what happened to one endpoint

Scopeswebhooks:readPages through results
Signature
listActivity(    string $id,    DateTimeInterface|string|null $since = null,    DateTimeInterface|string|null $until = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): Page

Returns one page of an endpoint's audit log, newest first, the Activity tab of the endpoint in the app. Every change is a row: created, updated, enabled, disabled, auto_disabled, secret_rotated, tested, replayed and removed, whether it came from the app, from a key over the API, or from Nextmail itself. actor says who, with label already formatted the way the app shows it: @username for a person, API key <name> for a key, and actor is null when Nextmail made the change on its own, such as switching an endpoint off after 100 failed events in a row. detail carries what moved: the URL, previousUrl when it changed, the event types and allowlists an update set, or the status and response code a test or a replay got.

Nothing is pruned, and a removed endpoint keeps its history, so this answers for an endpoint that is gone too. since: and until: keep a window.

Parameters

idstringRequired

Endpoint id, whe_ followed by 24 hex characters.

sincestring|DateTimeInterface

Only rows at or after this instant. A DateTimeInterface is sent as ISO 8601, and a string must already be one.

untilstring|DateTimeInterface

Only rows before this instant. It has to be later than since:, or the server answers 400 invalid_parameter.

limitint

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

cursorstring

The nextCursor from the previous page, passed back unchanged. Never build one yourself.

apiKeystring

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

Returns

A Page of change arrays, with items, hasMore and nextCursor. Each item has id, endpointId, endpointLabel, type, createdAt, actor and detail.

Example

$page = $client->webhooks->listActivity('whe_3f9c2a7b1e4d8f60a5c7b92d', since: new \DateTimeImmutable('-30 days')); foreach ($page as $change) {    echo $change['createdAt'], ' ', $change['type'], ' by ', $change['actor']['label'] ?? 'Nextmail', PHP_EOL;}

Notes

  • A 404 means no endpoint and no history with that id exists in this workspace. The cursor is opaque: pass nextCursor back as it came, and one this list did not hand out is a 400 invalid_cursor.

Also available in

API
GET /webhooks/{id}/activity
TypeScript
webhooks.listActivity()
Python
webhooks.list_activity()
Ruby
webhooks.list_activity
Go
Webhooks.ListActivity
Java
webhooks().listActivity
C#
Webhooks.ListActivityAsync
CLI
nextmail webhooks list-activity

webhooks->listAllActivity

Collect one endpoint's whole audit log into one array

Scopeswebhooks:readPages through results
Signature
listAllActivity(    string $id,    DateTimeInterface|string|null $since = null,    DateTimeInterface|string|null $until = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): array

Walks every page of webhooks->listActivity under the same window and returns every change, newest first.

Parameters

idstringRequired

Endpoint id, whe_ followed by 24 hex characters.

sincestring|DateTimeInterface

Only rows at or after this instant. A DateTimeInterface is sent as ISO 8601, and a string must already be one.

untilstring|DateTimeInterface

Only rows before this instant. It has to be later than since:, or the server answers 400 invalid_parameter.

limitint

Page size for each request, 1 to 100. The server defaults to 25.

cursorstring

Starts the walk from this cursor instead of the newest row.

apiKeystring

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

Returns

A list of change arrays, newest first.

Example

$changes = $client->webhooks->listAllActivity('whe_3f9c2a7b1e4d8f60a5c7b92d'); $rotations = array_filter($changes, static fn(array $change): bool => $change['type'] === 'secret_rotated'); echo count($changes), ' changes, ', count($rotations), ' of them secret rotations', PHP_EOL;

Notes

  • If any page fails, the exception is thrown and the rows already fetched are discarded.

Also available in

API
GET /webhooks/{id}/activity
TypeScript
webhooks.listAllActivity()
Python
webhooks.list_all_activity()
Ruby
webhooks.list_all_activity
Go
Webhooks.ListAllActivity
Java
webhooks().listAllActivity
C#
Webhooks.ListAllActivityAsync

webhooks->iterateActivity

Stream one endpoint's audit log one change at a time

Scopeswebhooks:readPages through results
Signature
iterateActivity(    string $id,    DateTimeInterface|string|null $since = null,    DateTimeInterface|string|null $until = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): Generator

Returns a Generator over webhooks->listActivity under the same window, fetching a page only when the one before is used up.

Parameters

idstringRequired

Endpoint id, whe_ followed by 24 hex characters.

sincestring|DateTimeInterface

Only rows at or after this instant. A DateTimeInterface is sent as ISO 8601, and a string must already be one.

untilstring|DateTimeInterface

Only rows before this instant. It has to be later than since:, or the server answers 400 invalid_parameter.

limitint

Page size per request, 1 to 100. The server defaults to 25.

cursorstring

Starts the walk from this cursor instead of the newest row.

apiKeystring

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

Returns

A Generator that yields one change array per step.

Example

foreach ($client->webhooks->iterateActivity('whe_3f9c2a7b1e4d8f60a5c7b92d') as $change) {    if ($change['type'] === 'auto_disabled') {        echo 'Switched off by Nextmail at ', $change['createdAt'], PHP_EOL;         break;    }}

Also available in

API
GET /webhooks/{id}/activity
TypeScript
webhooks.iterateActivity()
Python
webhooks.iterate_activity()
Ruby
webhooks.iterate_activity
Go
Webhooks.IterateActivity
Java
webhooks().iterateActivity
C#
Webhooks.IterateActivityAsync

webhooks->listWorkspaceActivity

List one page of what happened to every endpoint

Scopeswebhooks:readPages through results
Signature
listWorkspaceActivity(    array|string|null $endpointIds = null,    DateTimeInterface|string|null $since = null,    DateTimeInterface|string|null $until = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): Page

Returns one page of the whole workspace's webhook audit log, newest first, the Activity tab of Settings, Webhooks. Every change is a row: created, updated, enabled, disabled, auto_disabled, secret_rotated, tested, replayed and removed, whether it came from the app, from a key over the API, or from Nextmail itself. actor says who, with label already formatted the way the app shows it: @username for a person, API key <name> for a key, and actor is null when Nextmail made the change on its own, such as switching an endpoint off after 100 failed events in a row. detail carries what moved: the URL, previousUrl when it changed, the event types and allowlists an update set, or the status and response code a test or a replay got.

endpointIds: narrows it to some endpoints, removed ones included, and since: and until: keep a window.

Parameters

endpointIdsstring|string[]

Endpoint ids to read, at most 50, as a list or one comma-separated string. Left out, every endpoint in the workspace.

sincestring|DateTimeInterface

Only rows at or after this instant. A DateTimeInterface is sent as ISO 8601, and a string must already be one.

untilstring|DateTimeInterface

Only rows before this instant. It has to be later than since:, or the server answers 400 invalid_parameter.

limitint

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

cursorstring

The nextCursor from the previous page, passed back unchanged. Never build one yourself.

apiKeystring

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

Returns

A Page of change arrays, with items, hasMore and nextCursor. Each item has id, endpointId, endpointLabel, type, createdAt, actor and detail.

Example

$page = $client->webhooks->listWorkspaceActivity(since: new \DateTimeImmutable('-7 days')); foreach ($page as $change) {    echo $change['endpointLabel'], ': ', $change['type'], ' by ', $change['actor']['label'] ?? 'Nextmail', PHP_EOL;}

Notes

  • The cursor is opaque: pass nextCursor back as it came. One this list did not hand out is a 400 invalid_cursor.

Also available in

API
GET /webhooks/activity
TypeScript
webhooks.listWorkspaceActivity()
Python
webhooks.list_workspace_activity()
Ruby
webhooks.list_workspace_activity
Go
Webhooks.ListWorkspaceActivity
Java
webhooks().listWorkspaceActivity
C#
Webhooks.ListWorkspaceActivityAsync
CLI
nextmail webhooks list-workspace-activity

webhooks->listAllWorkspaceActivity

Collect the whole webhook audit log into one array

Scopeswebhooks:readPages through results
Signature
listAllWorkspaceActivity(    array|string|null $endpointIds = null,    DateTimeInterface|string|null $since = null,    DateTimeInterface|string|null $until = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): array

Walks every page of webhooks->listWorkspaceActivity under the same filters and returns every change, newest first.

Parameters

endpointIdsstring|string[]

Endpoint ids to read, at most 50, as a list or one comma-separated string. Left out, every endpoint in the workspace.

sincestring|DateTimeInterface

Only rows at or after this instant. A DateTimeInterface is sent as ISO 8601, and a string must already be one.

untilstring|DateTimeInterface

Only rows before this instant. It has to be later than since:, or the server answers 400 invalid_parameter.

limitint

Page size for each request, 1 to 100. The server defaults to 25.

cursorstring

Starts the walk from this cursor instead of the newest row.

apiKeystring

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

Returns

A list of change arrays, newest first.

Example

$changes = $client->webhooks->listAllWorkspaceActivity(since: new \DateTimeImmutable('-90 days'), limit: 100); $byKey = array_filter($changes, static fn(array $change): bool => ($change['actor']['kind'] ?? null) === 'apiKey'); echo count($changes), ' changes, ', count($byKey), ' of them made with an API key', PHP_EOL;

Notes

  • If any page fails, the exception is thrown and the rows already fetched are discarded.

Also available in

API
GET /webhooks/activity
TypeScript
webhooks.listAllWorkspaceActivity()
Python
webhooks.list_all_workspace_activity()
Ruby
webhooks.list_all_workspace_activity
Go
Webhooks.ListAllWorkspaceActivity
Java
webhooks().listAllWorkspaceActivity
C#
Webhooks.ListAllWorkspaceActivityAsync

webhooks->iterateWorkspaceActivity

Stream the whole webhook audit log one change at a time

Scopeswebhooks:readPages through results
Signature
iterateWorkspaceActivity(    array|string|null $endpointIds = null,    DateTimeInterface|string|null $since = null,    DateTimeInterface|string|null $until = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): Generator

Returns a Generator over webhooks->listWorkspaceActivity under the same filters, fetching a page only when the one before is used up.

Parameters

endpointIdsstring|string[]

Endpoint ids to read, at most 50, as a list or one comma-separated string. Left out, every endpoint in the workspace.

sincestring|DateTimeInterface

Only rows at or after this instant. A DateTimeInterface is sent as ISO 8601, and a string must already be one.

untilstring|DateTimeInterface

Only rows before this instant. It has to be later than since:, or the server answers 400 invalid_parameter.

limitint

Page size per request, 1 to 100. The server defaults to 25.

cursorstring

Starts the walk from this cursor instead of the newest row.

apiKeystring

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

Returns

A Generator that yields one change array per step.

Example

foreach ($client->webhooks->iterateWorkspaceActivity() as $change) {    if ($change['type'] === 'removed') {        echo $change['endpointLabel'], ' was removed by ', $change['actor']['label'] ?? 'Nextmail', ' at ', $change['createdAt'], PHP_EOL;    }}

Also available in

API
GET /webhooks/activity
TypeScript
webhooks.iterateWorkspaceActivity()
Python
webhooks.iterate_workspace_activity()
Ruby
webhooks.iterate_workspace_activity
Go
Webhooks.IterateWorkspaceActivity
Java
webhooks().iterateWorkspaceActivity
C#
Webhooks.IterateWorkspaceActivityAsync

webhooks->listEvents

List the events an endpoint can subscribe to

Scopeswebhooks:read
Signature
listEvents(?string $apiKey = null): array

Returns every event an endpoint can name in eventTypes, each with a sentence saying when it fires, and the limits an endpoint is held to: how many endpoints the workspace may have, which its plan decides, and how many addresses and domains one allowlist may name.

An endpoint that names no events receives every email event except email.replied and email.routed, so email.replied and the domain, suppression, file, form, automation, contact, sending, connector, task, approval, booking, broadcast and address families only reach an endpoint that asks for them by name. automation.webhook and email.routed are not in the list, because no endpoint subscribes to them: a webhook step sends automation.webhook to the endpoint the step names, and an address or route sends email.routed to the endpoint it names in webhookId and to the taps of the address.

Parameters

apiKeystring

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

Returns

An array with events, a list of arrays with id and label, then maxEndpoints, maxAddresses and maxDomains.

Example

$catalogue = $client->webhooks->listEvents(); foreach ($catalogue['events'] as $event) {    echo $event['id'], ': ', $event['label'], PHP_EOL;} echo 'Up to ', $catalogue['maxEndpoints'], ' endpoints, each naming up to ', $catalogue['maxAddresses'], ' addresses and ', $catalogue['maxDomains'], ' domains', PHP_EOL;

Notes

  • The same events are the constants of Nextmail\Constants\WebhookEvents, and WebhookEvents::values() lists their ids, so code that only needs the ids can skip the call.

  • Retried automatically on network failure, since it only reads.

Also available in

API
GET /webhooks/events
TypeScript
webhooks.listEvents()
Python
webhooks.list_events()
Ruby
webhooks.list_events
Go
Webhooks.ListEvents
Java
webhooks().listEvents
C#
Webhooks.ListEventsAsync
CLI
nextmail webhooks list-events

webhooks->stats

Read how webhook deliveries went inside a window

Scopeswebhooks:read
Signature
stats(    array|string|null $endpointIds = null,    DateTimeInterface|string|null $since = null,    DateTimeInterface|string|null $until = null,    ?string $grain = null,    ?int $offsetMinutes = null,    ?string $apiKey = null,): array

Returns the numbers behind the Analytics tab of the Webhooks page: how many delivery attempts were made, how many were delivered and how many failed, the median time a receiver took to answer, a series of buckets, the events sent and the response codes received.

It covers every endpoint, or the ones endpointIds: names. Each try of an event counts as one attempt, so an event retried three times counts three times. The window runs from since: to until:, and left out it is the 30 days before now. 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.

Parameters

endpointIdsstring|string[]

Only these endpoints, at most 50, as a list or one comma-separated string. Left out, every endpoint.

sincestring|DateTimeInterface

The start of the window, a DateTimeInterface or an ISO 8601 instant. Defaults to 30 days before until:.

untilstring|DateTimeInterface

The end of the window, not included. Defaults to now.

grainstring

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

offsetMinutesint

Minutes east of UTC to bucket in, from -840 to 840, defaulting to 0. Pass intdiv((new DateTimeImmutable())->getOffset(), 60) for the local zone.

apiKeystring

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

Returns

An array with the window it covered (since, until, grain and endpointIds), totals (attempts, delivered, failed and medianDurationMs), buckets, events and codes.

Example

$stats = $client->webhooks->stats(    since: new \DateTimeImmutable('-7 days'),    grain: 'day',    offsetMinutes: intdiv((new \DateTimeImmutable())->getOffset(), 60),); $totals = $stats['totals']; echo $totals['delivered'], ' of ', $totals['attempts'], ' attempts delivered, median ', $totals['medianDurationMs'] ?? 'n/a', ' ms', PHP_EOL; foreach ($stats['codes'] as $code) {    echo $code['id'], ': ', $code['count'], PHP_EOL;}

Notes

  • buckets is sparse: a bucket with no attempt has no entry, so a chart must fill the gaps.

  • medianDurationMs is null when nothing was sent in the window.

  • Retried automatically on network failure, since it only reads.

Also available in

API
GET /webhooks/stats
TypeScript
webhooks.stats()
Python
webhooks.stats()
Ruby
webhooks.stats
Go
Webhooks.Stats
Java
webhooks().stats
C#
Webhooks.StatsAsync
CLI
nextmail webhooks stats