API Reference - API Endpoints

The Liveblocks API is organized around REST. Our API has predictable resource-oriented URLs, accepts form-encoded request bodies, returns JSON-encoded responses, and uses standard HTTP response codes, authentication, and verbs.

With the Liveblocks API, you can authenticate requests, list and update rooms, list users, and more.

https://api.liveblocks.io/v2
Looking for API v1?

The API v1 is deprecated, learn more about it on its reference.

To use the API endpoints, you need to add your secret key to the request’s authorization header. Except for the public authorization endpoint.

1
curl https://api.liveblocks.io/v2/* \
2
-H "Authorization: Bearer YOUR_SECRET_KEY"

Returns a list of your rooms. The rooms are returned sorted by creation date, from newest to oldest. You can filter rooms by metadata, users accesses and groups accesses.

There is a pagination system where the next page URL is returned in the response as nextPage. You can also limit the number of rooms by query.

Filtering by metadata works by giving key values like metadata.color=red. Of course you can combine multiple metadata clauses to refine the response like metadata.color=red&metadata.type=text. Notice here the operator AND is applied between each clauses.

Filtering by groups works by giving a list of groups like groupIds=marketing,GZo7tQ,product. Notice here the operator OR is applied between each groupIds.

Parameters

limit optional

A limit on the number of rooms to be returned. The limit can range between 1 and 100, and defaults to 20.

  • Minimum: 1
  • Maximum: 100
  • Default: 20
startingAfter optional

A cursor used for pagination. You get the value from the response of the previous page.

metadata.KEY optional

A filter on metadata. Multiple metadata keys can be used to filter rooms.

metadata.colors=blue
userId optional

A filter on users accesses.

userId=user1
groupIds optional

A filter on groups accesses. Multiple groups can be used.

groupsIds=group1,group2
GET
https://api.liveblocks.io/v2/rooms

Responses

Status:

Success. Returns the list of rooms and the next page URL.

1
{
2
"nextPage": "/v2/rooms?startingAfter=W1siaWQiLCJVRzhWYl82SHRUS0NzXzFvci1HZHQiXSxbImNyZWF0ZWRBdCIsMTY2MDAwMDk4ODEzN11d",
3
"data": [
4
{
5
"type": "room",
6
"id": "HTOGSiXcORTECjfNBBLii",
7
"lastConnectionAt": "2022-08-08T23:23:15.281Z",
8
"createdAt": "2022-08-08T23:23:15.281Z",
9
"metadata": {
10
"name": [
11
"My room"
12
],
13
"type": [
14
"whiteboard"
15
]
16
},
17
"defaultAccesses": [
18
"room:write"
19
],
20
"groupsAccesses": {
21
"product": [
22
"room:write"
23
]
24
},
25
"usersAccesses": {
26
"vinod": [
27
"room:write"
28
]
29
}
30
}
31
]
32
}

Create room

Create a new room. id and defaultAccesses are required.

  • defaultAccessess could be [] or ["room:write"] (private or public).
  • metadata could be key/value as string or string[]. metadata supports maximum 50 entries. Key length has a limit of 40 characters maximum. Value length has a limit of 256 characters maximum. metadata is optional field.
  • usersAccesses could be [] or ["room:write"] for every records. usersAccesses can contain 100 ids maximum. Id length has a limit of 40 characters. usersAccesses is optional field.
  • groupsAccesses are optional fields.

Request body

1
{
2
"id": "my-room-3ebc26e2bf96",
3
"defaultAccesses": [
4
"room:write"
5
],
6
"metadata": {
7
"color": "blue"
8
},
9
"usersAccesses": {
10
"alice": [
11
"room:write"
12
]
13
},
14
"groupsAccesses": {
15
"product": [
16
"room:write"
17
]
18
}
19
}
POST
https://api.liveblocks.io/v2/rooms

Responses

Status:

Success. Returns the created room.

