Edit chat room states

Update time: 2022/12/13 08:42:44

If you create a chat room, the chat room is open and accessible by default. All participants can join the chat room. To prevent all participants from joining the chat room, call the specified RESTful API for closing a chat room. You can also query the chat room in service by calling the specified API.

Open or close a chat room

After creating a chat room, you can close the chat room by setting the valid parameter to false. You can also open a closed chat room by setting the valid parameter to true.

When you create a chat room, you can set a timer to close it.

URL

httpPOST https://api.netease.im/nimserver/chatroom/toggleCloseStat.action HTTP/1.1
Content-Type:application/x-www-form-urlencoded;charset=utf-8

Request parameters

  • For information about how to set the header in a POST request, see API Call methods.

  • The settings of the body in a POST request:

ParameterTypeRequiredDescription
roomid LongYes Chat room ID
operator String Yes The operator account. Only the creator can perform the operation.
valid Boolean Yes false: close the chat room, true: open the chat room.
delayClosePolicy IntegerNo Timer option. 0: no timer,
1: set a timer to close the chat room regardless of whether participants exist in the chat room,
2: set a timer to close the chat room when no participants exist in the chat room
delaySeconds LongNo The timer to close the chat room.
If you set delayClosePolicy=1 or 2 without a specific period of time, the default value (7*24*3600s) is applied

Response parameters

ParameterTypeDescription
code IntegerStatus code
roomid LongChat room ID
valid Booleanfalse: close a chat room, true: open a chat room
announcement StringAnnouncement in a chat room
name StringThe name of a chat room
broadcasturl StringURL for live streaming
ext StringExtension field
queuelevel Integer Queue management permission. 0: All participants have the permission to change a queue, 1: Only hosts and administrators have the permission to change a queue
muted BooleanWhether the chat room is all muted. Only administrators and creators can speak if a chat room is all muted. false: unmuted, true: muted
creator StringID of the creator
delayInfo StringTimer info
delayCloseEnable BooleanWhether a timer is enabled, true: enabled, false: disabled
delayClosePolicyIntegerMethod to close a chat room. 0: no timer, 1: close a chat room when the timer ends, 2: close a chat room if no participants exist in the chat room
delaySeconds Long Timer period. The maximum period (7*24*3600s)
status IntegerCurrent status, 1: The task starts in the initial state, 2: waiting state, 3: task completion state, 4: task canceled< /td>
startTimeLong Timestamp of the start time

Example

cURL request example

curlcurl -X POST -i 'https://api.netease.im/nimserver/chatroom/toggleCloseStat.action' -H "Nonce: 12345" -H "CheckSum: bbecaa4b278bc74508f1d359b42d84e0ae38b082" -H "AppKey: 2bd025c577313e81b2bdb2d2dcefcadb" -H "CurTime: 1666597407" -d 'roomid=1600849147&operator=test100&valid=true&delayClosePolicy=1&delaySeconds=60'

Example success response

json"Content-Type": "application/json; charset=utf-8"
{
  "code": 200,
  "chatroom": {
    "valid": true,
    "ext": "",
    "creator": "test100",
    "name": "test1-chatroom",
    "muted": false,
    "announcement": null,
    "broadcasturl": "xxxxxx",
    "roomid": 1600849147,
    "queuelevel": 0,
    "delayInfo": {
      "delaySeconds": 60,
      "delayCloseEnable": true,
      "startTime": 1666597407137,
      "delayClosePolicy": 1,
      "status": 2
    }
  }
}

Example error response

"Content-Type": "application/json; charset=utf-8"
{
    "code": 414, 
    "desc": "owner not registered" 
}

Status codes

The following status codes are related to responses of this API. For more status codes, see Status codes.

Status code Description Recommendation
200 Success -
414 Parameter error Check the format and restrictions of arguments based on the error message
403 Forbidden operation The app does not have the permission to open or close the chat room
419 The number of chat rooms exceeds the upper limit -
404 Chat room does not exist Check the chat room ID
417 Repeated operation The closed chat room cannot be closed again, and the opened chat room cannot be opened again
13002 The chat room is invalid The status of the chat room is abnormal. Check its status

Query chat rooms in service

Query active chat rooms.

URL

httpPOST https://api.netease.im/nimserver/chatroom/queryUserRoomIds.action HTTP/1.1
Content-Type:application/x-www-form-urlencoded;charset=utf-8

Request parameters

  • For information about how to set the header in a POST request, see API Call methods.

  • The settings of the body in a POST request:

ParameterTypeRequiredDescription
creator StringYes The accid of the creator

Example

cURL request example

curlcurl -X POST  -H 'appkey: fe416640c8e8a72734219e1847ad2547'  -H 'cache-control: no-cache'  -H 'checksum: 18f5435a7bf287af9150ad608797f75265495034'  -H 'content-type: application/x-www-form-urlencoded'   -H 'curtime: 1508481877'   -H 'nonce: 12345' -d 'creator=xiaoming01' "https://api.netease.im/nimserver/chatroom/queryUserRoomIds.action"

Example success response

json
"Content-Type": "application/json; charset=utf-8"
{
  "code": 200,
  "desc":{
    "roomids": [
        "1015",
        "2016",
        "2017",
        "5062",
        "23037398"
    ]
    }
}

Status code

The status code is returned in the response body. For more information, see Status codes.

Was this page helpful?
Yes
No
  • Open or close a chat room
  • URL
  • Request parameters
  • Response parameters
  • Example
  • cURL request example
  • Example success response
  • Example error response
  • Status codes
  • Query chat rooms in service
  • URL
  • Request parameters
  • Example
  • cURL request example
  • Example success response
  • Status code