# Create a connect session

Create a hosted flow for a user to authorize an integration or enter its API-key credentials.

`POST https://api.smallworld.sh/api/v1/users/:userId/connect-sessions`

## Parameters

| Name | Location | Type | Required | Description |
| --- | --- | --- | --- | --- |
| userId | path | string | Yes | Your application's user ID, URL-encoded. At most 512 characters, with no surrounding whitespace or null bytes. Encode the IDs `.` and `..` as `%2E` and `%2E%2E`: curl sends these as written, but JavaScript's `fetch` removes them even when encoded. |
| integration | body | string | Yes | The key from GET /integrations. |
| redirectUrl | body | string \| null | No | Optional absolute URL, at most 2048 characters. HTTPS is required; HTTP is allowed only for loopback development. No credentials or fragment. |
| requireConfirmation | body | boolean | No | Defaults to false. true holds credentials until your backend confirms the returning signed-in user; requires redirectUrl. |

## Request examples

### curl

```curl
curl --fail-with-body -X POST 'https://api.smallworld.sh/api/v1/users/customer_123/connect-sessions' \
  -H "Authorization: Bearer $SMALLWORLD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "integration": "github",
  "redirectUrl": "https://app.example.com/settings/integrations",
  "requireConfirmation": true
}'
```

### typescript

```typescript
const response = await fetch("https://api.smallworld.sh/api/v1/users/customer_123/connect-sessions", {
  method: "POST",
  headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
  body: JSON.stringify({
  "integration": "github",
  "redirectUrl": "https://app.example.com/settings/integrations",
  "requireConfirmation": true
}),
});
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
const result = await response.json();
```

### python

```python
response = requests.post(
    "https://api.smallworld.sh/api/v1/users/customer_123/connect-sessions",
    headers={"Authorization": f"Bearer {api_key}"},
    json={
  "integration": "github",
  "redirectUrl": "https://app.example.com/settings/integrations",
  "requireConfirmation": True
},
    timeout=30,
)
response.raise_for_status()
result = response.json()
```

## Responses

Returns id, integration, userId, groupId, status, requireConfirmation, nullable redirectUrl/error/connection, expiresAt, createdAt, updatedAt, and nullable completedAt. Exactly one of userId and groupId is set: your user's ID, or your group's ID for a group's session. Status is pending, awaiting_confirmation, completed, failed, expired, or cancelled. A completed connection uses the public connection shape. Only creation returns connectUrl; store it temporarily and send the user's browser there.

### 201 · Pending

A new hosted attempt was created. connectUrl is returned only here; navigate the user's browser to it.

```json
{
  "id": "01995e58-1000-7000-8000-009ea3dcd8fc",
  "integration": "github",
  "userId": "customer_123",
  "groupId": null,
  "status": "pending",
  "requireConfirmation": true,
  "redirectUrl": "https://app.example.com/settings/integrations",
  "error": null,
  "connection": null,
  "expiresAt": "2026-10-10T12:30:00.000Z",
  "createdAt": "2026-10-10T12:00:00.000Z",
  "updatedAt": "2026-10-10T12:00:00.000Z",
  "completedAt": null,
  "connectUrl": "https://api.example.com/api/integrations/connect/one-time-example-token"
}
```

### 400

invalid_request: A parameter or the body is invalid; the message names the problem. Unknown body fields are rejected. integration_invalid_provider: The integration key does not identify an available integration. integration_connection_not_supported: Built-in integrations have authScheme none and do not need a connection. integration_setup_required: An added MCP server needs its setup verified before anyone can connect. The message says what is missing.

#### invalid_request

A parameter or the body is invalid; the message names the problem. Unknown body fields are rejected.

```json
{
  "statusCode": 400,
  "code": "invalid_request",
  "message": "Unknown field: color"
}
```

#### integration_invalid_provider

The integration key does not identify an available integration.

```json
{
  "statusCode": 400,
  "code": "integration_invalid_provider",
  "message": "Unsupported integration provider 'acme'"
}
```

#### integration_connection_not_supported

Built-in integrations have authScheme none and do not need a connection.

```json
{
  "statusCode": 400,
  "code": "integration_connection_not_supported",
  "message": "Web Access is built in and available without a connection; there is nothing to connect"
}
```

#### integration_setup_required

An added MCP server needs its setup verified before anyone can connect. The message says what is missing.

```json
{
  "statusCode": 400,
  "code": "integration_setup_required",
  "message": "This server requires your own OAuth app. Enter its client ID and, if required by the provider, its client secret."
}
```

### 401

authentication_required: The Authorization header is missing or empty. invalid_api_key: The API key is invalid or revoked, or the header doesn't use the Bearer scheme.

#### authentication_required

The Authorization header is missing or empty.

```json
{
  "statusCode": 401,
  "code": "authentication_required",
  "message": "Authentication is required"
}
```

#### invalid_api_key

The API key is invalid or revoked, or the header doesn't use the Bearer scheme.

```json
{
  "statusCode": 401,
  "code": "invalid_api_key",
  "message": "The API key is invalid or revoked"
}
```

### 403

ip_not_allowed: The request came from an address outside the workspace's IP allowlist.

#### ip_not_allowed

The request came from an address outside the workspace's IP allowlist.

```json
{
  "statusCode": 403,
  "code": "ip_not_allowed",
  "message": "The source IP address is not allowed by this account's security settings"
}
```

### 409

integration_disabled: Enable the integration in your workspace before connecting it. integration_setup_required: Complete the integration setup before connecting it.

#### integration_disabled

Enable the integration in your workspace before connecting it.

```json
{
  "statusCode": 409,
  "code": "integration_disabled",
  "message": "GitHub is not enabled for this workspace. Add it under Integrations first."
}
```

#### integration_setup_required

Complete the integration setup before connecting it.

```json
{
  "statusCode": 409,
  "code": "integration_setup_required",
  "message": "Complete the integration setup before users can connect it"
}
```

### 413

request_too_large: The JSON body is larger than 12 MiB. File uploads count toward it, base64 or escaping included.

#### request_too_large

The JSON body is larger than 12 MiB. File uploads count toward it, base64 or escaping included.

```json
{
  "statusCode": 413,
  "code": "request_too_large",
  "message": "The request body is larger than 12 MiB."
}
```

### 415

unsupported_media_type: The request has a body that isn't JSON. Send JSON with Content-Type: application/json, or no body at all.

#### unsupported_media_type

The request has a body that isn't JSON. Send JSON with Content-Type: application/json, or no body at all.

```json
{
  "statusCode": 415,
  "code": "unsupported_media_type",
  "message": "Send the request body as JSON with Content-Type: application/json."
}
```

### 500

internal_error: An unexpected server error.

#### internal_error

An unexpected server error.

```json
{
  "statusCode": 500,
  "code": "internal_error",
  "message": "Internal server error"
}
```

## Notes

- Public user IDs are identifiers from your application, not Smallworld's internal database IDs. Derive them from your authenticated user on your backend.

- An unknown userId is created automatically. A new session cancels earlier pending connection attempts for this user and integration with connect_session_superseded.

- The connection belongs to the user. To connect one account that a whole group shares, use POST /groups/:groupId/connect-sessions.

- Send the user's browser to connectUrl immediately. Treat the link as sensitive; it is returned only on creation.

- The hosted page follows the workspace's current OAuth or API-key setup. Connections apply across the user's sessions in every World that allows the integration.

- Redirect query parameters (connectSessionId, status, and possible error) are hints. Read the session from your backend before relying on them.

- Sessions expire after 30 minutes by default. Use the returned expiresAt. With requireConfirmation, the session waits at awaiting_confirmation before credentials become active.