1
{
2
"type": "room",
3
"id": "my-room-3ebc26e2bf96",
4
"lastConnectionAt": "2022-08-22T15:10:25.225Z",
5
"createdAt": "2022-08-22T15:10:25.225Z",
6
"metadata": {
7
"color": "blue"
8
},
9
"defaultAccesses": [
10
"room:write"
11
],
12
"groupsAccesses": {
13
"product": [
14
"room:write"
15
]
16
},
17
"usersAccesses": {
18
"alice": [
19
"room:write"
20
]
21
}
22
}

Get a room by its id.

Route parameters

roomId required

id of the room

GET
https://api.liveblocks.io/v2/rooms/{roomId}

Responses

Status:

Success. Returns the room.

1
{
2
"type": "room",
3
"id": "react-todo-list",
4
"lastConnectionAt": "2022-08-04T21:07:09.380Z",
5
"createdAt": "2022-07-13T14:32:50.697Z",
6
"metadata": {
7
"color": "blue",
8
"size": "10",
9
"target": [
10
"abc",
11
"def"
12
]
13
},
14
"defaultAccesses": [
15
"room:write"
16
],
17
"groupsAccesses": {
18
"marketing": [
19
"room:write"
20
]
21
},
22
"usersAccesses": {
23
"alice": [
24
"room:write"
25
],
26
"vinod": [
27
"room:write"
28
]
29
}
30
}

Update room

Updates specific properties of a room. It's not necessary to provide the entire room's information. Setting a property to null means to delete this property. For example, if you want to remove access to a specific user without losing other users: { "users_accesses": { "john": null } } defaultAccessess, metadata, usersAccesses, groupsAccesses can be updated.

  • defaultAccessess could be [] or ["room:write"] (private or public).
  • metadata could be key/value as string or string[]. metadata supports maximum 50 entries. Key length has a limit of 40 characters maximum. Value length has a limit of 256 characters maximum. metadata is optional field.
  • usersAccesses could be [] or ["room:write"] for every records. usersAccesses can contain 100 ids maximum. Id length has a limit of 256 characters. usersAccesses is optional field.
  • groupsAccesses could be [] or ["room:write"] for every records. groupsAccesses can contain 100 ids maximum. Id length has a limit of 256 characters. groupsAccesses is optional field.

Route parameters

roomId required

id of the room

Request body

1
{
2
"defaultAccesses": [
3
"room:write"
4
],
5
"users_accesses": {
6
"vinod": [
7
"room:write"
8
],
9
"alice": [
10
"room:write"
11
]
12
},
13
"groups_accesses": {
14
"marketing": [
15
"room:write"
16
]
17
},
18
"metadata": {
19
"color": "blue"
20
}
21
}
POST
https://api.liveblocks.io/v2/rooms/{roomId}

Responses

Status:

Success. Returns the updated room.

1
{
2
"type": "room",
3
"id": "react-todo-list",
4
"lastConnectionAt": "2022-08-04T21:07:09.380Z",
5
"createdAt": "2022-07-13T14:32:50.697Z",
6
"metadata": {
7
"color": "blue",
8
"size": "10",
9
"target": [
10
"abc",
11
"def"
12
]
13
},
14
"defaultAccesses": [
15
"room:write"
16
],
17
"groupsAccesses": {
18
"marketing": [
19
"room:write"
20
]
21
},
22
"usersAccesses": {
23
"alice": [
24
"room:write"
25
],
26
"vinod": [
27
"room:write"
28
]
29
}
30
}

Returns a list of users currently present in the requested room. For better performance, we recommand to call this endpoint every 10 seconds maximum. Duplicates can happen if a user is in the requested room with multiple browser tabs opened.

Route parameters

roomId required

id of the room

GET
https://api.liveblocks.io/v2/rooms/{roomId}/active_users

Responses

Status:

Success. Returns the list of active users for the specified room.

1
{
2
"data": [
3
{
4
"type": "user",
5
"connectionId": 16,
6
"id": "alice",
7
"info": {}
8
},
9
{
10
"type": "user",
11
"connectionId": 20,
12
"id": "bob",
13
"info": {}
14
}
15
]
16
}

Returns a room storage as JSON.

Some implementation details: Each Liveblocks data structure is represented by a JSON element having two properties: "liveblocksType": "LiveObject" | "LiveList" | "LiveMap" "data" => contains the nested data structures (children) and data. The root is always a LiveObject.

