> ## Documentation Index
> Fetch the complete documentation index at: https://docs.series.hr/llms.txt
> Use this file to discover all available pages before exploring further.

# Trigger Connect

> Trigger server connection via game messaging

Trigger a server connection for an attendance session by sending a message to all game servers via Roblox Open Cloud Messaging Service. The in-game Attendance module will detect the host and connect the server automatically (Premium/Enterprise only).

<Note>
  This endpoint is designed for **external integrations** (Discord bots, custom tools) that need to trigger
  the server connection step without using the Series dashboard. It requires a **Session Attendance OpenCloud
  API key** to be configured in your workspace settings.
</Note>

## When to use this

The `add-attendee` endpoint requires a server to be connected to the session first. Normally, the in-game Attendance module
handles this automatically when the host joins the game. However, if you create or start a session **after** the host is
already in-game, the connection doesn't happen automatically.

Call this endpoint to tell the in-game module to look for the host and connect the server. After calling it, wait a
few seconds, then proceed with adding attendees.

## Request

```bash theme={null}
curl -X POST https://api.series.hr/attendance/trigger-connect/session_xyz789 \
  -H "apikey: YOUR_API_KEY"
```

## Parameters

<ParamField path="sessionId" type="string" required>
  The session ID to trigger server connection for
</ParamField>

## Prerequisites

* Session must be **ongoing** (status = `ongoing`)
* Session must have a **PlaceId** configured
* Session must have a **Host** assigned
* Server must **not** already be connected (if already connected, returns success with current server info)
* Workspace must have a **Session Attendance OpenCloud API key** configured in settings
* The host must be **present in a game server** running the Attendance module

## Response

<ResponseField status={200} name="200 - Request sent">
  ```json theme={null}
  {
    "success": true,
    "data": {
      "message": "Connection request sent to game servers. The server will connect automatically once the host is detected in-game."
    }
  }
  ```
</ResponseField>

<ResponseField status={200} name="200 - Already connected">
  ```json theme={null}
  {
    "success": true,
    "data": {
      "message": "Server is already connected to this session",
      "ServerId": "job-server-abc123",
      "ServerConnectedAt": "2024-01-15T10:30:00Z"
    }
  }
  ```
</ResponseField>

## Error Responses

| Status | Error                           | Description                                          |
| ------ | ------------------------------- | ---------------------------------------------------- |
| `400`  | Session must be ongoing         | Session is not in "ongoing" status                   |
| `400`  | No place configured             | Session has no PlaceId set                           |
| `400`  | No host assigned                | Session has no host                                  |
| `400`  | No OpenCloud API key configured | Workspace needs a Session Attendance key in settings |
| `401`  | Unauthorized                    | Invalid or missing API key                           |
| `403`  | Subscription required           | Requires Premium or Enterprise                       |
| `404`  | Session not found               | Session ID doesn't exist in workspace                |

## Rate Limiting

This endpoint has stricter rate limiting than other attendance endpoints:

* **10 requests per minute** per API key

## Example: Discord Bot Integration

```javascript theme={null}
// Step 1: Create/start your session
const sessionId = 'session_xyz789';

// Step 2: Trigger server connection
const connectResponse = await fetch(
  `https://api.series.hr/attendance/trigger-connect/${sessionId}`,
  {
    method: 'POST',
    headers: { 'apikey': API_KEY }
  }
);

// Step 3: Wait for the in-game module to connect (poll server-status)
let connected = false;
for (let i = 0; i < 10; i++) {
  await new Promise(r => setTimeout(r, 3000)); // Wait 3 seconds

  const statusResponse = await fetch(
    `https://api.series.hr/attendance/server-status/${sessionId}`,
    { headers: { 'apikey': API_KEY } }
  );
  const status = await statusResponse.json();

  if (status.data.ServerId) {
    connected = true;
    break;
  }
}

if (!connected) {
  console.log('Host not found in game. Is the host in a server with the Attendance module?');
  return;
}

// Step 4: Now add attendees
await fetch(
  `https://api.series.hr/attendance/add-attendee/${sessionId}`,
  {
    method: 'POST',
    headers: {
      'apikey': API_KEY,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      UserId: '714760171',
      Username: 'player_name',
      JoinTime: new Date().toISOString()
    })
  }
);
```
