Skip to the documentation
Ruby

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

me.get

Describe the API key or access token making the call

No scope
Signature
get(api_key: nil) -> Hash

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 nil 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 nil, clientId naming the connected app, roleId nil 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 nil when it never does. It is not the expiry of the access token, which the app renews with its refresh token.

Parameters

api_keyString

Describes this key instead of the credential the client was built with.

Returns

A Hash. For an API key it has object set to api_key, kind, id, mode, scopes, grantedScopes, roleId, workspaceId, addressAllowlist and domainAllowlist. For an OAuth access token it has object set to oauth_token, the same fields with id and roleId nil, plus clientId and expiresAt.

Example

key = client.me.get puts key[:mode], key[:workspaceId] removed_by_role = key[:grantedScopes] - key[:scopes]p removed_by_role puts key[:clientId], key[:expiresAt] if key[:object] == "oauth_token"

Notes

  • Narrowing a role takes effect on the next request without touching the key itself, so scopes can shrink between two calls with the same secret. Replacing the secret is a separate act, and me.rotate is the call that does it.

  • roleId is nil 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_key or inactive_api_key for 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_token and the grant_* codes mean the app has to be connected again.

Also available in

API
GET /keys/self
TypeScript
nextmail.me.get()
Python
me.get()
PHP
me->get
Go
Me.Get
Java
me().get
C#
Me.GetAsync
CLI
nextmail me get

me.ping

Check that a key or access token authenticates

No scope
Signature
ping(api_key: nil) -> Hash

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 nil, clientId naming the connected app, roleId nil and mode always live. A key answers kind: "apiKey".

Parameters

api_keyString

Checks this key instead of the credential the client was built with.

Returns

A Hash with ok set to true, kind, keyId, mode, scopes, grantedScopes, roleId and workspaceId, plus clientId for an OAuth access token.

Example

ping = client.me.ping raise "Key #{ping[:keyId]} cannot send mail" unless ping[:scopes].include?("emails:send")

Notes

  • The id is keyId here and id on me.get, and there is no object field on this response, so tell a key from a token by kind.

  • A bad key never returns ok: false. It raises Nextmail::AuthenticationError with status 401, so auth? is the check to make.

Also available in

API
GET /ping
TypeScript
nextmail.me.ping()
Python
me.ping()
PHP
me->ping
Go
Me.Ping
Java
me().ping
C#
Me.PingAsync
CLI
nextmail me ping

me.rotate

Replace the calling key's own secret

Scopeskeys:write
Signature
rotate(api_key: nil) -> Hash

Mints a new secret for the key making the call and returns 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

api_keyString

Rotates this key instead of the one the client was built with.

Returns

The same Hash as me.get 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

rotated = client.me.rotate File.write(".nextmail-key", rotated[:token]) puts rotated[:rotationCount], rotated[:rotatedAt]

Notes

  • It needs keys:write, and a key without it gets 403 insufficient_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 revoked or 409 expired otherwise. None of the three is rotatable, so the answer is a new key from the console.

  • rotationCount is the count after this call, so the first rotation of a key answers 1, and rotatedAt is when that rotation committed.

Also available in

API
POST /keys/self/rotate
TypeScript
nextmail.me.rotate()
Python
me.rotate()
PHP
me->rotate
Go
Me.Rotate
Java
me().rotate
C#
Me.RotateAsync
CLI
nextmail me rotate

me.list_requests

List one page of the calling key's own request log

No scopePages through results
Signature
list_requests(failed_only: nil, statuses: nil, path: nil, since: nil, until: nil, limit: nil, cursor: nil, api_key: nil) -> Nextmail::Page

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.list_requests and keys.list_workspace_requests 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. failed_only:, statuses:, path:, since: and until: narrow it, and they combine.

Parameters

failed_onlyBoolean

Only calls answered with a status of 400 or more.

statusesArray<Integer>

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 as status.

pathString

