Zur Dokumentation springen
Go

client.Me

Jede Methode in diesem Namespace: ihre Signatur, ihre Parameter, was sie zurückgibt und ein Beispiel.

Methoden

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

Kein Geltungsbereich
Signatur
Get(ctx context.Context, opts ...openemail.RequestOption) (openemail.Object, error)

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.

Parameter

openemail.WithAPIKeystring

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

Rückgabe

An openemail.Object. For an API key it is an API key self object, with object set to api_key, kind, id, mode, scopes, grantedScopes, roleId, workspaceId, addressAllowlist and domainAllowlist. For an OAuth access token it is an OAuth token self object, with object set to oauth_token, the same fields with id and roleId null, plus clientId and expiresAt.

Beispiel

key, err := client.Me.Get(ctx)if err != nil {	return err} fmt.Println(key.String("mode"), key.String("workspaceId"), key.String("object"))

Hinweise

  • 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 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_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.

Auch verfügbar über

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

Me.Ping

Check that a key or access token authenticates

Kein Geltungsbereich
Signatur
Ping(ctx context.Context, opts ...openemail.RequestOption) (openemail.Object, error)

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

Parameter

openemail.WithAPIKeystring

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

Rückgabe

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

Beispiel

ping, err := client.Me.Ping(ctx)if err != nil {	return err} fmt.Println(ping.String("keyId"))

Hinweise

  • 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 returns an *openemail.Error with status 401, so openemail.ErrAuthentication is the check to make.

Auch verfügbar über

API
GET /ping
TypeScript
me.ping()
Python
me.ping()
Ruby
me.ping
PHP
me->ping
Java
me().ping
C#
Me.PingAsync
CLI
openemail me ping

Me.Rotate

Replace the calling key's own secret

Geltungsbereichekeys:write
Signatur
Rotate(ctx context.Context, opts ...openemail.RequestOption) (openemail.Object, error)

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

Parameter

openemail.WithAPIKeystring

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

Rückgabe

An openemail.Object: the key object 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.

Beispiel

rotated, err := client.Me.Rotate(ctx)if err != nil {	return err} fmt.Println(rotated.Int("rotationCount"), rotated.String("rotatedAt"), rotated.String("token"))

Hinweise

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

Auch verfügbar über

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

Me.ListRequests

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

Kein GeltungsbereichBlättert durch die Ergebnisse
Signatur
ListRequests(ctx context.Context, opts ...openemail.RequestOption) (*openemail.Page, error)

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. openemail.WithFailedOnly, openemail.WithStatusCodes, openemail.WithPath, openemail.WithSince and openemail.WithUntil narrow it, and they combine.

Parameter

openemail.WithFailedOnlybool

Only calls answered with a status of 400 or more.

openemail.WithStatusCodes...int

Only calls answered with one of these HTTP status codes, such as 401 and 403. At most 20, each from 100 to 599, sent comma-separated as status.

openemail.WithPathstring

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

openemail.WithSincetime.Time

Only rows at or after this instant. A time.Time, sent as an ISO 8601 instant.

openemail.WithUntiltime.Time

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

openemail.WithLimitint

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

openemail.WithCursorstring

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

openemail.WithAPIKeystring

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

Rückgabe

A *openemail.Page with Items, HasMore and NextCursor. Each item has id, keyId, keyName, requestId, method, path, status, errorCode, durationMs, ip, userAgent and createdAt.

Beispiel

page, err := client.Me.ListRequests(	ctx,	openemail.WithStatusCodes(429),	openemail.WithSince(time.Date(2026, time.October, 1, 0, 0, 0, 0, time.UTC)),)if err != nil {	return err} for _, request := range page.Items {	fmt.Println(request.String("createdAt"), request.String("method"), request.String("path"), request.Int("status"))} fmt.Println(page.HasMore, page.NextCursor)

Hinweise

  • An OAuth access token is refused with 403 api_key_only. Calls made with one are not logged, so there is nothing to read.

  • openemail.WithPath 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.

Auch verfügbar über

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

Me.ListAllRequests

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

Kein GeltungsbereichBlättert durch die Ergebnisse
Signatur
ListAllRequests(ctx context.Context, opts ...openemail.RequestOption) ([]openemail.Object, error)

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.

Parameter

openemail.WithFailedOnlybool

Only calls answered with a status of 400 or more.

openemail.WithStatusCodes...int

Only calls answered with one of these HTTP status codes, such as 401 and 403. At most 20, each from 100 to 599, sent comma-separated as status.

openemail.WithPathstring

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

openemail.WithSincetime.Time

Only rows at or after this instant. A time.Time, sent as an ISO 8601 instant.

openemail.WithUntiltime.Time

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

openemail.WithLimitint

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

openemail.WithCursorstring

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

openemail.WithAPIKeystring

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

Rückgabe

A []openemail.Object, newest first. Each item has id, keyId, keyName, requestId, method, path, status, errorCode, durationMs, ip, userAgent and createdAt.

Beispiel

failures, err := client.Me.ListAllRequests(	ctx,	openemail.WithFailedOnly(true),	openemail.WithSince(time.Now().Add(-time.Hour)),	openemail.WithLimit(100),)if err != nil {	return err} fmt.Println(len(failures), "failed calls in the last hour")

Hinweise

  • An OAuth access token is refused with 403 api_key_only. Calls made with one are not logged, so there is nothing to read.

Auch verfügbar über

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

Me.IterateRequests

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

Kein GeltungsbereichBlättert durch die Ergebnisse
Signatur
IterateRequests(ctx context.Context, opts ...openemail.RequestOption) *openemail.Iterator

An iterator over Me.ListRequests under the same filters, fetching a page only when the one before is drained.

Parameter

