Register a mail trigger
const url = 'https://example.com/v1/mail-triggers';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"flowId":"example","flowVersion":"example","agentId":"example","agentVersion":"example","projectId":"2489E9AD-2EE2-8E00-8EC9-32D5F69181C0","runAsServiceAccountId":"example","runAsProject":true,"config":{"mailbox":{"app":"google","as":"company"},"folder":"example","pollSeconds":1,"runsPerHour":1},"label":"example","toolsAllowedUnattended":["example"]}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://example.com/v1/mail-triggers \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "flowId": "example", "flowVersion": "example", "agentId": "example", "agentVersion": "example", "projectId": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0", "runAsServiceAccountId": "example", "runAsProject": true, "config": { "mailbox": { "app": "google", "as": "company" }, "folder": "example", "pollSeconds": 1, "runsPerHour": 1 }, "label": "example", "toolsAllowedUnattended": [ "example" ] }'Each new mail in the mailbox’s folder starts a run of the trigger’s agent or flow, with the mail as the run’s input, as the trigger’s owner. A trigger on a person’s mailbox (config.mailbox.as: person) reads the caller’s own mail through their connection, so the caller owns it: it needs write on the project, and a service account can’t own it. One on the company’s mailbox (company) reads it through the company’s connection and needs admin on the project; runAsServiceAccountId makes it shared, owned by that service account (which needs act_as on it), and runAsProject makes it shared, owned by the project’s own account (made the first time, with the editor role on the project). Both need execute on what it runs. A trigger that names no projectId goes in the tenant’s Default project. In its runs, every call that changes something, or uses the run’s own mailbox, waits for a person’s yes, unless toolsAllowedUnattended names it: naming it takes admin on the project, each id must be a tool the target calls, and it’s audited (trigger-tools-allowed-unattended-set).
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Header Parameters
Section titled “Header Parameters”Caller-supplied idempotency key, scoped to the caller: the same key from someone else in the tenant is their own request (from 0.1.5). Retries with the same key return the original response byte-identical (per docs/API-ROUTE-CONVENTIONS.md §3.1). A retry sent while the first request still runs is answered 409 idempotency-key-in-flight with Retry-After, on a runtime whose store holds keys (from 0.1.5); retry after it, and you get the first request’s answer. An answer that carries a secret (a new API key or public run token, a session token, a generated signing secret) isn’t kept: a retry gets 409 idempotency-key-replay-withheld, with the first request’s status and when it succeeded (from 0.1.5). A request whose key store can’t be read before it runs is answered 503 idempotency-store-unavailable with Retry-After: nothing ran, so retry with the same key (from 0.3.0).
Request Bodyrequired
Section titled “Request Bodyrequired”Name what it runs: flowId with flowVersion, or agentId (with an optional agentVersion). Its runs’ input is the mail, so it takes none. A trigger on a person’s mailbox reads the caller’s own mail and is theirs: it needs write on the project. One on the company’s mailbox needs admin on the project. Both need execute on what it runs.
object
Run a flow (with flowVersion).
Run an agent (instead of a flow): at agentVersion, else its live version.
The trigger’s project. Absent → the tenant’s default project.
On the company’s mailbox only: a service account that owns the trigger, so it’s shared, named by id instead of the caller. Needs act_as on that account, which a tenant admin holds, and the account must itself hold the access the target needs. With an authorization store, that’s checked when the account is named, and again when the trigger’s target changes: an account that can’t is refused (409 trigger-owner-cannot-run-target). Not a project’s own account (409 service-account-project-owned: name it with runAsProject). Absent: the caller owns it.
On the company’s mailbox only. true: the trigger’s runs act as its project’s own service account, made the first time with the editor role on the project, so it’s shared. It runs only what the project’s editors can. With an authorization store, that’s checked when it’s named, and again when the trigger’s target changes: if it can’t run the target, the request is refused (409 trigger-owner-cannot-run-target). Takes admin on the trigger’s project, as the company’s mailbox does (without an authorization store, a tenant-admin key), not act_as. Not with runAsServiceAccountId, on a person’s mailbox, or without a project (400). A runtime that can’t make the account answers 501 trigger-operation-unsupported. false or absent: as runAsServiceAccountId says.
A new mail trigger’s mailbox, folder and pace.
object
The mailbox a mail trigger reads: its app (google: Gmail; microsoft: Outlook) and whose it is (company: the company’s mailbox, through the company’s connection of that app; person: the trigger owner’s own, through their connection).
object
The Gmail label id, or the Outlook folder id or well-known name, it watches. Absent: the inbox.
How often it looks for new mail, in seconds (default 60).
The most runs its mail starts in an hour (default 60). Past it, a mail’s fire is refused (detail starts over-limit:), and that mail doesn’t run later.
The tools whose calls in this trigger’s runs needn’t wait for a person’s yes. Naming it, [] included, takes admin on the trigger’s project. Each tool by its id, with no wildcard or pattern, and only tools this trigger’s flow or agent calls. It lifts only that wait: the tenant’s approval rules, the agent’s own rules, the permission check (as the trigger’s owner) and the tool’s own limits all still apply.
Responses
Section titled “Responses”Mail trigger registered.
A mail trigger: each new mail in its mailbox’s folder starts a run of its agent or flow, with the mail as the run’s input, as its owner. In such a run, every call that changes something, or uses the run’s own mailbox, waits for a person’s yes unless the trigger lists it (toolsAllowedUnattended).
object
Run a flow (with flowVersion).
Run an agent (instead of a flow): at agentVersion, else its live version.
The trigger’s project: its runs are this project’s.
Who its runs act as, with their connections. A service account owns a shared trigger, on the company’s mailbox: one named with runAsServiceAccountId, or the project’s own (runAsProject, isProjectAccount). A person owns a personal one: every trigger on a person’s mailbox, and one on the company’s mailbox registered without either. No edit moves it; only a take-over (POST …/owner) does.
object
The owner’s name at the time of the response: the person’s display name, or the service account’s name. Absent when it can’t be read (no directory, a removed account) and from a runtime before Kindgi 0.1.6: show the id then.
Set when the owner is the trigger’s project’s own service account (runAsProject): the trigger is shared, and runs as the project. Show it as “This project”. Absent otherwise.
The mailbox a mail trigger reads: its app (google: Gmail; microsoft: Outlook) and whose it is (company: the company’s mailbox, through the company’s connection of that app; person: the trigger owner’s own, through their connection).
object
The Gmail label id, or the Outlook folder id or well-known name, it watches. Absent: the inbox.
How often it looks for new mail, in seconds (default 60).
The most runs its mail starts in an hour (default 60). Past it, a mail’s fire is refused (detail starts over-limit:), and that mail doesn’t run later.
Lifecycle status. Only active triggers fire. Tombstoned rows are excluded from every read path.
Why it isn’t polling as it should: connection-missing (the mailbox’s connection is gone or lapsed; polls go on, and work again once it’s back), owner-refused (its owner was removed or may no longer run the target; polls go on and read nothing until that changes or an admin takes it over), or why the runtime paused it.
The trigger’s newest version (GET …/versions): one more for each change to what it runs, when, as whom or with what. Absent until its first version.
The mailbox’s account at its last poll: the connection’s account id and its label (the address). Absent before its first poll.
object
When it last polled the mailbox and got an answer.
The tools whose calls in this trigger’s runs don’t wait for a person’s yes, though a run a mail started asks for one for every call that changes something or uses its mailbox. Absent: none. Each tool by its id, with no wildcard or pattern, and only tools this trigger’s flow or agent calls. It lifts only that wait: the tenant’s approval rules, the agent’s own rules, the permission check (as the trigger’s owner) and the tool’s own limits all still apply.
Example
{ "owner": { "kind": "user", "isProjectAccount": true }, "mailbox": { "app": "google", "as": "company" }, "status": "active"}A body that fails validation (bad-input): no target or two, a config with anything but mailbox, folder, pollSeconds and runsPerHour, a service account named or calling or runAsProject for a person’s mailbox, or runAsProject with runAsServiceAccountId or with no project. Or reference-out-of-scope: what it runs isn’t the project’s to reach (details.issues, at /target), and nothing is registered.
object
object
Stable machine-readable discriminant. Values match domain error codes (see docs/API-ROUTE-CONVENTIONS.md §4.3).
Optional, kind-specific.
object
Server-assigned request id; also echoed via X-Request-Id header.
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}Missing / malformed / expired / revoked bearer token.
object
object
Stable machine-readable discriminant. Values match domain error codes (see docs/API-ROUTE-CONVENTIONS.md §4.3).
Optional, kind-specific.
object
Server-assigned request id; also echoed via X-Request-Id header.
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}runAsServiceAccountId names an unregistered account (service-account-unregistered), a project’s own account (service-account-project-owned: name it with runAsProject), or one that can’t run what the trigger runs (trigger-owner-cannot-run-target). Or, with runAsProject, the project’s own account can’t run what the trigger runs either (trigger-owner-cannot-run-target; the account stays, for the next runAsProject), or an active account someone made already has the project account’s name, project-<projectId> (service-account-name-taken: a tenant admin can unregister it). Or the Idempotency-Key was reused with a different body, or a resource-state conflict.
object
object
Stable machine-readable discriminant. Values match domain error codes (see docs/API-ROUTE-CONVENTIONS.md §4.3).
Optional, kind-specific.
object
Server-assigned request id; also echoed via X-Request-Id header.
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}The request body is over the API’s limit (request-too-large; details.maxBytes says how much).
object
object
Stable machine-readable discriminant. Values match domain error codes (see docs/API-ROUTE-CONVENTIONS.md §4.3).
Optional, kind-specific.
object
Server-assigned request id; also echoed via X-Request-Id header.
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}Server error (unmapped domain code or framework crash).
object
object
Stable machine-readable discriminant. Values match domain error codes (see docs/API-ROUTE-CONVENTIONS.md §4.3).
Optional, kind-specific.
object
Server-assigned request id; also echoed via X-Request-Id header.
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}trigger-operation-unsupported: runAsProject on a runtime that can’t make a project’s own account.
object
object
Stable machine-readable discriminant. Values match domain error codes (see docs/API-ROUTE-CONVENTIONS.md §4.3).
Optional, kind-specific.
object
Server-assigned request id; also echoed via X-Request-Id header.
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}The Idempotency-Key store couldn’t be read before the request ran (idempotency-store-unavailable), so nothing was changed; Retry-After (whole seconds) says when to try again with the same key.
object
object
Stable machine-readable discriminant. Values match domain error codes (see docs/API-ROUTE-CONVENTIONS.md §4.3).
Optional, kind-specific.
object
Server-assigned request id; also echoed via X-Request-Id header.
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}See also
GET /v1/mail-triggers: List mail triggers- Error code
bad-input - Error code
idempotency-store-unavailable - Error code
reference-out-of-scope - Error code
request-too-large - Error code
service-account-name-taken - Error code
service-account-project-owned - Error code
service-account-unregistered - Error code
trigger-operation-unsupported - Error code
trigger-owner-cannot-run-target - Every error code