Only calls to this route, whatever the method, such as /emails or /emails/:id. It matches the route, not the exact path: an id counts as :id and an email address as :address. End it with * to read every route that starts with it, such as /emails/*.

sinceTime, Date or String

Only rows at or after this instant. A Time is sent as ISO 8601 in UTC, and a String must already be ISO 8601.

untilTime, Date or String

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

limitInteger

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

cursorString

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

api_keyString

Reads the log of this key instead of the one the client was built with.

Returns

The Nextmail::Page of Hashes, with items, has_more? and next_cursor. Each item has id, keyId, keyName, requestId, method, path, status, errorCode, durationMs, ip, userAgent and createdAt.

Example

page = client.me.list_requests(statuses: [429], since: "2026-10-01T00:00:00Z") page.items.each do |call|  puts call.values_at(:createdAt, :method, :path, :status).join(" ")end

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.

  • path: matches 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 exact path.

  • 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

API
GET /keys/self/requests
TypeScript
nextmail.me.listRequests()
Python
me.list_requests()
PHP
me->listRequests
Go
Me.ListRequests
Java
me().listRequests
C#
Me.ListRequestsAsync
CLI
nextmail me list-requests

me.list_all_requests

Collect the calling key's whole request log into one array

No scopePages through results
Signature
list_all_requests(failed_only: nil, statuses: nil, path: nil, since: nil, until: nil, limit: nil, cursor: nil, api_key: nil) -> Array<Hash>

Walks every page of me.list_requests 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.iterate_requests to stop early.

Parameters

failed_onlyBoolean

Only calls answered with a status of 400 or more.

statusesArray<Integer>

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 as status.

pathString

Only calls to this route, whatever the method, such as /emails or /emails/:id. It matches the route, not the exact path: an id counts as :id and an email address as :address. End it with * to read every route that starts with it, such as /emails/*.

sinceTime, Date or String

Only rows at or after this instant. A Time is sent as ISO 8601 in UTC, and a String must already be ISO 8601.

untilTime, Date or String

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

limitInteger

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

cursorString

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

api_keyString

Reads the log of this key instead of the one the client was built with, for every page of this walk.

Returns

An Array of Hashes, one per call with the fields me.list_requests returns, newest first.

Example

failures = client.me.list_all_requests(failed_only: true, since: Time.now - (60 * 60), limit: 100) puts "#{failures.size} 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

API
GET /keys/self/requests
TypeScript
nextmail.me.listAllRequests()
Python
me.list_all_requests()
PHP
me->listAllRequests
Go
Me.ListAllRequests
Java
me().listAllRequests
C#
Me.ListAllRequestsAsync

me.iterate_requests

Stream the calling key's own request log one call at a time

No scopePages through results
Signature
iterate_requests(failed_only: nil, statuses: nil, path: nil, since: nil, until: nil, limit: nil, cursor: nil, api_key: nil, &block) -> Enumerator<Hash>

An Enumerator over me.list_requests under the same filters, fetching a page only when the one before is drained. Given a block, it yields each call to the block instead.

Parameters

failed_onlyBoolean

Only calls answered with a status of 400 or more.

statusesArray<Integer>

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 as status.

pathString

Only calls to this route, whatever the method, such as /emails or /emails/:id. It matches the route, not the exact path: an id counts as :id and an email address as :address. End it with * to read every route that starts with it, such as /emails/*.

sinceTime, Date or String

Only rows at or after this instant. A Time is sent as ISO 8601 in UTC, and a String must already be ISO 8601.

untilTime, Date or String

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

limitInteger

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

cursorString

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

api_keyString

Reads the log of this key instead of the one the client was built with, for every page of this walk.

Returns

An Enumerator of Hashes, one call per step (or yields each one to a block).

Example

client.me.iterate_requests(path: "/emails", statuses: [422]) do |call|  puts call.values_at(:createdAt, :errorCode, :requestId).join(" ")end

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

API
GET /keys/self/requests
TypeScript
nextmail.me.iterateRequests()
Python
me.iterate_requests()
PHP
me->iterateRequests
Go
Me.IterateRequests
Java
me().iterateRequests
C#
Me.IterateRequestsAsync

me.list_activity

List one page of what happened to the calling key

No scopePages through results
Signature
list_activity(since: nil, until: nil, limit: nil, cursor: nil, api_key: nil) -> Nextmail::Page

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.list_activity and keys.list_workspace_activity 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 source in detail says where it came from: console, api, mcp or documentation.

Parameters

sinceTime, Date or String

Only rows at or after this instant. A Time is sent as ISO 8601 in UTC, and a String must already be ISO 8601.

untilTime, Date or String

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

limitInteger

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

cursorString

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

api_keyString

Reads the log of this key instead of the one the client was built with.

Returns

The Nextmail::Page of Hashes, with items, has_more? and next_cursor. Each item has id, keyId, keyName, type, createdAt, actor and detail.

Example

page = client.me.list_activity page.items.each do |change|  puts [change[:createdAt], change[:type], change.dig(:actor, :label), change.dig(:detail, :source)].join(" ")end

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 revoked and deleted rows are only ever read by another key, through keys.list_activity.

Also available in

API
GET /keys/self/activity
TypeScript
nextmail.me.listActivity()
Python
me.list_activity()
PHP
me->listActivity
Go
Me.ListActivity
Java
me().listActivity
C#
Me.ListActivityAsync
CLI
nextmail me list-activity

me.list_all_activity

Collect everything that happened to the calling key into one array

No scopePages through results
Signature
list_all_activity(since: nil, until: nil, limit: nil, cursor: nil, api_key: nil) -> Array<Hash>

Walks every page of me.list_activity under the same window. Use me.iterate_activity to stop early.

Parameters

sinceTime, Date or String

Only rows at or after this instant. A Time is sent as ISO 8601 in UTC, and a String must already be ISO 8601.

untilTime, Date or String

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

limitInteger

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

cursorString

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

api_keyString

Reads the log of this key instead of the one the client was built with, for every page of this walk.

Returns

An Array of Hashes, one per change with the fields me.list_activity returns, newest first.

Example

history = client.me.list_all_activity rotations = history.count { |change| change[:type] == "rotated" } puts "#{rotations} 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

API
GET /keys/self/activity
TypeScript
nextmail.me.listAllActivity()
Python
me.list_all_activity()
PHP
me->listAllActivity
Go
Me.ListAllActivity
Java
me().listAllActivity
C#
Me.ListAllActivityAsync

me.iterate_activity

Stream what happened to the calling key one change at a time

No scopePages through results
Signature
iterate_activity(since: nil, until: nil, limit: nil, cursor: nil, api_key: nil, &block) -> Enumerator<Hash>

An Enumerator over me.list_activity under the same window, fetching a page only when the one before is drained. Given a block, it yields each change to the block instead.

Parameters

sinceTime, Date or String

Only rows at or after this instant. A Time is sent as ISO 8601 in UTC, and a String must already be ISO 8601.

untilTime, Date or String

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

limitInteger

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

cursorString

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

api_keyString

Reads the log of this key instead of the one the client was built with, for every page of this walk.

Returns

An Enumerator of Hashes, one change per step (or yields each one to a block).

Example

client.me.iterate_activity do |change|  next unless change[:type] == "auth_failed"   puts "last refused attempt at #{change[:createdAt]}"  breakend

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

API
GET /keys/self/activity
TypeScript
nextmail.me.iterateActivity()
Python
me.iterate_activity()
PHP
me->iterateActivity
Go
Me.IterateActivity
Java
me().iterateActivity
C#
Me.IterateActivityAsync

me.stats

Read what the calling key did inside a window

No scope
Signature
stats(since: nil, until: nil, grain: nil, offset_minutes: nil, api_key: nil) -> Hash

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 nil, 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 offset_minutes: shifts the boundaries so days break where the reader's day does.

Parameters

sinceTime, Date or String

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

untilTime, Date or String

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

grainString

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

offset_minutesInteger

Minutes east of UTC to bucket in, from -840 to 840, defaulting to 0.

api_keyString

Reads the figures of this key instead of the one the client was built with.

Returns

A Hash with the window it covered, keyIds holding the id of the key alone, sends or nil, rejected, requests, routes and codes.

Example

stats = client.me.stats(grain: "hour", since: Time.now - (24 * 60 * 60)) failed = stats[:requests].sum { |bucket| bucket[:failed] } puts "#{failed} failed calls today"puts stats.dig(: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
TypeScript
nextmail.me.stats()
Python
me.stats()
PHP
me->stats
Go
Me.Stats
Java
me().stats
C#
Me.StatsAsync
CLI
nextmail me stats