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","connectionId":"2489E9AD-2EE2-8E00-8EC9-32D5F69181C0"},"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", "connectionId": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0" }, "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 a company connection of the app and needs admin on the project: config.mailbox.connectionId names one of the project’s candidates (GET /v1/connection-choices/candidates), and with none named the project’s only one is stored, several are 409 connection-not-chosen, and none stores nothing; 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 project its API key or session is limited to, else in the workspace’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”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
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
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, a connectionId for a person’s mailbox or naming a person’s own live connection of the app, 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
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}Missing / malformed / expired / revoked bearer token.
object
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}config.mailbox.connectionId isn’t one of the project’s company connections of the app, the same answer as for one that doesn’t exist (connection-not-found, details.field config.mailbox.connectionId).
object
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 company’s mailbox names no connection and the project has several company connections of the app (connection-not-chosen: details.choices lists them, {connectionId, name} sorted by name, and details.field is config.mailbox.connectionId). Or the Idempotency-Key was reused with a different body, or a resource-state conflict. Or idempotency-key-in-flight (with Retry-After): a request with the same Idempotency-Key still runs, so this one wasn’t run; send it again after Retry-After to get that request’s answer.
object
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}Headers
Section titled “Headers”The request body is over the API’s limit (request-too-large; details.maxBytes says how much).
object
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}rate-limit-exceeded with details.limit: "api-requests", on a runtime that sets workspace limits (Kindgi Cloud): this workspace’s limit on API requests a minute is reached, so the request wasn’t run; Retry-After says when to send it again.
object
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}Headers
Section titled “Headers”Server error (unmapped domain code or framework crash).
object
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
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}The Idempotency-Key store (idempotency-store-unavailable) or the authorization store (authz-backend-unavailable) couldn’t be reached before the request ran, or the database was too busy for its authorization check (database-busy), so nothing was changed; Retry-After (whole seconds) says when to try again with the same key. Or tenant-state-unavailable (with Retry-After), on a runtime serving many workspaces: the workspace’s state couldn’t be read, so nothing was changed.
object
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}Headers
Section titled “Headers”See also
GET /v1/mail-triggers: List mail triggers- Error code
authz-backend-unavailable - Error code
bad-input - Error code
connection-not-chosen - Error code
connection-not-found - Error code
database-busy - Error code
idempotency-key-in-flight - Error code
idempotency-store-unavailable - Error code
rate-limit-exceeded - 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
tenant-state-unavailable - Error code
trigger-operation-unsupported - Error code
trigger-owner-cannot-run-target - Every error code