openemail.WithFailedOnlybool

Only calls answered with a status of 400 or more.

openemail.WithStatusCodes...int

Only calls answered with one of these HTTP status codes, such as 401 and 403. At most 20, each from 100 to 599, sent comma-separated as status.

openemail.WithPathstring

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

openemail.WithSincetime.Time

Only rows at or after this instant. A time.Time, sent as an ISO 8601 instant.

openemail.WithUntiltime.Time

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

openemail.WithLimitint

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

openemail.WithCursorstring

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

openemail.WithAPIKeystring

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

Rückgabe

An *openemail.Iterator yielding one call per step.

Beispiel

for request, err := range client.Me.IterateRequests(ctx, openemail.WithPath("/emails"), openemail.WithStatusCodes(422)).All() {	if err != nil {		return err	} 	fmt.Println(request.String("createdAt"), request.String("errorCode"), request.String("requestId"))}

Hinweise

  • An OAuth access token is refused with 403 api_key_only. Calls made with one are not logged, so there is nothing to read.

Auch verfügbar über

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

Me.ListActivity

List one page of what happened to the calling key

Kein GeltungsbereichBlättert durch die Ergebnisse
Signatur
ListActivity(ctx context.Context, opts ...openemail.RequestOption) (*openemail.Page, error)

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.

Parameter

openemail.WithSincetime.Time

Only rows at or after this instant. A time.Time, sent as an ISO 8601 instant.

openemail.WithUntiltime.Time

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

openemail.WithLimitint

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

openemail.WithCursorstring

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

openemail.WithAPIKeystring

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

Rückgabe

A *openemail.Page with Items, HasMore and NextCursor. Each item has id, keyId, keyName, type, createdAt, actor and detail.

Beispiel

page, err := client.Me.ListActivity(ctx)if err != nil {	return err} for _, activity := range page.Items {	fmt.Println(activity.String("createdAt"), activity.String("type"), activity.Object("actor").String("label"), activity.Object("detail").String("source"))} fmt.Println(page.HasMore, page.NextCursor)

Hinweise

  • 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.ListActivity.

Auch verfügbar über

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

Me.ListAllActivity

Collect everything that happened to the calling key into one slice

Kein GeltungsbereichBlättert durch die Ergebnisse
Signatur
ListAllActivity(ctx context.Context, opts ...openemail.RequestOption) ([]openemail.Object, error)

Walks every page of Me.ListActivity under the same window. Use Me.IterateActivity to stop early.

Parameter

openemail.WithSincetime.Time

Only rows at or after this instant. A time.Time, sent as an ISO 8601 instant.

openemail.WithUntiltime.Time

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

openemail.WithLimitint

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

openemail.WithCursorstring

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

openemail.WithAPIKeystring

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

Rückgabe

A []openemail.Object, newest first. Each item has id, keyId, keyName, type, createdAt, actor and detail.

Beispiel

history, err := client.Me.ListAllActivity(ctx)if err != nil {	return err} rotations := 0 for _, activity := range history {	if activity.String("type") == "rotated" {		rotations++	}} fmt.Println(rotations, "rotations")

Hinweise

  • An OAuth access token is refused with 403 api_key_only. Calls made with one are not logged, so there is nothing to read.

Auch verfügbar über

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

Me.IterateActivity

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

Kein GeltungsbereichBlättert durch die Ergebnisse
Signatur
IterateActivity(ctx context.Context, opts ...openemail.RequestOption) *openemail.Iterator

An iterator over Me.ListActivity under the same window, fetching a page only when the one before is drained.

Parameter

openemail.WithSincetime.Time

Only rows at or after this instant. A time.Time, sent as an ISO 8601 instant.

openemail.WithUntiltime.Time

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

openemail.WithLimitint

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

openemail.WithCursorstring

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

openemail.WithAPIKeystring

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

Rückgabe

An *openemail.Iterator yielding one change per step.

Beispiel

for activity, err := range client.Me.IterateActivity(ctx).All() {	if err != nil {		return err	} 	if activity.String("type") == "auth_failed" {		fmt.Println("last refused attempt at", activity.String("createdAt")) 		break	}}

Hinweise

  • An OAuth access token is refused with 403 api_key_only. Calls made with one are not logged, so there is nothing to read.

Auch verfügbar über

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

Me.Stats

Read what the calling key did inside a window

Kein Geltungsbereich
Signatur
Stats(ctx context.Context, opts ...openemail.RequestOption) (openemail.Object, error)

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. Test it with Has first, because the readers of an openemail.Object return zero for a field that is null.

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.

Parameter

openemail.WithSincetime.Time

The start of the window, a time.Time. Defaults to 30 days before until.

openemail.WithUntiltime.Time

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

openemail.WithGrainstring

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

openemail.WithOffsetMinutesint

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

openemail.WithAPIKeystring

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

Rückgabe

An openemail.Object with the window it covered, keyIds holding the id of the key alone, sends or null, rejected, requests, routes and codes.

Beispiel

stats, err := client.Me.Stats(ctx, openemail.WithGrain("hour"), openemail.WithSince(time.Now().Add(-24*time.Hour)))if err != nil {	return err} failed := 0 for _, bucket := range stats.Objects("requests") {	failed += bucket.Int("failed")} fmt.Println(failed, "failed calls today") if stats.Has("sends") {	fmt.Println(stats.Object("sends").Object("totals").Int("sends"), "emails sent")} else {	fmt.Println("this key cannot read its sends")}

Hinweise

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

Auch verfügbar über

API
GET /keys/self/stats
TypeScript
me.stats()
Python
me.stats()
Ruby
me.stats
PHP
me->stats
Java
me().stats
C#
Me.StatsAsync
CLI
openemail me stats