群组管理


环信提供了 REST API 来管理 APP 中的群组。

单个APP创建群组数量有限制,如需增加可根据具体业务联系商务解决。单用户ID只能加入500个群。

字段名 类型 描述
id String 群组 ID,群组唯一标识符,由环信服务器生成,等同于单个用户的环信 ID。
name String 群组名称,根据用户输入创建,字符串类型。
description String 群组描述,根据用户输入创建,字符串类型。
public Boolean 群组类型:true:公开群,false:私有群。
membersonly Boolean 加入群组是否需要群主或者群管理员审批。true:是,false:否。
allowinvites Boolean 是否允许群成员邀请别人加入此群。 true:允许群成员邀请人加入此群,false:只有群主才可以往群里加人。
maxusers Integer 群成员上限,创建群组的时候设置,可修改。
affiliations_count Integer 现有成员总数。
affiliations Array 现有成员列表,包含了 owner 和 member。例如:“affiliations”:[{“owner”: “13800138001”},{“member”:“v3y0kf9arx”},{“member”:“xc6xrnbzci”}]。
owner String 群主的环信 ID。例如:{“owner”: “13800138001”}。
member String 群成员的环信 ID。例如:{“member”:“xc6xrnbzci”}。
invite_need_confirmBoolean邀请加群,被邀请人是否需要确认。如果是true,表示邀请加群需要被邀请人确认;如果是false,表示不需要被邀请人确认,直接将被邀请人加入群。 该字段的默认值为true。

群组除了群主、普通群成员之外,新增群管理员角色。

群组角色权限范围:群主 > 群管理员 > 普通群成员

  • 群主拥有群的所有权限;
  • 群管理员拥有管理黑名单、禁言等权限。

REST API

IM 群组集成过程中,需要使用到的 REST API 文档详细说明,可以通过使用文档中嵌入的Easemob REST API进行在线测试。

环信提供多个接口完成群组相关的集成,包括对群组的创建、获取、修改、删除等管理功能。

名称请求描述
获取App中所有的群组(可分页)/{org_name}/{app_name}/chatgroups获取应用下全部的群组信息
获取一个用户参与的所有群组/{app_name}/users/{username}/joined_chatgroups根据用户名称获取此用户加入的全部群组
获取群组详情/{org_name}/{app_name}/chatgroups/{group_ids}根据群组ID获取此群组的详情
创建一个群组/{org_name}/{app_name}/chatgroups创建一个新群组
修改群组信息/{org_name}/{app_name}/chatgroups/{group_id}修改群组的部分信息
删除群组/{org_name}/{app_name}/chatgroups/{group_id}删除一个群组

获取App中所有的群组(可分页)

分页获取应用下全部的群组信息的接口

HTTP Request

/{org_name}/{app_name}/chatgroups

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

Response Body

在返回值中查看data字段包含的信息

参数说明
owner群主的环信 ID。例如:{“owner”: “user1}。
groupid群组ID
affiliations群组现有人数
type“group”群组类型
last_modified最近一次修改的时间戳
groupname群组名称

请求示例

第一页

curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups?limit=2'

可能返回的结果示例

返回值200,表示获取群组成功

{
    "action": "get",
    "params": {
        "limit": [
            "2"
        ]
    },
    "uri": "https://a1.easemob.com/easemob-demo/testapp/chatgroups",
    "entities": [],
    "data": [
        {
            "owner": "easemob-demo#testapp_user1",
            "groupid": "100743775617286960",
            "affiliations": 2,
            "type": "group",
            "last_modified": "1441021038124",
            "groupname": "testgroup1"
        },
        {
            "owner": "easemob-demo#testapp_user2",
            "groupid": "100973270123152176",
            "affiliations": 1,
            "type": "group",
            "last_modified": "1441074471486",
            "groupname": "testgroup2"
        }
    ],
    "timestamp": 1441094193812,
    "duration": 14,
    "cursor": "Y2hhdGdyb3VwczplYXNlbW9iLWRlbW8vY2hhdGRlbW91aV8z",
    "count": 2
}

返回值401,未授权[无token、token错误、token过期]

{
  "error": "group_authorization",
  "timestamp": 1542359035948,
  "duration": 0,
  "exception": "com.easemob.group.exception.GroupAuthorizationException",
  "error_description": "this token is bad, or has expired!"
}

第二页

curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups?limit=2&cursor=ZGNiMjRmNGY1YjczYjlhYTNkYjk1MDY2YmEyNzFmODQ6aW06Z3JvdXA6ZWFzZW1vYi1kZW1vI3Rlc3RhcHA6Mg'

可能返回的结果示例

返回值200,表示获取群组成功

{
  "action": "get",
  "application": "8be024f0-e978-11e8-b697-5d598d5f8402",
  "params": {
    "cursor": [
      "ZGNiMjRmNGY1YjczYjlhYTNkYjk1MDY2YmEyNzFmODQ6aW06Z3JvdXA6ZWFzZW1vYi1kZW1vI3Rlc3RhcHA6Mg"
    ],
    "limit": [
      "2"
    ]
  },
  "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups",
  "entities": [],
  "data": [
    {
      "groupid": "66016467025921",
      "groupname": "testgroup2",
      "owner": "easemob-demo#testapp_user2",
      "affiliations": 1,
      "lastModified": 1542356609540,
      "type": "group",
      "created": 1542356609540
    },
    {
      "groupid": "66016480657410",
      "groupname": "testgroup3",
      "owner": "easemob-demo#testapp_user3",
      "affiliations": 1,
      "lastModified": 1542356622235,
      "type": "group",
      "created": 1542356622235
    }
  ],
  "timestamp": 1542358693048,
  "duration": 0,
  "organization": "easemob-demo",
  "applicationName": "testapp",
  "cursor": "ZGNiMjRmNGY1YjczYjlhYTNkYjk1MDY2YmEyNzFmODQ6aW06Z3JvdXA6ZWFzZW1vYi1kZW1vI3Rlc3RhcHA6Mw",
  "count": 2
}

