logo
In-app Chat
On this page

Create a room


Description

Developers can call this interface to create a room, and support setting custom room attributes when creating a room. A room can set up to 20 room attributes. If you need to increase the upper limit of the number of room attributes, please contact ZEGOCLOUD Technical Support.

Request method and endpoint

  • Request method: POST
  • Request URL: https://zim-api.zego.im/?Action=CreateRoom
  • Transmission protocol: HTTPS
  • QPS limit: 20 requests/second

Request parameters

The following table describes only the operation-specific request parameters and some common request parameters. For the complete list of common request parameters, see the Common request parameters section of the Accessing Server APIs topic.

ParameterTypeRequiredDescription
FromUserIdStringYesThe operator, which needs to be in the registered state. This user will not be automatically added to the room. Only numbers, English characters, '!', '#', '$', '%', '&', '(', ')', '+', '-', ':', ';', '<', '=', '.', '>', '?', '@', '[', ']', '^', '_', ' ', ', ', '|', '~' are supported.
RoomIdStringYesRoom ID. Only numbers, English characters, '!', '#', '$', '%', '&', '(', ')', '+', '-', ':', ';', '<', '=', '.', '>', '?', '@', '[', ']', '^', '_', ' ', ', ', '|', '~' are supported.
RoomNameStringNoRoom name. The maximum length is 64 bytes.
DestroyDelayTimeNumberNoThe room delay destruction time when the number of room users is 0, in seconds. The maximum room delay destruction time is 10800 seconds by default.
AttributesArray of CreateRoomAttributeNoThe attribute information to be added.

CreateRoomAttribute structure:

ParameterTypeRequiredDescription
KeyStringYesRoom attribute key.
ValueStringYesRoom attribute value.
AutoDeleteNumberNoWhether to automatically delete when the user exits the room, 0: not automatically delete, 1: automatically delete. When creating a room, FromUserId will not be added to the room, only when it enters the room first and then exits the room, the deletion operation will be triggered.

Request example

  • Request URL:
Untitled
https://zim-api.zego.im/?Action=CreateRoom
&<Common request parameters>
1
Copied!
  • Request body:
Untitled
{
    "FromUserId": "User1",
    "RoomId": "Room1",
    "RoomName":"RoomName1",
    "DestroyDelayTime":3600,
    "Attributes": [
        {
            "Key":"k1",
            "Value":"v1",
            "AutoDelete": 0
        },
        {
            "Key":"k2",
            "Value":"v2",
            "AutoDelete": 1
        }
    ]
}
1
Copied!

Response parameters

The response parameters are as follows:

ParameterTypeRequiredDescription
Codeint32YesReturn status code (0 means success).
MessagestringYesReturn status information.
RequestIdstringYesRequest unique identifier.

Response example

Untitled
{
    "Code": 0,
    "Message": "success",
    "RequestId": "req-123456789",
}
1
Copied!

Return codes

The following return codes are only listed for interface business logic. For the complete list of return codes, see Global return codes.

Return codeDescriptionSolution
660000002Parameter error.Please check the parameters.
660300005Frequency limit.Please try again later.
660300014Room already exists.Check if the room has been created.
660300015Room number exceeds the upper limit.Check if the room number exceeds the upper limit, or contact technical support to expand.

Previous

Delete all friends

Next

Query room attributes