# Connection API Use your app’s backend to call a service approved for the app. Run `smolcloud guide APP_ID` for the endpoints and environment variables in your deployment, or `smolcloud capabilities APP_ID` for JSON. Both commands need **Can administer**. Check `deploymentReady` before calling an endpoint. Each endpoint uses its own deployment token in the `Authorization: Bearer` header. For a personal connection, show the signed-in person the supplied connect link so they can select what to share. Forward `X-Innie-Connector-Context` only from the incoming Smolcloud request. [Set up a connection](service-connectors.md) or [request one for your app](resource-declarations.md). ## Google ### Read a Google file For one file shared with the app, GET `CONNECTOR_GOOGLE_URL` with `CONNECTOR_GOOGLE_TOKEN`. Check the caller’s permission in your backend before serving the file. For a personal file, send the person to `CONNECTOR_GOOGLE_PERSONAL_CONNECT_URL` to choose a file. Then read it from the backend using that person’s request context: ```js export async function readMyGoogleFile(request) { const context = request.headers.get("X-Innie-Connector-Context"); const url = process.env.CONNECTOR_GOOGLE_PERSONAL_URL; const token = process.env.CONNECTOR_GOOGLE_PERSONAL_TOKEN; if (!url || !token) return new Response("Connection not enabled", { status: 503 }); if (!context) return new Response("Sign in first", { status: 403 }); try { const upstream = await fetch(url, { headers: { Authorization: `Bearer ${token}`, "X-Innie-Connector-Context": context, }, redirect: "error", cache: "no-store", signal: AbortSignal.timeout(15000), }); if (!upstream.ok) return new Response("File unavailable", { status: upstream.status }); return new Response(upstream.body, { headers: { "Content-Type": "application/octet-stream", "Content-Disposition": "attachment", "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff", }, }); } catch { return new Response("File temporarily unavailable", { status: 503 }); } } ``` ### Calendars and document drafts [Set up Google](service-connectors.md#google-drive-calendar-and-docs) and request `google.workflow`. Show `CONNECTOR_GOOGLE_WORKFLOW_CONNECT_URL` to the signed-in person. They select calendars and can allow the app to prepare document drafts. Append each path to `CONNECTOR_GOOGLE_WORKFLOW_URL`. Send `CONNECTOR_GOOGLE_WORKFLOW_TOKEN` as a Bearer token and forward the caller’s `X-Innie-Connector-Context`. | Method and suffix | Request | Result | | ----------------- | ------------------------------------------------------ | --------------------------------------------------------- | | GET `/calendars` | None | `{calendars:[{id,name,timeZone,primary}],drafts:boolean}` | | POST `/events` | `{calendar,start,end}` with ISO timestamps and offsets | `{calendar,events:[{id,summary,start,end}],hasMore}` | | POST `/drafts` | `{key:UUID,title,text}` | `{id:UUID,url}`; `url` is the review page for the person | For a draft, keep the same UUID, title and text if you retry the request. Give the returned review URL to the person. The document is created when they select **Create Google Doc**. If creation is uncertain, check Drive before requesting another draft. Removing access stops calendar reads and pending drafts. Documents already created stay in Drive. ## Microsoft OneDrive - **Shared file.** GET `CONNECTOR_MICROSOFT_URL` using `CONNECTOR_MICROSOFT_TOKEN`. Your backend checks who can read the result. - **Personal file.** Show `CONNECTOR_MICROSOFT_PERSONAL_CONNECT_URL` to the person choosing the file. GET `CONNECTOR_MICROSOFT_PERSONAL_URL` using `CONNECTOR_MICROSOFT_PERSONAL_TOKEN` and their incoming `X-Innie-Connector-Context`. ## Slack **Personal channels.** Show `CONNECTOR_SLACK_PERSONAL_CONNECT_URL` so the person can select channels. Use `CONNECTOR_SLACK_PERSONAL_URL` as the base URL, `CONNECTOR_SLACK_PERSONAL_TOKEN` as the Bearer token and the incoming request context on both calls. | Request | Body | Result | | ---------------- | -------------------------- | --------------------------------------- | | GET `/channels` | None | Channels the person selected | | POST `/messages` | `{"channel":"CHANNEL_ID"}` | Recent messages from a selected channel | **Shared bot.** POST JSON to `CONNECTOR_SLACK_URL` using `CONNECTOR_SLACK_TOKEN`. Forward the caller’s context and send an `Idempotency-Key` UUID for the action. The bot acts in channels approved for the app. | Operation | Request body | Result | | --------- | -------------------------------------------------------------- | ----------------------------- | | Read | `{"operation":"read","channel":"CHANNEL_ID"}` | Recent messages and `hasMore` | | Send | `{"operation":"send","channel":"CHANNEL_ID","text":"MESSAGE"}` | Channel and message timestamp | ## External PostgreSQL POST to `CONNECTOR_POSTGRES_URL` with `CONNECTOR_POSTGRES_TOKEN`, the caller’s context and an `Idempotency-Key` UUID. Pass values in the order of the saved query’s parameters. For a query with one region parameter, send `{"params":["UK"]}`. The database uses the shared read-only login. Your app decides who may see the results. The response contains `columns` and `rows`. Each cell is a string or `null`, including numeric and date columns. For a database hosted in Smolcloud, see [Databases and files](data-services.md). ## Handle failures | Response | What to do | | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | 401 or 403 | Check the deployment token, app permission and any required caller context. For a personal connection, check that this person connected and selected the resource. | | 409 | Smolcloud already recorded an action with that key. Check app activity. An operation record alone doesn’t confirm delivery. | | 422 | Check the file or result size. For Slack, inspect `X-Innie-Connector-Error` for a channel, scope or token issue. | | 429 | Wait before retrying. Honour `Retry-After` when present. | | 502 | The connector could not confirm the result. For a Slack send, check the channel before trying again. | For shared Slack and PostgreSQL requests, use one idempotency key per action. Keep that key if the same action is retried. A new key starts a separate action. ## Limits - **Request context:** valid for 30 seconds and up to four uses. - **Google file reads:** one selected file per app and person in personal mode, or one file per app in shared mode. File reads are limited to 10 MiB. - **Google Calendar and Docs:** up to eight calendars per person. An events request covers up to 31 days and returns up to 50 events (512 KiB). If `hasMore` is true, try a narrower time range. A draft takes a title up to 200 characters and text up to 16 KiB. The signed-in person has 10 minutes to review it. Each person can have five pending drafts and request ten new drafts per app per day. Drafts create new documents. - **Shared Slack:** up to eight approved channels, 3,000 UTF-8 bytes per send and up to 15 recent messages or 256 KiB per read. The connector reads a single page of channel history. - **External PostgreSQL:** up to 16 scalar parameters, 64 columns and 500 rows per query. Keep responses under 1 MiB. The statement timeout is five seconds. The whole query operation has eight seconds. - **Shared Slack and PostgreSQL requests:** the connector handles four at once across both services. Each app can record up to 60 connector operations per minute.