Route parameters

roomId required

id of the room

GET
https://api.liveblocks.io/v2/rooms/{roomId}/storage

Responses

Status:

Success. Returns the room storage as JSON.

1
{
2
"liveblocksType": "LiveObject",
3
"data": {
4
"aLiveObject": {
5
"liveblocksType": "LiveObject",
6
"data": {
7
"a": 1
8
}
9
},
10
"aLiveList": {
11
"liveblocksType": "LiveList",
12
"data": [
13
"a",
14
"b"
15
]
16
},
17
"aLiveMap": {
18
"liveblocksType": "LiveMap",
19
"data": {
20
"a": 1,
21
"b": 2
22
}
23
}
24
}
25
}

Initialize storage

Initializes a room storage. The room must already exist and have an empty storage.

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"
  • "data" => contains the nested data structures (children) and data.

The root's type can only be LiveObject.

Route parameters

roomId required

id of the room

Request body

1
{
2
"liveblocksType": "LiveObject",
3
"data": {
4
"aLiveObject": {
5
"liveblocksType": "LiveObject",
6
"data": {
7
"a": 1
8
}
9
},
10
"aLiveList": {
11
"liveblocksType": "LiveList",
12
"data": [
13
"a",
14
"b"
15
]
16
},
17
"aLiveMap": {
18
"liveblocksType": "LiveMap",
19
"data": {
20
"a": 1,
21
"b": 2
22
}
23
}
24
}
25
}
POST
https://api.liveblocks.io/v2/rooms/{roomId}/storage

Responses

Status:

Success. The storage is initialized. Returns the room storage as JSON.

1
{
2
"liveblocksType": "LiveObject",
3
"data": {
4
"aLiveObject": {
5
"liveblocksType": "LiveObject",
6
"data": {
7
"a": 1
8
}
9
},
10
"aLiveList": {
11
"liveblocksType": "LiveList",
12
"data": [
13
"a",
14
"b"
15
]
16
},
17
"aLiveMap": {
18
"liveblocksType": "LiveMap",
19
"data": {
20
"a": 1,
21
"b": 2
22
}
23
}
24
}
25
}

Deletes all elements of the room storage.

Route parameters

roomId required

id of the room

DELETE
https://api.liveblocks.io/v2/rooms/{roomId}/storage

Get an access token to enter a room

This endpoint lets your application server (= your backend) obtain a token that one of its clients (= your frontend) can use to enter a Liveblocks room. You use this endpoint to implement your own application’s custom authentication endpoint. When making this request, you’ll have to use your secret key.

The body for this POST request lets you declare what user ID the token is for, by means of the userId property. This can be whatever internal identifier you use for your user accounts, as long as it uniquely identifies an account. Setting the userId is optional if you want to use public rooms, but it is required to enter a private room (because permissions are assigned to specific user IDs). You can also declare which groupIds this user belongs to, in case you want to use the group permission system.

Additionally, you can set custom metadata to the token, which will be publicly accessible by other clients, through the user.info property. This is useful to store static data like avatar images, or the user's display name.

Route parameters

roomId required

id of the room

Request body

1
{
2
"userId": "b2c1c290-f2c9-45de-a74e-6b7aa0690f59",
3
"groupIds": [
4
"g1",
5
"g2"
6
],
7
"userInfo": {
8
"name": "bob",
9
"colors": [
10
"blue",
11
"red"
12
]
13
}
14
}
POST
https://api.liveblocks.io/v2/rooms/{roomId}/authorize

Responses

Status:

Success. Returns the JWT token.

1
{
2
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
3
}

Get an access token to enter a room with public key

This endpoint works with the public key and can be used client side. That means you don't need to implement a dedicated authorization endpoint server side. The generated JWT token works only with public room (defaultAccesses: ["room:write"]).

Route parameters

roomId required

id of the room

Request body

1
{
2
"publicApiKey": "pk_test_lOMrmwejSWLaPYQc5_JuGHXXX"
3
}
POST
https://api.liveblocks.io/v2/rooms/{roomId}/public/authorize

Responses

Status:

Success. Returns the JWT token.

1
{
2
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
3
}