# Get a connect session

Read the authoritative state of a user's or a group's hosted connection attempt.

`GET https://api.smallworld.sh/api/v1/connect-sessions/:id`

## Parameters

| Name | Location | Type | Required | Description |
| --- | --- | --- | --- | --- |
| id | path | UUID | Yes | The connect-session ID returned when the session was created. |

## Request examples

### curl

```curl
curl --fail-with-body -X GET 'https://api.smallworld.sh/api/v1/connect-sessions/01995e58-1000-7000-8000-009ea3dcd8fc' \
  -H "Authorization: Bearer $SMALLWORLD_API_KEY"
```

### typescript

```typescript
const response = await fetch("https://api.smallworld.sh/api/v1/connect-sessions/01995e58-1000-7000-8000-009ea3dcd8fc", {
  method: "GET",
  headers: { Authorization: `Bearer ${apiKey}` },
});
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
const result = await response.json();
```

### python

```python
response = requests.get(
    "https://api.smallworld.sh/api/v1/connect-sessions/01995e58-1000-7000-8000-009ea3dcd8fc",
    headers={"Authorization": f"Bearer {api_key}"},
    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.

### 200 · Pending

The user has not completed the hosted flow, or credential exchange is still in progress.

```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
}
```

### 200 · Awaiting confirmation

Credentials are held until your backend confirms the authenticated returning user, or the group for a group's session.

```json
{
  "id": "01995e58-1000-7000-8000-009ea3dcd8fc",
  "integration": "github",
  "userId": "customer_123",
  "groupId": null,
  "status": "awaiting_confirmation",
  "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:01.000Z",
  "completedAt": null
}
```

### 200 · Completed

The connection was activated. Read its state and refresh the user's tool catalog.

```json
{
  "id": "01995e58-1000-7000-8000-009ea3dcd8fc",
  "integration": "github",
  "userId": "customer_123",
  "groupId": null,
  "status": "completed",
  "requireConfirmation": true,
  "redirectUrl": "https://app.example.com/settings/integrations",
  "error": null,
  "connection": {
    "integration": "github",
    "userId": "customer_123",
    "groupId": null,
    "source": "personal",
    "overridesGroup": false,
    "authScheme": "api_key",
    "status": "connected",
    "accountId": "123456",
    "accountName": "octocat",
    "workspaceId": null,
    "connectedAt": "2026-10-10T12:00:01.000Z",
    "updatedAt": "2026-10-10T12:00:01.000Z",
    "error": null
  },
  "expiresAt": "2026-10-10T12:30:00.000Z",
  "createdAt": "2026-10-10T12:00:00.000Z",
  "updatedAt": "2026-10-10T12:00:01.000Z",
  "completedAt": "2026-10-10T12:00:01.000Z"
}
```

### 200 · Failed

The hosted flow failed. The HTTP read succeeded; error explains the connection failure.

```json
{
  "id": "01995e58-1000-7000-8000-009ea3dcd8fc",
  "integration": "github",
  "userId": "customer_123",
  "groupId": null,
  "status": "failed",
  "requireConfirmation": true,
  "redirectUrl": "https://app.example.com/settings/integrations",
  "error": {
    "code": "integration_credentials_invalid",
    "message": "GitHub did not accept these credentials"
  },
  "connection": null,
  "expiresAt": "2026-10-10T12:30:00.000Z",
  "createdAt": "2026-10-10T12:00:00.000Z",
  "updatedAt": "2026-10-10T12:00:01.000Z",
  "completedAt": null
}
```

### 200 · Expired

The connection attempt expired. Create a new connect session if the user wants to try again.

```json
{
  "id": "01995e58-1000-7000-8000-009ea3dcd8fc",
  "integration": "github",
  "userId": "customer_123",
  "groupId": null,
  "status": "expired",
  "requireConfirmation": true,
  "redirectUrl": "https://app.example.com/settings/integrations",
  "error": {
    "code": "connect_session_expired",
    "message": "The end user did not finish connecting before the session expired."
  },
  "connection": null,
  "expiresAt": "2026-10-10T12:30:00.000Z",
  "createdAt": "2026-10-10T12:00:00.000Z",
  "updatedAt": "2026-10-10T12:30:00.000Z",
  "completedAt": null
}
```

### 200 · Cancelled

The attempt was superseded or cancelled by disconnecting the integration.

```json
{
  "id": "01995e58-1000-7000-8000-009ea3dcd8fc",
  "integration": "github",
  "userId": "customer_123",
  "groupId": null,
  "status": "cancelled",
  "requireConfirmation": true,
  "redirectUrl": "https://app.example.com/settings/integrations",
  "error": {
    "code": "connect_session_cancelled",
    "message": "The connection was disconnected before this session finished."
  },
  "connection": null,
  "expiresAt": "2026-10-10T12:30:00.000Z",
  "createdAt": "2026-10-10T12:00:00.000Z",
  "updatedAt": "2026-10-10T12:00:01.000Z",
  "completedAt": null
}
```

### 400

invalid_request: A parameter is invalid; the message names the problem. Unknown query parameters are rejected.

#### invalid_request

A parameter is invalid; the message names the problem. Unknown query parameters are rejected.

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

### 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"
}
```

### 404

connect_session_not_found: The connect session does not exist in your workspace.

#### connect_session_not_found

The connect session does not exist in your workspace.

```json
{
  "statusCode": 404,
  "code": "connect_session_not_found",
  "message": "Connect session not found"
}
```

### 500

internal_error: An unexpected server error.

#### internal_error

An unexpected server error.

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

## Notes

- This endpoint does not return connectUrl again. Poll after the hosted flow or read it when the user returns to your application.

- Expired sessions are returned with status expired. Failed sessions include an error object with code and message; a failed flow can still return HTTP 200 here.

- A cancelled session's error code is connect_session_superseded when a newer connect session, or credentials saved through the API, replaced it before it finished, and connect_session_cancelled when the integration was disconnected.
