nextmail.me
Every method in this namespace: its signature, its parameters, what it returns and an example.
Methods
The API key or OAuth access token behind the client: its mode, scopes, role ceiling and workspace, and for a key its own request log, activity and stats.
nextmail.me.get()
Describe the API key or access token making the call
get(options?: RequestScope): Promise<KeyResource>Returns what the key is: its id, whether it is a live or test key, the workspace it belongs to, the scopes it can use and the allowlists that narrow who it may send as. It needs no scope, because a key may always describe itself, so it works with any valid key and is the first call to make when a request is refused.
scopes is the effective list and the only one that authorises anything. It is the scopes the key was created with intersected with the permissions of the role it was issued under, resolved on every request rather than frozen into the key. grantedScopes is what the key was created holding and roleId names the role that capped it, so a scope present in grantedScopes and missing from scopes was removed by that role. A 403 insufficient_scope on a key the console shows as holding the scope is almost always this, and the fix is to change the role rather than to mint another key.
A key can be narrowed by whole domains, by individual addresses, or by both. domainAllowlist holds whole domains, and the key may send as any address on one of them, including addresses created after the key was. addressAllowlist holds individual addresses and covers only those. Both null means the key may send as any address the workspace owns. When either is set the key is narrowed, and reads of sent mail, tracking and calendar narrow to the same set. An address whose domain is already in domainAllowlist is dropped from addressAllowlist when the key is saved, so the two lists never overlap.
Called with an OAuth access token it describes the token instead, and object tells the two apart. A key answers object: 'api_key' and kind: 'apiKey'. A token answers object: 'oauth_token' and kind: 'oauth', with id null, clientId naming the connected app, roleId null and mode always live. scopes and grantedScopes are the permissions the person approved for the app, and the allowlists are the addresses and domains the app may reach. expiresAt is when that approval runs out, or null when it never does. It is not the expiry of the access token, which the app renews with its refresh token.
Parameters
options.signalAbortSignalCancels the request.
options.apiKeystringDescribes this key instead of the credential the client was built with.
Returns
KeyResource. For an API key it is ApiKeySelfResource, with object set to api_key, kind, id, mode, scopes, grantedScopes, roleId, workspaceId, addressAllowlist and domainAllowlist. For an OAuth access token it is OauthTokenSelfResource, with object set to oauth_token, the same fields with id and roleId null, plus clientId and expiresAt.
Example
const key = await nextmail.me.get() console.log(key.mode, key.workspaceId) const removedByRole = key.grantedScopes.filter((scope) => !key.scopes.includes(scope)) console.log(removedByRole) if (key.object === 'oauth_token') console.log(key.clientId, key.expiresAt)Notes
Narrowing a role takes effect on the next request without touching the key itself, so
scopescan shrink between two calls with the same secret. Replacing the secret is a separate act, andme.rotateis the call that does it.roleIdis null on a key with no ceiling, which is what every key issued before roles existed still has.A failure here is a 401 naming the credential problem:
missing_api_key,invalid_api_key,revoked_api_key,expired_api_keyorinactive_api_keyfor a key switched off in the console.An access token that has run out is a 401
expired_access_token, which the app answers by renewing it with its refresh token.invalid_access_tokenand thegrant_*codes mean the app has to be connected again.
Also available in
- API
GET /keys/self- Python
me.get()- Ruby
me.get- PHP
me->get- Go
Me.Get- Java
me().get- C#
Me.GetAsync- CLI
openemail me get
nextmail.me.ping()
Check that a key or access token authenticates
ping(options?: RequestScope): Promise<PingResource>An authentication smoke test. It runs the same key check every other endpoint runs and answers ok: true with the key id, its mode, the workspace and the effective scopes. It needs no scope, so a key with none at all still gets a 200.
Use it in a health check or at process start to fail fast on a revoked, expired or mistyped key. The answer carries the same scope detail as me.get, scopes effective and grantedScopes as created with roleId naming the cap between them, but it leaves out both allowlists. Call me.get when you need to know which domains and which addresses the key may send as.
An OAuth access token gets the same answer with kind: 'oauth', keyId null, clientId naming the connected app, roleId null and mode always live. A key answers kind: 'apiKey'.
Parameters
options.signalAbortSignalCancels the request.
options.apiKeystringChecks this key instead of the credential the client was built with.
Returns
PingResource with ok set to true, kind, keyId, mode, scopes, grantedScopes, roleId and workspaceId, plus clientId for an OAuth access token.
Example
const ping = await nextmail.me.ping() if (!ping.scopes.includes('emails:send')) { throw new Error(`Key ${ping.keyId} cannot send mail`)}Notes
The id is
keyIdhere andidonme.get, and there is noobjectfield on this response, so tell a key from a token bykind.A bad key never resolves with
ok: false. It throws anNextmailApiErrorwith status 401, soisAuthis the check to make.
Also available in
- API
GET /ping- Python
me.ping()- Ruby
me.ping- PHP
me->ping- Go
Me.Ping- Java
me().ping- C#
Me.PingAsync- CLI
openemail me ping
nextmail.me.rotate()
Replace the calling key's own secret
rotate(options?: RequestScope): Promise<RotatedKeyResource>Mints a new secret for the key making the call and resolves with the same body as me.get plus token, the new key in full. That is the only place the value appears, so store it before anything else.
Everything else about the key survives. The id, the mode, the scopes, the role ceiling, the address allowlist and the domain allowlist all come back unchanged, so token is the only thing your configuration has to change. Because the id is stable, an audit trail joined on it stays joined up across rotations.
There is no overlap window. The old secret stops authenticating the moment this call commits, and neither secret can be shown again. Write token to wherever the key is read from before the next request. A lost response is the bad case: the rotation may have committed to a secret nobody saw, which leaves the key unusable until someone mints it a new secret in the console.
Parameters
options.signalAbortSignalCancels the request.
options.apiKeystringRotates this key instead of the one the client was built with.
Returns
RotatedKeyResource: the KeyResource body plus token, the new key formatted oe_live_ or oe_test_ then the 24 character key id, an underscore and 43 base64url characters, plus rotationCount and rotatedAt.
Example
const rotated = await nextmail.me.rotate() console.log(rotated.rotationCount, rotated.rotatedAt) const check = await nextmail.me.get({ apiKey: rotated.token }) console.log(check.id, check.scopes)Notes
It needs
keys:write, and a key without it gets 403insufficient_scope. No key holds that scope unless somebody gave it one in the console, so a key that cannot reach this call has to be rotated from there.There is no request body and the success status is 200, not 201.
Not retried automatically. Repeating a rotation would invalidate the secret the first attempt returned, so a failure has to be judged rather than retried.
The 404 and the two 409s are races rather than everyday answers, because a key that is missing, revoked or expired cannot authenticate this call in the first place. They mean the key changed state between authenticating and rotating: 404 if the row went, 409
revokedor 409expiredotherwise. None of the three is rotatable, so the answer is a new key from the console.rotationCountis the count after this call, so the first rotation of a key answers 1, androtatedAtis when that rotation committed.
Also available in
- API
POST /keys/self/rotate- Python
me.rotate()- Ruby
me.rotate- PHP
me->rotate- Go
Me.Rotate- Java
me().rotate- C#
Me.RotateAsync- CLI
openemail me rotate
nextmail.me.listRequests()
List one page of the calling key's own request log
listRequests(options?: ApiKeyRequestListOptions): Promise<Page<ApiKeyRequestResource>>Returns one page of the calls the key making the request made, newest first. It needs no scope: a key may always read its own log, and it reads no other key's here. keys.listRequests and keys.listWorkspaceRequests are the ones that reach other keys, behind keys:read.
The request log records every authenticated call the key made: method, path, status, error code, duration, IP and user agent, and never a body or a query string. Nothing is pruned, so the log reaches back to the key's first call, and it runs straight through a rotation because it hangs off the key id. failedOnly, statuses, path, since and until narrow it, and they combine.
Parameters
options.failedOnlybooleanOnly calls answered with a status of 400 or more.
options.statusesArray<number>Only calls answered with one of these HTTP status codes, such as
[401, 403]. At most 20, each from 100 to 599, sent comma-separated asstatus.options.pathstringOnly calls to this route, whatever the method, such as
/emailsor/emails/:id. It matches the route, not the exact path: an id counts as:idand an email address as:address. End it with*to read every route that starts with it, such as/emails/*.options.sinceDate | stringOnly rows at or after this instant. A
Dateis sent as ISO 8601, and a string must already be one.options.untilDate | stringOnly rows before this instant. It has to be later than
since, or the server answers 400invalid_parameter.options.limitnumberRows per page, a whole number from 1 to 100. The server defaults to 25.
options.cursorstringThe
nextCursorfrom the previous page, passed back unchanged. Never build one yourself.options.signalAbortSignalCancels the request.
options.apiKeystringReads the log of this key instead of the one the client was built with.
Returns
Page<ApiKeyRequestResource> with items, hasMore and nextCursor. Each item has id, keyId, keyName, requestId, method, path, status, errorCode, durationMs, ip, userAgent and createdAt.
Example
const page = await nextmail.me.listRequests({ statuses: [429], since: '2026-10-01T00:00:00Z' }) for (const call of page.items) console.log(call.createdAt, call.method, call.path, call.status)Notes
An OAuth access token is refused with 403
api_key_only. Calls made with one are not logged, so there is nothing to read.pathmatches the route rather than the exact path, because the log folds ids and addresses: every call to/emails/<id>is the one route/emails/:id. Each row still carries the exactpath.The call that reads the log is logged too.
The cursor is opaque and stays valid under the same filters. One this log did not hand out is a 400
invalid_cursor.
Also available in
nextmail.me.listAllRequests()
Collect the calling key's whole request log into one array
listAllRequests(options?: ApiKeyRequestListOptions): Promise<Array<ApiKeyRequestResource>>Walks every page of me.listRequests under the same filters. The log is never pruned, so give it a window unless you mean to read the key's whole history, or use me.iterateRequests to stop early.
Parameters
options.failedOnlybooleanOnly calls answered with a status of 400 or more.
options.statusesArray<number>Only calls answered with one of these HTTP status codes, such as
[401, 403]. At most 20, each from 100 to 599, sent comma-separated asstatus.options.pathstringOnly calls to this route, whatever the method, such as
/emailsor/emails/:id. It matches the route, not the exact path: an id counts as:idand an email address as:address. End it with*to read every route that starts with it, such as/emails/*.options.sinceDate | stringOnly rows at or after this instant. A
Dateis sent as ISO 8601, and a string must already be one.options.untilDate | stringOnly rows before this instant. It has to be later than
since, or the server answers 400invalid_parameter.options.limitnumberPage size per request, 1 to 100. The server defaults to 25.
options.cursorstringStarts the walk from this cursor instead of the newest row.
options.signalAbortSignalCancels the walk between pages and the request in flight.
options.apiKeystringReads the log of this key instead of the one the client was built with, for every page of this walk.
Returns
Array<ApiKeyRequestResource>, newest first. Each item has id, keyId, keyName, requestId, method, path, status, errorCode, durationMs, ip, userAgent and createdAt.
Example
const failures = await nextmail.me.listAllRequests({ failedOnly: true, since: new Date(Date.now() - 60 * 60 * 1000), limit: 100 }) console.log(failures.length, 'failed calls in the last hour')Notes
An OAuth access token is refused with 403
api_key_only. Calls made with one are not logged, so there is nothing to read.
Also available in
nextmail.me.iterateRequests()
Stream the calling key's own request log one call at a time
iterateRequests(options?: ApiKeyRequestListOptions): AsyncGenerator<ApiKeyRequestResource, void, undefined>An async generator over me.listRequests under the same filters, fetching a page only when the one before is drained.
Parameters
options.failedOnlybooleanOnly calls answered with a status of 400 or more.
options.statusesArray<number>Only calls answered with one of these HTTP status codes, such as
[401, 403]. At most 20, each from 100 to 599, sent comma-separated asstatus.options.pathstringOnly calls to this route, whatever the method, such as
/emailsor/emails/:id. It matches the route, not the exact path: an id counts as:idand an email address as:address. End it with*to read every route that starts with it, such as/emails/*.options.sinceDate | stringOnly rows at or after this instant. A
Dateis sent as ISO 8601, and a string must already be one.options.untilDate | stringOnly rows before this instant. It has to be later than
since, or the server answers 400invalid_parameter.options.limitnumberPage size per request, 1 to 100. The server defaults to 25.
options.cursorstringStarts the walk from this cursor instead of the newest row.
options.signalAbortSignalCancels the request in flight and ends the iteration.
options.apiKeystringReads the log of this key instead of the one the client was built with, for every page of this walk.
Returns
AsyncGenerator<ApiKeyRequestResource, void, undefined> yielding one call per step.
Example
for await (const call of nextmail.me.iterateRequests({ path: '/emails', statuses: [422] })) { console.log(call.createdAt, call.errorCode, call.requestId)}Notes
An OAuth access token is refused with 403
api_key_only. Calls made with one are not logged, so there is nothing to read.
Also available in
nextmail.me.listActivity()
List one page of what happened to the calling key
listActivity(options?: ApiKeyActivityListOptions): Promise<Page<ApiKeyActivityResource>>Returns one page of the audit log of the key making the request, newest first. It needs no scope, and it reads no other key's history: keys.listActivity and keys.listWorkspaceActivity do that, behind keys:read.
Every change to the key is a row: created, updated, rotated, deactivated and reactivated, plus auth_failed for every call that presented the key and was refused. actor names who made the change, a person as @username or a key as API key <name> in label, and detail.source says where it came from: console, api, mcp or documentation.
Parameters
options.sinceDate | stringOnly rows at or after this instant. A
Dateis sent as ISO 8601, and a string must already be one.options.untilDate | stringOnly rows before this instant. It has to be later than
since, or the server answers 400invalid_parameter.options.limitnumberRows per page, a whole number from 1 to 100. The server defaults to 25.
options.cursorstringThe
nextCursorfrom the previous page, passed back unchanged. Never build one yourself.options.signalAbortSignalCancels the request.
options.apiKeystringReads the log of this key instead of the one the client was built with.
Returns
Page<ApiKeyActivityResource> with items, hasMore and nextCursor. Each item has id, keyId, keyName, type, createdAt, actor and detail.
Example
const page = await nextmail.me.listActivity() for (const change of page.items) console.log(change.createdAt, change.type, change.actor?.label, change.detail.source)Notes
An OAuth access token is refused with 403
api_key_only. Calls made with one are not logged, so there is nothing to read.A revoked or deleted key cannot authenticate, so
revokedanddeletedrows are only ever read by another key, throughkeys.listActivity.
Also available in
nextmail.me.listAllActivity()
Collect everything that happened to the calling key into one array
listAllActivity(options?: ApiKeyActivityListOptions): Promise<Array<ApiKeyActivityResource>>Walks every page of me.listActivity under the same window. Use me.iterateActivity to stop early.
Parameters
options.sinceDate | stringOnly rows at or after this instant. A
Dateis sent as ISO 8601, and a string must already be one.options.untilDate | stringOnly rows before this instant. It has to be later than
since, or the server answers 400invalid_parameter.options.limitnumberPage size per request, 1 to 100. The server defaults to 25.
options.cursorstringStarts the walk from this cursor instead of the newest row.
options.signalAbortSignalCancels the walk between pages and the request in flight.
options.apiKeystringReads the log of this key instead of the one the client was built with, for every page of this walk.
Returns
Array<ApiKeyActivityResource>, newest first. Each item has id, keyId, keyName, type, createdAt, actor and detail.
Example
const history = await nextmail.me.listAllActivity() const rotations = history.filter((change) => change.type === 'rotated') console.log(rotations.length, 'rotations')Notes
An OAuth access token is refused with 403
api_key_only. Calls made with one are not logged, so there is nothing to read.
Also available in
nextmail.me.iterateActivity()
Stream what happened to the calling key one change at a time
iterateActivity(options?: ApiKeyActivityListOptions): AsyncGenerator<ApiKeyActivityResource, void, undefined>An async generator over me.listActivity under the same window, fetching a page only when the one before is drained.
Parameters
options.sinceDate | stringOnly rows at or after this instant. A
Dateis sent as ISO 8601, and a string must already be one.options.untilDate | stringOnly rows before this instant. It has to be later than
since, or the server answers 400invalid_parameter.options.limitnumberPage size per request, 1 to 100. The server defaults to 25.
options.cursorstringStarts the walk from this cursor instead of the newest row.
options.signalAbortSignalCancels the request in flight and ends the iteration.
options.apiKeystringReads the log of this key instead of the one the client was built with, for every page of this walk.
Returns
AsyncGenerator<ApiKeyActivityResource, void, undefined> yielding one change per step.
Example
for await (const change of nextmail.me.iterateActivity()) { if (change.type === 'auth_failed') { console.log('last refused attempt at', change.createdAt) break }}Notes
An OAuth access token is refused with 403
api_key_only. Calls made with one are not logged, so there is nothing to read.
Also available in
nextmail.me.stats()
Read what the calling key did inside a window
stats(options?: KeySelfStatsOptions): Promise<KeySelfStatsResource>Returns the figures of the key making the request: the requests it made and how many failed, the calls refused because its secret was wrong, revoked or expired, the routes it called most with the median time each took, and the status codes it got back. It needs no scope, and it reads no other key's figures: keys.stats does that.
sends, the mail the key sent and what became of it, is filled only when the key holds emails:read. Without that scope it is null, never zeros, so a missing permission cannot read as a quiet week.
The window runs from since to until, and left out it is the 30 days before now. grain sets the bucket width of the series and offsetMinutes shifts the boundaries so days break where the reader's day does.
Parameters
options.sinceDate | stringThe start of the window, a
Dateor an ISO 8601 instant. Defaults to 30 days beforeuntil.options.untilDate | stringThe end of the window, not included. Defaults to now.
options.grainTrackingGrainBucket width:
minute,hourorday, defaulting today.options.offsetMinutesnumberMinutes east of UTC to bucket in, from -840 to 840, defaulting to 0.
options.signalAbortSignalCancels the request.
options.apiKeystringReads the figures of this key instead of the one the client was built with.
Returns
KeySelfStatsResource with the window it covered, keyIds holding the id of the key alone, sends or null, rejected, requests, routes and codes.
Example
const stats = await nextmail.me.stats({ grain: 'hour', since: new Date(Date.now() - 24 * 60 * 60 * 1000) }) const failed = stats.requests.reduce((sum, bucket) => sum + bucket.failed, 0) console.log(failed, 'failed calls today')console.log(stats.sends?.totals.sends ?? 'this key cannot read its sends')Notes
An OAuth access token is refused with 403
api_key_only. Calls made with one are not logged, so there is nothing to read.The series are sparse: a bucket with nothing in it has no entry, so a chart must fill the gaps.
Retried automatically on network failure, since it only reads.
Also available in
- API
GET /keys/self/stats- Python
me.stats()- Ruby
me.stats- PHP
me->stats- Go
Me.Stats- Java
me().stats- C#
Me.StatsAsync- CLI
openemail me stats