返回值401,未授权[无token、token错误、token过期]

{
  "error": "group_authorization",
  "timestamp": 1542358868326,
  "duration": 0,
  "exception": "com.easemob.group.exception.GroupAuthorizationException",
  "error_description": "this token is bad, or has expired!"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


获取一个用户参与的所有群组

根据用户名称获取该用户加入的全部群组接口

HTTP Request

/{app_name}/users/{username}/joined_chatgroups

需要在请求时对应填写{username},需要获取的 IM 用户名。

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

Response Body

在返回值中查看data字段包含的信息

参数说明
groupid群组ID
groupname群组名称

请求示例

curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://a1.easemob.com/easemob-demo/testapp/users/user1/joined_chatgroups'

可能返回的结果示例

返回值200,表示获取群组成功

{
  "action": "get",
  "application": "8be024f0-e978-11e8-b697-5d598d5f8402",
  "uri": "http://a1.easemob.com/easemob-demo/testapp/users/user1/joined_chatgroups",
  "entities": [],
  "data": [
    {
      "groupid": "66016455491585",
      "groupname": "testgroup1"
    },
    {
      "groupid": "66016467025921",
      "groupname": "testgroup2"
    },
  ],
  "timestamp": 1542359565885,
  "duration": 1,
  "organization": "easemob-demo",
  "applicationName": "testapp",
  "count": 2
}

返回值404,此用户不存在

{
  "error": "resource_not_found",
  "timestamp": 1542359607100,
  "duration": 0,
  "exception": "com.easemob.group.exception.ResourceNotFoundException",
  "error_description": "username user20 doesn't exist!"
}

返回值401,未授权[无token、token错误、token过期]

{
  "error": "group_authorization",
  "timestamp": 1542359664255,
  "duration": 0,
  "exception": "com.easemob.group.exception.GroupAuthorizationException",
  "error_description": "this token is bad, or has expired!"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


获取群组详情

可以获取一个或多个群组的详情。当获取多个群组的详情时,会返回所有存在的群组的详情,对于不存在的群组,response body内返回“group id doesn't exist”。

HTTP Request

{org_name}/{app_name}/chatgroups/{group_ids}

需要在请求时对应填写{group_ids},需要获取的群组 ID 。

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

Response Body

在返回值中查看data字段包含的信息

参数说明
id群组 ID,群组唯一标识符,由环信服务器生成,等同于单个用户的环信 ID。
name群组名称,根据用户输入创建,字符串类型。
description群组描述,根据用户输入创建,字符串类型。
membersonly加入群组是否需要群主或者群管理员审批。true:是,false:否。
allowinvites是否允许群成员邀请别人加入此群。 true:允许群成员邀请人加入此群,false:只有群主才可以往群里加人。
maxusers群成员上限,创建群组的时候设置,可修改。
owner群主的环信 ID。例如:{“owner”: “user1”}。
created创建该群组的时间戳
affiliations_count现有成员总数。
affiliations现有成员列表,包含了 owner 和 member。例如:“affiliations”:[{“owner”: “user1”},{“member”:“user2”},{“member”:“user3”}]。
public群组类型:true:公开群,false:私有群。

请求示例

curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585'

可能返回的结果示例

返回值200,表示获取群组详情成功

{
  "action": "get",
  "application": "8be024f0-e978-11e8-b697-5d598d5f8402",
  "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585",
  "entities": [],
  "data": [
    {
      "id": "66016455491585",
      "name": "testgroup1",
      "description": "testgroup1",
      "membersonly": false,
      "allowinvites": false,
      "maxusers": 200,
      "owner": "user1",
      "created": 1542356598609,
      "custom": "",
      "affiliations_count": 3,
      "affiliations": [
        {
          "member": "user3"
        },
        {
          "member": "user2"
        },
        {
          "owner": "user1"
        }
      ],
      "public": true
    }
  ],
  "timestamp": 1542360200677,
  "duration": 0,
  "organization": "easemob-demo",
  "applicationName": "testapp",
  "count": 1
}

返回值404,表示此群组ID不存在

{
  "error": "service_resource_not_found",
  "timestamp": 1542360292539,
  "duration": 0,
  "exception": "com.easemob.group.exception.ServiceResourceNotFoundException",
  "error_description": "do not find this group:6601645549158"
}

返回值401,未授权[无token、token错误、token过期]

{
  "error": "group_authorization",
  "timestamp": 1542360340446,
  "duration": 0,
  "exception": "com.easemob.group.exception.GroupAuthorizationException",
  "error_description": "this token is bad, or has expired!"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


创建一个群组

创建一个群组,并设置群组名称、群组描述、公开群/私有群属性、群成员最大人数(包括群主)、加入公开群是否需要批准、群主、以及群成员。

HTTP Request

{org_name}/{app_name}/chatgroups

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

Request Body

参数说明
groupname群组名称,此属性为必须的
desc群组描述,此属性为必须的
public是否是公开群,此属性为必须的
maxusers群组成员最大数(包括群主),值为数值类型,默认值200,最大值2000,此属性为可选的
members_only加入群是否需要群主或者群管理员审批,默认是false
allowinvites是否允许群成员邀请别人加入此群。 true:允许群成员邀请人加入此群,false:只有群主或者管理员才可以往群里加人。
owner群组的管理员,此属性为必须的
members群组成员,此属性为可选的,但是如果加了此项,数组元素至少一个(注:群主user1不需要写入到members里面)

Response Body

在返回值中查看data字段包含的信息

参数说明
groupid群组ID

请求示例

curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' -d '{  
   "groupname": "testgroup",  
   "desc": "test",  
   "public": true,  
   "maxusers": 300,  
   "approval": true,  
   "owner": "testuser",  
   "members": [  
     "user2"  
   ]  
 }' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups'

可能返回的结果示例

返回值200,表示群组创建成功

{
  "action": "post",
  "application": "8be024f0-e978-11e8-b697-5d598d5f8402",
  "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups",
  "entities": [],
  "data": {
    "groupid": "66021836783617"
  },
  "timestamp": 1542361730243,
  "duration": 0,
  "organization": "easemob-demo",
  "applicationName": "testapp"
}

返回值400,owner用户不存在

{
  "error": "resource_not_found",
  "timestamp": 1542361812517,
  "duration": 0,
  "exception": "com.easemob.group.exception.ResourceNotFoundException",
  "error_description": "username tesuser doesn't exist!"
}

返回值401,未授权[无token、token错误、token过期]

{
  "error": "resource_not_found",
  "timestamp": 1542361812517,
  "duration": 0,
  "exception": "com.easemob.group.exception.ResourceNotFoundException",
  "error_description": "username tesuser doesn't exist!"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


修改群组信息

修改成功的数据行会返回 true,失败为 false。请求 body 只接收 groupname、description、maxusers、membersonly 四个属性,传不存在的字段,或者不能修改的字段会抛异常。

HTTP Request

/{org_name}/{app_name}/chatgroups/{group_id}

需要在请求时对应填写{group_id},需要修改的群组 ID 。

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

Request Body

参数说明
groupname群组名称,修改时值不能包含斜杠(“/“)
description群组描述,修改时值不能包含斜杠(”/“)
maxusers群组成员最大数(包括群主),值为数值类型
membersonly加入群组是否需要群主或者群管理员审批。true:是,false:否。

Response Body

在返回值中查看data字段包含的信息

参数说明
description群组描述,true表示修改成功,false表示修改失败
maxusers群组成员最大数,true表示修改成功,false表示修改失败
groupname群组名称,true表示修改成功,false表示修改失败
membersonly加入群组是否需要群主或者群管理员审批。true:是,false:否。

请求示例

curl -X PUT -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' -d '{  
   "groupname": "testgroup1",  
   "description": "test",  
   "maxusers": 300,
   "membersonly": true
 }' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617'

可能返回的结果示例

返回值200,表示群组信息修改成功

{
  "action": "put",
  "application": "8be024f0-e978-11e8-b697-5d598d5f8402",
  "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617",
  "entities": [],
  "data": {
    "membersonly": true,
    "description": true,
    "maxusers": true,
    "groupname": true
  },
  "timestamp": 1542363146301,
  "duration": 0,
  "organization": "easemob-demo",
  "applicationName": "testapp"
}

返回值404,群组ID不存在

{
  "error": "resource_not_found",
  "timestamp": 1542363205192,
  "duration": 0,
  "exception": "com.easemob.group.exception.ResourceNotFoundException",
  "error_description": "grpID 6602183678361 does not exist!"
}

返回值401,未授权[无token、token错误、token过期]

{
  "error": "group_authorization",
  "timestamp": 1542363254128,
  "duration": 0,
  "exception": "com.easemob.group.exception.GroupAuthorizationException",
  "error_description": "this token is bad, or has expired!"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


删除群组

删除一个群组的接口。

HTTP Request

/{org_name}/{app_name}/chatgroups/{group_id}

需要在请求时对应填写{group_id},需要删除的群组 ID 。

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

请求示例

curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617'

可能返回的结果示例

返回值200,表示群组删除成功

{
  "action": "delete",
  "application": "8be024f0-e978-11e8-b697-5d598d5f8402",
  "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617",
  "entities": [],
  "data": {
    "success": true,
    "groupid": "66021836783617"
  },
  "timestamp": 1542363546590,
  "duration": 0,
  "organization": "easemob-demo",
  "applicationName": "testapp"
}

返回值404,群组ID不存在

{
  "error": "resource_not_found",
  "timestamp": 1542363611915,
  "duration": 0,
  "exception": "com.easemob.group.exception.ResourceNotFoundException",
  "error_description": "grpID 6602183678361 does not exist!"
}

返回值401,未授权[无token、token错误、token过期]

{
  "error": "group_authorization",
  "timestamp": 1542363640975,
  "duration": 0,
  "exception": "com.easemob.group.exception.GroupAuthorizationException",
  "error_description": "this token is bad, or has expired!"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


环信提供多个接口实现对群组成员的管理,包括添加、移除群组成员关系列表,转让群主等

名称请求描述
分页获取群组成员/{org_name}/{app_name}/chatgroups/{group_id}/users分页获取一个群组的群成员列表
添加单个群组成员/{org_name}/{app_name}/chatgroups/{group_id}/users/{username}添加用户至群组成员列表
批量添加群组成员/{org_name}/{app_name}/chatgroups/{chatgroupid}/users批量添加用户至群组成员列表
移除单个群组成员/{org_name}/{app_name}/chatgroups/{group_id}/users/{username}从群组成员列表中移除用户
批量移除群组成员/{org_name}/{app_name}/chatgroups/{group_id}/users/{usernames}从群组成员列表中批量移除用户
获取群管理员列表/{org_name}/{app_name}/chatgroups/{group_id}/admin获取群组管理员列表
添加群管理员/{org_name}/{app_name}/chatgroups/{group_id}/admin添加用户至群组管理员列表
移除群管理员/{org_name}/{app_name}/chatgroups/{group_id}/admin/{oldadmin}从群组管理员列表中移除用户
转让群组/{org_name}/{app_name}/chatgroups/{groupid}转让群组owner

分页获取群组成员

可以分页获取群组成员列表的接口。

HTTP Request

/{org_name}/{app_name}/chatgroups/{group_id}/users

需要在请求时对应填写{group_id},需要获取的群组 ID 。

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

Response Body

在返回值中查看data字段包含的信息。

参数说明
owner群主的环信 ID。例如:{“owner”: “user1”}。
member群成员的环信 ID。例如:{“member”:“user2”}。

请求示例

curl -X GET HTTP://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/users?pagenum=2&pagesize=2 -H 'Authorization: Bearer YWMtG4T5wkOTEeST5V-9lp7f-wAAAUnafsqrQFnCU4gI0-rQImw4523fWqIasd1'

可能返回的结果示例

返回值200,表示群组成员获取成功

{
	  "action": "get",
	  "application": "527cd7e0-04b3-11e7-9f59-ef10ecd81ff0",
	  "params": {
	    "pagesize": [
	      "2"
	    ],
	    "pagenum": [
	      "2"
	    ]
	  },
	  "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/users",
	  "entities": [],
	  "data": [
	    {
	      "member": "user1"
	    },
	    {
	      "member": "user2"
	    }
	  ],
	  "timestamp": 1489074511416,
	  "duration": 0,
	  "organization": "easemob-demo",
	  "applicationName": "testapp",
	  "count": 2
	}

返回值404,群组ID不存在

{
  "error": "service_resource_not_found",
  "timestamp": 1542364673829,
  "duration": 0,
  "exception": "com.easemob.group.exception.ServiceResourceNotFoundException",
  "error_description": "do not find this group:66016455491581"
}

返回值401,未授权[无token、token错误、token过期]

{
  "error": "group_authorization",
  "timestamp": 1542364697076,
  "duration": 0,
  "exception": "com.easemob.group.exception.GroupAuthorizationException",
  "error_description": "this token is bad, or has expired!"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


添加单个群组成员

一次给群添加一个成员,不同重复添加同一个成员。如果用户已经是群成员,将添加失败,并返回错误。

HTTP Request

/{org_name}/{app_name}/chatgroups/{group_id}/users/{username}

需要在请求时对应填写{username},需要添加的 IM 用户名。

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

Response Body

在返回值中查看data字段包含的信息。

参数说明
result添加结果,true表示添加成功,false表示添加失败
groupid群组 ID
action执行的操作
user被添加的用户 ID

请求示例

curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/users/user4'

可能返回的结果示例

返回值200,表示添加群组成员成功

{
  "action": "post",
  "application": "8be024f0-e978-11e8-b697-5d598d5f8402",
  "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/users/user4",
  "entities": [],
  "data": {
    "result": true,
    "groupid": "66016455491585",
    "action": "add_member",
    "user": "user4"
  },
  "timestamp": 1542364958405,
  "duration": 0,
  "organization": "easemob-demo",
  "applicationName": "testapp"
}

返回值404,此群组id或被添加的人不存在

{
  "error": "resource_not_found",
  "timestamp": 1542365038436,
  "duration": 0,
  "exception": "com.easemob.group.exception.ResourceNotFoundException",
  "error_description": "username user8 doesn't exist!"
}

返回值401,未授权[无token、token错误、token过期]

{
  "error": "group_authorization",
  "timestamp": 1542365096789,
  "duration": 0,
  "exception": "com.easemob.group.exception.GroupAuthorizationException",
  "error_description": "this token is bad, or has expired!"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


批量添加群组成员

为群组添加多个成员,一次最多可以添加60位成员。如果所有用户均已是群成员,将添加失败,并返回错误。

HTTP Request

/{org_name}/{app_name}/chatgroups/{chatgroupid}/users

需要在请求时对应填写{chatgroupid},需要添加的群组 ID 。

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

Request Body

参数说明
usernamesusername1/username2 要添加到群中的成员用户名

Response Body

在返回值中查看data字段包含的信息。

参数说明
newmembers添加的群组成员 ID
groupid群组 ID
action执行的操作

请求示例

curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' -d '{  
   "usernames": [  
     "user4","user5"  
   ]  
 }' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/users'

可能返回的结果示例

返回值200,表示添加群组成员成功

{
  "action": "post",
  "application": "8be024f0-e978-11e8-b697-5d598d5f8402",
  "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/users",
  "entities": [],
  "data": {
    "newmembers": [
      "user5",
      "user4"
    ],
    "groupid": "66016455491585",
    "action": "add_member"
  },
  "timestamp": 1542365557942,
  "duration": 0,
  "organization": "easemob-demo",
  "applicationName": "testapp"
}

返回值404,此群组ID或被添加的人不存在

{
  "error": "resource_not_found",
  "timestamp": 1542365626633,
  "duration": 0,
  "exception": "com.easemob.group.exception.ResourceNotFoundException",
  "error_description": "grpID 6601645549158 does not exist!"
}

返回值401,未授权[无token、token错误、token过期]

{
  "error": "group_authorization",
  "timestamp": 1542365740570,
  "duration": 0,
  "exception": "com.easemob.group.exception.GroupAuthorizationException",
  "error_description": "this token is bad, or has expired!"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


移除单个群组成员

从群中移除某个成员。如果被移除用户不是群成员,将移除失败,并返回错误。

HTTP Request

/{org_name}/{app_name}/chatgroups/{group_id}/users/{username}

需要在请求时对应填写{username},需要移除的 IM 用户名。

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

Response Body

在返回值中查看data字段包含的信息。

参数说明
result移除结果,true表示添加成功,false表示添加失败
groupid群组 ID
action执行的操作
user被移除的用户 ID

请求示例

curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/users/user3'

可能返回的结果示例

返回值200,表示群组成员移除成功

{
  "action": "delete",
  "application": "8be024f0-e978-11e8-b697-5d598d5f8402",
  "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/users/user3",
  "entities": [],
  "data": {
    "result": true,
    "action": "remove_member",
    "user": "user3", 
    "groupid": "66016455491585"
  },
  "timestamp": 1542365943067,
  "duration": 0,
  "organization": "easemob-demo",
  "applicationName": "testapp"
}

返回值403,该成员不在此群组

{
  "error": "forbidden_op",
  "timestamp": 1542366087574,
  "duration": 0,
  "exception": "com.easemob.group.exception.ForbiddenOpException",
  "error_description": "users [user8] are not members of this group!"
}

返回值404,此群组ID不存在

{
  "error": "resource_not_found",
  "timestamp": 1542366050953,
  "duration": 0,
  "exception": "com.easemob.group.exception.ResourceNotFoundException",
  "error_description": "grpID 6601645549158 does not exist!"
}

返回值401,未授权[无token、token错误、token过期]

{
  "error": "group_authorization",
  "timestamp": 1542366178894,
  "duration": 0,
  "exception": "com.easemob.group.exception.GroupAuthorizationException",
  "error_description": "this token is bad, or has expired!"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


批量移除群组成员

移除群成员,用户名之间用英文逗号分隔。如果所有被移除用户均不是群成员,将移除失败,并返回错误。

HTTP Request

/{org_name}/{app_name}/chatgroups/{group_id}/users/{memebers}

需要在请求时对应填写{memebers},需要移除的 IM 用户名。

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

Response Body

在返回值中查看data字段包含的信息。

参数说明
result操作结果;true:移除成功,false:移除失败
action执行的操作;remove_member:移除群组成员
reason操作失败的原因
user被移除成员的用户名
groupid操作的群组 ID

请求示例

curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer YWMtduapFumREei8DkfcegKdAAAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnHD8qUwBPGgC0sPDXWLwWYh8ObqXytVlhbUhCTnbiIPi0oNGS8j2pDg' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/users/{memebers}'

可能返回的结果示例

返回值200,表示群组成员移除成功

{
    "action": "delete",
    "application": "9b848cf0-fafe-11e4-b5b8-0f74e8e740f7",
    "uri": "https://a1.easemob.com/easemob-demo/testapp",
    "entities": [],
    "data": [{
        "result": false,
        "action": "remove_member",
        "reason": "user ttestuser0015981 doesn't exist.",
        "user": "user1",
        "groupid": "1433492852257879"
    },
    {
        "result": true,
        "action": "remove_member",
        "user": "user2",
        "groupid": "1433492852257879"
    },
    {
        "result": true,
        "action": "remove_member",
        "user": "user3",
        "groupid": "1433492852257879"
    }],
    "timestamp": 1433492935318,
    "duration": 84,
    "organization": "easemob-demo",
    "applicationName": "testapp"
}

返回值403,该成员不在此群组

{
  "error": "forbidden_op",
  "timestamp": 1542367708303,
  "duration": 0,
  "exception": "com.easemob.group.exception.ForbiddenOpException",
  "error_description": "users [{memebers}] are not members of this group!"
}

返回值404,此群组ID不存在

{
  "error": "resource_not_found",
  "timestamp": 1542367736446,
  "duration": 0,
  "exception": "com.easemob.group.exception.ResourceNotFoundException",
  "error_description": "grpID 6601645549158 does not exist!"
}

返回值401,未授权[无token、token错误、token过期]

{
  "error": "group_authorization",
  "timestamp": 1542367755294,
  "duration": 0,
  "exception": "com.easemob.group.exception.GroupAuthorizationException",
  "error_description": "this token is bad, or has expired!"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


获取群管理员列表

获取群组管理员列表的接口。

HTTP Request

{org_name}/{app_name}/chatgroups/{group_id}/admin

需要在请求时对应填写{group_id},需要获取的群组 ID 。

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

Response Body

参数说明
data群组管理员信息

请求示例

curl -X GET HTTP://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/admin -H 'Authorization: Bearer YWMtG4T5wkOTEeST5V-9lp7f-wAAAUnafsqrQFnCU4gI0-rQImw4523fWqIasd1'

可能返回的结果示例

返回值200,表示获取群组管理员列表成功

{
    "action": "get",
    "application": "527cd7e0-04b3-11e7-9f59-ef10ecd81ff0",
    "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/admin",
    "entities": [],
    "data": ["user1"],
    "timestamp": 1489073361210,
    "duration": 0,
    "organization": "easemob-demo",
    "applicationName": "testapp",
    "count": 1
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


添加群管理员

将一个群成员角色提升为群管理员接口。

HTTP Request

/{org_name}/{app_name}/chatgroups/{group_id}/admin

需要在请求时对应填写{group_id},需要获取的群组 ID 。

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

Request Body

参数说明
newadmin添加的新管理员用户 ID

Response Body

参数说明
data添加的新管理员用户 ID

请求示例

curl -X POST HTTP://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/admin -d '{"newadmin":"user1"}' -H 'Authorization: Bearer YWMtG4T5wkOTEeST5V-9lp7f-wAAAUnafsqrQFnCU4gI0-rQImw4523fWqIasd1'

可能返回的结果示例

返回值200,表示获取群组管理员列表成功

{
    "action": "get",
    "application": "527cd7e0-04b3-11e7-9f59-ef10ecd81ff0",
    "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/admin",
    "entities": [],
    "data": ["user1"],
    "timestamp": 1489073361210,
    "duration": 0,
    "organization": "easemob-demo",
    "applicationName": "testapp",
    "count": 1
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


移除群管理员

将用户的角色从群管理员降为群普通成员接口。

HTTP Request

/{org_name}/{app_name}/chatgroups/{group_id}/admin/{oldadmin}

需要在请求时对应填写{group_id}和{oldadmin},需要移除的管理员所在群组和管理员的用户名。

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

请求示例

curl -X DELETE HTTP://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/admin/user1 -H 'Authorization: Bearer YWMtG4T5wkOTEeST5V-9lp7f-wAAAUnafsqrQFnCU4gI0-rQImw4523fWqIasd1'

可能返回的结果示例

返回值200,表示移除群组管理员成功

{
    "action": "delete",
    "application": "527cd7e0-04b3-11e7-9f59-ef10ecd81ff0",
    "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/admin/user1",
    "entities": [],
    "data": {
        "result": "success",
        "oldadmin": "user1"
    },
    "timestamp": 1489073432732,
    "duration": 1,
    "organization": "easemob-demo",
    "applicationName": "testapp"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


转让群组

修改群组 Owner 为同一群组中的其他成员。

HTTP Request

/{org_name}/{app_name}/chatgroups/{groupid}

需要在请求时对应填写{groupid},需要转让的群组 ID 。

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

Request Body

参数说明
newowner群组的新管理员 ID

Response Body

在返回值中查看data字段包含的信息。

参数说明
newowner群组的新管理员 ID

请求示例

curl -X PUT -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt7CoyjusbEeixOi3iod4eDAAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnJlhJIwBPGgCqtjiyVnR209iyr8kNbhJhhanNQDdP9CMmpK2G-NIUOQ' -d '{  
   "newowner": "user2"  
 }' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585'

可能返回的结果示例

返回值200,表示群组转移成功

{
  "action": "put",
  "application": "8be024f0-e978-11e8-b697-5d598d5f8402",
  "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585",
  "entities": [],
  "data": {
    "newowner": true
  },
  "timestamp": 1542537813420,
  "duration": 0,
  "organization": "easemob-demo",
  "applicationName": "testapp"
}

返回值403,该成员不在此群组

{
  "error": "forbidden_op",
  "timestamp": 1542538459201,
  "duration": 0,
  "exception": "com.easemob.group.exception.ForbiddenOpException",
  "error_description": "user: user6 doesn't exist in group: 66016455491585"
}

返回值404,此群组ID不存在

{
  "error": "resource_not_found",
  "timestamp": 1542367736446,
  "duration": 0,
  "exception": "com.easemob.group.exception.ResourceNotFoundException",
  "error_description": "grpID 6601645549158 does not exist!"
}

返回值401,未授权[无token、token错误、token过期]

{
  "error": "group_authorization",
  "timestamp": 1542538513851,
  "duration": 0,
  "exception": "com.easemob.group.exception.GroupAuthorizationException",
  "error_description": "this token is bad, or has expired!"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


环信提供多个接口完成群组黑名单管理,包括查看、将用户添加、移除黑名单等。

查询群组黑名单/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users查看群组的黑名单列表
添加单个用户至群组黑名单/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users/{username}将用户添加至群组的黑名单列表
批量添加用户至群组黑名单/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users将用户批量添加至群组的黑名单列表
从群组黑名单移除单个用户/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users/{username}将用户从黑名单列表中移除
批量从群组黑名单移除用户/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users/{usernames}批量将用户从黑名单列表中移除

查询群组黑名单

查询一个群组黑名单中的用户列表。位于黑名单中的用户查看不到该群组的信息,也无法收到该群组的消息。

HTTP Request

/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users

需要在请求时对应填写{group_id},需要查询的群组 ID 。

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

Response Body

在返回值中查看data字段包含的信息。

参数说明
data群组黑名单用户 ID

请求示例

curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer YWMt7CoyjusbEeixOi3iod4eDAAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnJlhJIwBPGgCqtjiyVnR209iyr8kNbhJhhanNQDdP9CMmpK2G-NIUOQ' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/blocks/users'

可能返回的结果示例

返回值200,表示群组黑名单查询成功

{
  "action": "get",
  "application": "8be024f0-e978-11e8-b697-5d598d5f8402",
  "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/67178793598977/blocks/users",
  "entities": [],
  "data": [
    "user2",
    "user3"
  ],
  "timestamp": 1543466293681,
  "duration": 0,
  "organization": "easemob-demo",
  "applicationName": "testapp",
  "count": 2
}

返回值404,该群组ID不存在

{
  "error": "resource_not_found",
  "timestamp": 1542539206941,
  "duration": 0,
  "exception": "com.easemob.group.exception.ResourceNotFoundException",
  "error_description": "grpID 6601645549158 does not exist!"
}

返回值401,未授权[无token、token错误、token过期]

{
  "error": "group_authorization",
  "timestamp": 1542539245149,
  "duration": 0,
  "exception": "com.easemob.group.exception.GroupAuthorizationException",
  "error_description": "this token is bad, or has expired!"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


添加单个用户至群组黑名单

添加一个用户进入一个群组的黑名单。群主无法被加入群组的黑名单。

用户进入群组黑名单后,会收到消息:You are kicked out of the group xxx。之后,该用户查看不到该群组的信息,也收不到该群组的消息。

HTTP Request

/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users/{username}

需要在请求时对应填写{group_id},需要添加黑名单的群组 ID ,以及需{username},要添加的 IM 用户名。

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

Response Body

在返回值中查看data字段包含的信息。

参数说明
result添加结果,true表示添加成功,false表示添加失败
groupid群组 ID
action执行操作
user被添加的用户 ID

请求示例

curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt7CoyjusbEeixOi3iod4eDAAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnJlhJIwBPGgCqtjiyVnR209iyr8kNbhJhhanNQDdP9CMmpK2G-NIUOQ' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/blocks/users/user1'

可能返回的结果示例

返回值200,添加用户至群组黑名单成功

{
  "action": "post",
  "application": "8be024f0-e978-11e8-b697-5d598d5f8402",
  "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/blocks/users/user1",
  "entities": [],
  "data": {
    "result": true,
    "action": "add_blocks",
    "user": "user1",
    "groupid": "66016455491585"
  },
  "timestamp": 1542539577124,
  "duration": 27,
  "organization": "easemob-demo",
  "applicationName": "testapp"
}

返回值404,该群组ID不存在

{
  "error": "resource_not_found",
  "timestamp": 1542539654833,
  "duration": 0,
  "exception": "com.easemob.group.exception.ResourceNotFoundException",
  "error_description": "grpID 6601645549158 does not exist!"
}

返回值403,该用户不存在

{
  "error": "forbidden_op",
  "timestamp": 1542539679705,
  "duration": 0,
  "exception": "com.easemob.group.exception.ForbiddenOpException",
  "error_description": "users [user10] are not members of this group!"
}

返回值401,未授权[无token、token错误、token过期]

{
  "error": "group_authorization",
  "timestamp": 1542539732510,
  "duration": 0,
  "exception": "com.easemob.group.exception.GroupAuthorizationException",
  "error_description": "this token is bad, or has expired!"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


批量添加用户至群组黑名单

添加多个用户进入一个群组的黑名单,一次性最多可以添加60个用户。群主无法被加入群组的黑名单。

用户进入群组黑名单后,会收到消息:You are kicked out of the group xxx。之后,该用户查看不到该群组的信息,也收不到该群组的消息。

HTTP Request

/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users

需要在请求时对应填写{group_id},需要添加黑名单的群组 ID ,以及需{username},要添加的 IM 用户名。

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

Request Body

参数说明
usernames添加的用户名 ID

Response Body

在返回值中查看data字段包含的信息。

参数说明
result添加结果,true表示添加成功,false表示添加失败
reason添加失败的原因
groupid群组 ID
action执行的操作
user被添加的用户 ID

请求示例

curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt7CoyjusbEeixOi3iod4eDAAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnJlhJIwBPGgCqtjiyVnR209iyr8kNbhJhhanNQDdP9CMmpK2G-NIUOQ' -d '{  
   "usernames": [  
     "user3","user4"  
   ]  
 }' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/blocks/users'

可能返回的结果示例

返回值200,添加用户至群组黑名单成功

{
  "action": "post",
  "application": "8be024f0-e978-11e8-b697-5d598d5f8402",
  "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/blocks/users",
  "entities": [],
  "data": [
    {
      "result": false,
      "action": "add_blocks",
      "reason": "user: user3 doesn't exist in group: 66016455491585",
      "user": "user3",
      "groupid": "66016455491585"
    },
    {
      "result": true,
      "action": "add_blocks",
      "user": "user4",
      "groupid": "66016455491585"
    }
  ],
  "timestamp": 1542540095540,
  "duration": 16,
  "organization": "easemob-demo",
  "applicationName": "testapp"
}

返回值404,该群组ID不存在

{
  "error": "resource_not_found",
  "timestamp": 1542540155192,
  "duration": 1,
  "exception": "com.easemob.group.exception.ResourceNotFoundException",
  "error_description": "grpID 6601645549158 does not exist!"
}

返回值403,该用户不存在或不能添加群主至黑名单

{
  "error": "forbidden_op",
  "timestamp": 1542540210145,
  "duration": 0,
  "exception": "com.easemob.group.exception.ForbiddenOpException",
  "error_description": "forbidden operation on group owner!"
}

返回值401,未授权[无token、token错误、token过期]

{
  "error": "group_authorization",
  "timestamp": 1542540260660,
  "duration": 0,
  "exception": "com.easemob.group.exception.GroupAuthorizationException",
  "error_description": "this token is bad, or has expired!"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


从群组黑名单移除单个用户

从群组黑名单中移除一个用户。对于群组黑名单中的用户,如果需要将其再次加入群组,需要先将其从群组黑名单中移除。

HTTP Request

/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users/{username}

需要在请求时对应填写{group_id},需要移除黑名单的群组 ID ,以及需{username},要移除的 IM 用户名。

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

请求示例

curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer YWMt7CoyjusbEeixOi3iod4eDAAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnJlhJIwBPGgCqtjiyVnR209iyr8kNbhJhhanNQDdP9CMmpK2G-NIUOQ' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/blocks/users/user1'

可能返回的结果示例

返回值200,移除用户黑名单成功

{
  "action": "delete",
  "application": "8be024f0-e978-11e8-b697-5d598d5f8402",
  "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/blocks/users/user1",
  "entities": [],
  "data": {
    "result": true,
    "action": "remove_blocks",
    "user": "user1",
    "groupid": "66016455491585"
  },
  "timestamp": 1542540470679,
  "duration": 45,
  "organization": "easemob-demo",
  "applicationName": "testapp"
}

返回值404,该群组ID不存在

{
  "error": "resource_not_found",
  "timestamp": 1542540559252,
  "duration": 0,
  "exception": "com.easemob.group.exception.ResourceNotFoundException",
  "error_description": "grpID 6601645549158 does not exist!"
}

返回值404,该用户不存在

{
  "error": "resource_not_found",
  "timestamp": 1542540616864,
  "duration": 0,
  "exception": "com.easemob.group.exception.ResourceNotFoundException",
  "error_description": "username user10 doesn't exist!"
}

返回值401,未授权[无token、token错误、token过期]

{
  "error": "group_authorization",
  "timestamp": 1542540739864,
  "duration": 0,
  "exception": "com.easemob.group.exception.GroupAuthorizationException",
  "error_description": "this token is bad, or has expired!"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


批量从群组黑名单移除用户

从群组黑名单中移除多个用户。对于群组黑名单中的用户,如果需要将其再次加入群组,需要先将其从群组黑名单中移除。

HTTP Request

/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users/{usernames}

需要在请求时对应填写{group_id},需要移除黑名单的群组 ID ,以及需{username},要移除的 IM 用户名。

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

请求示例

curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer YWMt7CoyjusbEeixOi3iod4eDAAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnJlhJIwBPGgCqtjiyVnR209iyr8kNbhJhhanNQDdP9CMmpK2G-NIUOQ' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/blocks/users/user1%2Cuser2'

可能返回的结果示例

返回值200,移除用户黑名单成功

{
  "action": "delete",
  "application": "8be024f0-e978-11e8-b697-5d598d5f8402",
  "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/blocks/users/user1%2Cuser2",
  "entities": [],
  "data": [
    {
      "result": true,
      "action": "remove_blocks",
      "user": "user1",
      "groupid": "66016455491585"
    },
    {
      "result": true,
      "action": "remove_blocks",
      "user": "user2",
      "groupid": "66016455491585"
    }
  ],
  "timestamp": 1542541014655,
  "duration": 29,
  "organization": "easemob-demo",
  "applicationName": "testapp"
}

返回值404,该群组ID不存在

{
  "error": "resource_not_found",
  "timestamp": 1542541067286,
  "duration": 0,
  "exception": "com.easemob.group.exception.ResourceNotFoundException",
  "error_description": "grpID 6601645549158 does not exist!"
}

返回值404,该用户不存在

{
  "error": "resource_not_found",
  "timestamp": 1542541102793,
  "duration": 0,
  "exception": "com.easemob.group.exception.ResourceNotFoundException",
  "error_description": "username user10 doesn't exist!"
}

返回值401,未授权[无token、token错误、token过期]

{
  "error": "group_authorization",
  "timestamp": 1542541134588,
  "duration": 0,
  "exception": "com.easemob.group.exception.GroupAuthorizationException",
  "error_description": "this token is bad, or has expired!"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


环信提供多个接口群组禁言列表的管理,包括查看、将用户添加、移除禁言列表等。

名称请求描述
添加禁言/{org_name}/{app_name}/chatgroups/{group_id}/mute添加用户至群组的禁言列表
移除禁言/{org_name}/{app_name}/chatgroups/{group_id}/mute/{member1}(,{member2},…)从群组的禁言列表中移除用户
获取禁言列表/{org_name}/{app_name}/chatgroups/{group_id}/mute获取群组的禁言列表

添加禁言

将一个用户禁言。用户被禁言后,将无法在群中发送消息。

HTTP Request

/{org_name}/{app_name}/chatgroups/{group_id}/mute

需要在请求时对应填写{group_id},需要移除黑名单的群组 ID ,以及需{username},要移除的 IM 用户名。

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

Request Body

参数说明
mute_duration禁言的时间,单位毫秒,如果是“-1000”代表永久
usernames要被添加禁言用户的 ID

Response Body

参数说明
result操作结果;true:添加成功;false:添加失败
expire禁言到期时间
user被禁言用户的 ID

请求示例

curl -X POST HTTP://a1.easemob.com/easemob-demo/testuser/chatgroups/10130212061185/mute -d '{"usernames":["user1"], "mute_duration":86400000}' -H 'Authorization: Bearer YWMtG4T5wkOTEeST5V-9lp7f-wAAAUnafsqrQFnCU4gI0-rQImw4523fWqIasd1'

可能返回的结果示例

返回值200,添加禁言成功

{
    "action": "post",
    "application": "527cd7e0-04b3-11e7-9f59-ef10ecd81ff0",
    "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/mute",
    "entities": [],
    "data": [{
        "result": true,
        "expire": 1489158589481,
        "user": "user1"
    }],
    "timestamp": 1489072189508,
    "duration": 0,
    "organization": "easemob-demo",
    "applicationName": "testapp"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


移除禁言

将用户从禁言列表中移除。移除后,用户可以正常在群中发送消息。

HTTP Request

/{org_name}/{app_name}/chatgroups/{group_id}/mute/{member1}(,{member2},…)

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

请求示例

curl -X DELETE HTTP://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/mute/user1  -H 'Authorization: Bearer YWMtG4T5wkOTEeST5V-9lp7f-wAAAUnafsqrQFnCU4gI0-rQImw4523fWqIasd1'

可能返回的结果示例

返回值200,表示移除禁言成功

{
    "action": "delete",
    "application": "527cd7e0-04b3-11e7-9f59-ef10ecd81ff0",
    "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/mute/user1",
    "entities": [],
    "data": [{
        "result": true,
        "user": "user1"
    }],
    "timestamp": 1489072695859,
    "duration": 0,
    "organization": "easemob-demo",
    "applicationName": "testapp"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


获取禁言列表

获取当前群组的禁言用户列表。

HTTP Request

/{org_name}/{app_name}/chatgroups/{group_id}/mute

Request Headers

参数说明
Content-Typeapplication/json
AuthorizationBearer ${token}

Response Body

参数说明
expire禁言到期时间,单位毫秒。“-1000“代表永久禁言
user被禁言用户的 ID

请求示例

curl -X GET HTTP://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/mute -H 'Authorization: Bearer YWMtG4T5wkOTEeST5V-9lp7f-wAAAUnafsqrQFnCU4gI0-rQImw4523fWqIasd1'

可能返回的结果示例

返回值200,表示获取禁言列表成功

{
    "action": "post",
    "application": "527cd7e0-04b3-11e7-9f59-ef10ecd81ff0",
    "uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/mute",
    "entities": [],
    "data": [{
        "expire": 1489158589481,
        "user": "user1"
    }],
    "timestamp": 1489072802179,
    "duration": 0,
    "organization": "easemob-demo",
    "applicationName": "testapp"
}

如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见接口限流说明

使用 Easemob REST API 在线测试


上一页:发送消息

下一页:聊天室管理