Storage

Initialize Storage document

Changed on

This endpoint initializes or reinitializes a room’s Storage. The room must already exist. Calling this endpoint will disconnect all users from the room if there are any, triggering a reconnect. Corresponds to liveblocks.initializeStorageDocument.

The format of the request body is the same as what’s returned by the get Storage endpoint.

For each Liveblocks data structure that you want to create, you need a JSON element having two properties:

  • "liveblocksType" => "LiveObject" | "LiveList" | "LiveMap" | "LiveFile"
  • "data" => contains the nested data structures (children) and data.

The root’s type can only be LiveObject.

A utility function, toPlainLson is included in @liveblocks/client from 1.0.9 to help convert LiveObject, LiveList, LiveMap, and LiveFile to the structure expected by the endpoint.

post/rooms/{roomId}/storage

Request

  • Base URL: https://api.liveblocks.io/v2
  • URL: https://api.liveblocks.io/v2/rooms/{roomId}/storage
  • Auth: none declared

Path parameters

roomIdstring required

ID of the room

Example:my-room-id

Request body

liveblocksType'LiveObject' required
dataobject required

Response

Success. The Storage is initialized. Returns the room’s Storage as JSON.

liveblocksType'LiveObject'
dataobject

Example response

{
  "liveblocksType": "LiveObject",
  "data": {
    "aLiveObject": {
      "liveblocksType": "LiveObject",
      "data": {
        "a": 1
      }
    },
    "aLiveList": {
      "liveblocksType": "LiveList",
      "data": [
        "a",
        "b"
      ]
    },
    "aLiveFile": {
      "liveblocksType": "LiveFile",
      "data": {
        "id": "fl_abc123456789012345678",
        "name": "photo.png",
        "size": 12345,
        "mimeType": "image/png"
      }
    }
  }
}

Changes

    • breaking

      request body became required

    • breaking

      the request property became required

    • breaking

      the request property became required

    • breaking

      the request property const value LiveObject was added

    • breaking

      the response's property type changed from string object to object for status

    • info

      api operation id post-rooms-roomId-storage removed and replaced with initialize-storage-document

    • info

      the response property const value LiveObject was added for the status