---
title: "Connect to the realtime service"
method: GET
path: "/connect/"
tags: ["Realtime"]
---

# Connect to the realtime service

`GET /connect/`

Creates a websocket connection to the realtime service, sending messages to the realtime service
will subscribe you to different resources allowing you to listen to document updates in realtime. When subscribing if a
resource doesn't exist yet a listener will be created and will be triggered when the resource is created. If the resource
is deleted the listener will still exist so make sure to unsubscribe when you no longer need the resource.

When connecting via a html websocket you will need to parse all of your headers in through `Sec-WebSocket-Protocol`
which is an optional header that takes in a string. Format for the string needs to be a list of headers split by \n and
key value split by : and then encoded into base58

Example format

x-m2-organization:testOrg
x-m2-project:testProj


Example messages for subscribing to the resources available in the realtime service -

* KVStore:

        {
            "action": "subscribe",
            "resource": {
                "type": "kvStore",
                "id": "World:kvstoreClient:testKey"
            }
        }

* Collections:

        {
            "action": "subscribe",
            "resource": {
                "type": "collection",
                "id": "public"
            }
        }

* Liveconfig:

        {
            "action": "subscribe",
            "resource": {
                "type": “liveConfig",
                "id": “game"
            }
        }

Using the same format, you can also unsubscribe from the resources by changing the action to "unsubscribe" and sending the same resource.

Example response formats below.

## Success:

        {
          "userId": "fakeUserId",
          "resource": {
              "type": "collection",
              "id": "private"
          },
          "data": {
              "userId": "fakeUserId",
              "datasourceId": "fakeDatasourceId",
              "userCollection": []
          },
          "version": "2024-01-30T15:50:35.742Z"
        }

## Warning:

        {
          "warning": "resource_not_found",
          "message": "KVStore resource doesn't currently exist, subscription was still made successfully"
        }

## Error:

        {
          "error": "Invalid message format"
        }

## Headers

- `x-m2-organization-id` string, required
- `x-m2-project-id` string
- `x-m2-world-id` string

## Other responses

- `101` — Default Response
- `4XX` — The error object returned by the API when an error occurs

---

[API](https://skmtc.net/otherside/apis/realtime.md) · [All operations](https://skmtc.net/otherside/apis/realtime/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/otherside/realtime/revisions/440a22407dac/schema)
