# Connect

> Create hosted connect sessions, read their outcome and start a headless OAuth flow.

URL: https://docs.workwae.com/reference/connect

Guides: [Connect flows](/guides/connect).

| Method | Path | Operation | Scope |
| --- | --- | --- | --- |
| `POST` | `/v1/connect-sessions` | [Create a hosted connect session](#create-a-hosted-connect-session) | `write` |
| `GET` | `/v1/connect-sessions/{sessionId}` | [Read a hosted connect session's outcome](#read-a-hosted-connect-sessions-outcome) | `read` |
| `POST` | `/v1/oauth-authorizations` | [Start a headless OAuth connect](#start-a-headless-oauth-connect) | `write` |

## Create a hosted connect session

`POST /v1/connect-sessions`

TypeScript SDK method: `workwae.connectSessions.create()`

Returns a link to the hosted connect page. Its OAuth sign-ins pass a Continue page naming the tenant and provider, on the API origin or, for a tenant OAuth app that uses the workspace's connect domain (useConnectDomain), on that domain, and must finish in the browser that pressed Continue (an HttpOnly cookie on that origin); a callback in any other browser renders an error page and connects nothing. A sign-in through an app whose connect domain is not active returns to redirectUri with error=connect_domain_inactive. Without redirectUri the owner ends on Workwae's own confirmation page, which needs no allowlist entry; follow the outcome with GET /v1/connect-sessions/{sessionId} or the account.connected event. A failed sign-in returns with status=error and error set to a ConnectErrorCode.

Required scope: `write`.

### Request body (required)

Content type `application/json`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `redirectUri` | string (uri) | no | Example `"https://app.example.com/mail/connected"`. |
| `providers` | ("google" \| "microsoft" \| "imap")[] | no | At least 1 item. Default `["google","microsoft"]`. |
| `microsoftCloud` | "global" \| "gcc-high" \| "dod" \| "china" | no | Default `"global"`. |
| `oauthAppIds` | object | no |  |
| `oauthAppIds.google` | string (uuid) | no | Example `"759730a9-7e43-43f3-a0ee-12805db065e3"`. |
| `oauthAppIds.microsoft` | string (uuid) | no | Example `"64814a3b-7fd8-444a-96ad-3641fd3451c6"`. |
| `externalRef` | string | no | At most 255 characters. Example `"user_42"`. |
| `loginHint` | string (email) | no | At most 320 characters. Example `"ada@example.com"`. |
| `state` | string | no | At most 1024 characters. Example `"opaque-value-you-check-on-return"`. |
| `accountId` | string (uuid) | no | Example `"6f1c2a4e-8b3d-4e5f-9a7b-1c2d3e4f5a6b"`. |
| `options` | object | no |  |
| `options.mailEnabled` | boolean | no |  |
| `options.calendarEnabled` | boolean | no |  |
| `options.contactsEnabled` | boolean | no |  |
| `options.bodyStorage` | "none" \| "cache" \| "full" | no |  |
| `options.mailAccess` | "api" \| "imap" | no |  |
| `options.sharedMailboxesEnabled` | boolean | no |  |
| `options.mailPermissions` | "full" \| "read_send" \| "read" | no |  |
| `mcp` | object | no |  |
| `mcp.scopes` | ("read" \| "write" \| "send")[] | yes | At least 1 item. |
| `mcp.name` | string | no | 1 to 100 characters. Default `"MCP"`. |
| `ttlSeconds` | integer | no | 60 to 86400. Default `3600`. |

### Responses

- **201** OK (application/json, object)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string (uuid) | yes | Example `"c4e6a8b0-1d3f-4a5c-8e7b-9d1f3a5c7e9b"`. |
| `url` | string (uri) | yes | Example `"https://app.example.com/"`. |
| `expiresAt` | string (date-time) | yes | Example `"2026-05-04T09:30:00.000Z"`. |

- **Errors**, by status and `code` (see [Errors](/guides/errors)):
  - 400: `invalid_input`, `invalid_idempotency_key`, `redirect_uri_not_allowed`, `org_connection_account`, `shared_mailbox_account`, `mail_permissions_unsupported`, `storage_unavailable`, `oauth_app_mismatch`, `google_imap_requires_own_app`
  - 401: `unauthenticated`, `api_key_expired`
  - 402: `billing_past_due`
  - 403: `missing_scope`, `role_forbidden`, `account_token_forbidden`, `account_scope_forbidden`, `mcp_only_key`, `plan_limit_storage`, `plan_module_unavailable`
  - 409: `idempotency_key_in_progress`, `account_mismatch`, `mcp_key_limit`
  - 413: `payload_too_large`
  - 422: `idempotency_key_reused`, `unknown_account`, `unknown_oauth_app`
  - 429: `rate_limited`, `too_many_requests`
  - 500: `internal_error`
  - 503: `overloaded`

## Read a hosted connect session's outcome

`GET /v1/connect-sessions/{sessionId}`

TypeScript SDK method: `workwae.connectSessions.get()`

Required scope: `read`.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `sessionId` | path | string (uuid) | yes | Example `"6479c36f-cac9-42db-8efa-f6e3f731ba08"`. |

### Responses

- **200** OK (application/json, object)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string (uuid) | yes | Example `"c4e6a8b0-1d3f-4a5c-8e7b-9d1f3a5c7e9b"`. |
| `status` | "pending" \| "completed" \| "failed" | yes |  |
| `error` | "session_used" \| "session_expired" \| "provider_not_allowed" \| "access_denied" \| "access_token_rejected" \| "provider_error" \| "provider_unavailable" \| "provider_not_configured" \| "unsupported_provider" \| "token_exchange_failed" \| "invalid_client" \| "interaction_required" \| "invalid_grant" \| "missing_refresh_token" \| "scope_denied" \| "identity_failed" \| "identity_unavailable" \| "credential_conflict" \| "credential_missing" \| "delegate_missing" \| "account_exists" \| "account_mismatch" \| "account_not_found" \| "unknown_oauth_app" \| "oauth_app_mismatch" \| "oauth_app_secret_unreadable" \| "google_imap_requires_own_app" \| "unknown_meeting_app" \| "meeting_app_mismatch" \| "meeting_app_secret_unreadable" \| "connect_domain_inactive" \| "consent_failed" \| "consent_required" \| "consent_revoked" \| "consent_unverified" \| "directory_already_connected" \| "directory_mismatch" \| "directory_unavailable" \| "invalid_certificate" \| "invalid_service_account_key" \| "org_connection_not_found" \| "org_connection_secret_unreadable" \| "plan_limit_accounts" \| "plan_required" \| "spend_cap_reached" \| "plan_module_unavailable" \| "connect_grants_nothing" \| "billing_past_due" \| "internal_error" \| null | yes |  |
| `accountId` | string (uuid) \| null | yes | Example `"6f1c2a4e-8b3d-4e5f-9a7b-1c2d3e4f5a6b"`. |
| `email` | string \| null | yes |  |
| `mcpKeyId` | string (uuid) \| null | yes | Example `"0f631a79-440a-4430-8c42-145950e24fef"`. |
| `mcpKeySkipped` | "mcp_key_limit" \| null | yes |  |
| `expiresAt` | string (date-time) | yes | Example `"2026-05-04T09:30:00.000Z"`. |
| `createdAt` | string (date-time) | yes | Example `"2026-05-04T09:30:00.000Z"`. |

- **Errors**, by status and `code` (see [Errors](/guides/errors)):
  - 400: `invalid_input`, `invalid_idempotency_key`
  - 401: `unauthenticated`, `api_key_expired`
  - 403: `missing_scope`, `role_forbidden`, `account_token_forbidden`, `account_scope_forbidden`, `mcp_only_key`
  - 404: `connect_session_not_found`
  - 409: `idempotency_key_in_progress`
  - 413: `payload_too_large`
  - 422: `idempotency_key_reused`
  - 429: `rate_limited`, `too_many_requests`
  - 500: `internal_error`
  - 503: `overloaded`

## Start a headless OAuth connect

`POST /v1/oauth-authorizations`

TypeScript SDK method: `workwae.oauthAuthorizations.create()`

authorizeUrl is a page naming the tenant and the provider, on the API origin or, for a tenant OAuth app that uses the workspace's connect domain (useConnectDomain), on that domain; only its Continue button (a form POST, accepted only from that page's origin or the console's) leads on to the provider. Continuing works once and binds the sign-in to that browser with an HttpOnly cookie scoped to the callback; a callback arriving in any other browser renders an error page and connects nothing, so send the user's own browser to it. A failed sign-in returns with status=error and error set to a ConnectErrorCode.

Required scope: `write`.

### Request body (required)

Content type `application/json`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `provider` | "google" \| "microsoft" | yes |  |
| `redirectUri` | string (uri) | yes | Example `"https://app.example.com/mail/connected"`. |
| `microsoftCloud` | "global" \| "gcc-high" \| "dod" \| "china" | no | Default `"global"`. |
| `oauthAppId` | string (uuid) | no | Example `"c6e11c75-050f-4212-9cff-bddb4fb07e36"`. |
| `externalRef` | string | no | At most 255 characters. Example `"user_42"`. |
| `state` | string | no | At most 1024 characters. Example `"opaque-value-you-check-on-return"`. |
| `accountId` | string (uuid) | no | Example `"6f1c2a4e-8b3d-4e5f-9a7b-1c2d3e4f5a6b"`. |
| `options` | object | no |  |
| `options.mailEnabled` | boolean | no |  |
| `options.calendarEnabled` | boolean | no |  |
| `options.contactsEnabled` | boolean | no |  |
| `options.bodyStorage` | "none" \| "cache" \| "full" | no |  |
| `options.mailAccess` | "api" \| "imap" | no |  |
| `options.sharedMailboxesEnabled` | boolean | no |  |
| `options.mailPermissions` | "full" \| "read_send" \| "read" | no |  |

### Responses

- **200** OK (application/json, object)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `authorizeUrl` | string (uri) | yes | Example `"https://app.example.com/"`. |

- **Errors**, by status and `code` (see [Errors](/guides/errors)):
  - 400: `invalid_input`, `invalid_idempotency_key`, `redirect_uri_not_allowed`, `org_connection_account`, `shared_mailbox_account`, `mail_permissions_unsupported`, `storage_unavailable`, `oauth_app_mismatch`, `oauth_app_secret_unreadable`, `provider_not_configured`, `connect_grants_nothing`, `google_imap_requires_own_app`
  - 401: `unauthenticated`, `api_key_expired`
  - 402: `billing_past_due`
  - 403: `missing_scope`, `role_forbidden`, `account_token_forbidden`, `account_scope_forbidden`, `mcp_only_key`, `plan_limit_storage`, `plan_module_unavailable`
  - 409: `idempotency_key_in_progress`, `connect_domain_inactive`, `account_mismatch`
  - 413: `payload_too_large`
  - 422: `idempotency_key_reused`, `unknown_account`, `unknown_oauth_app`
  - 429: `rate_limited`, `too_many_requests`
  - 500: `internal_error`
  - 503: `overloaded`
