Skip to main content

Chat RESTful API overview

Chat provides RESTful APIs through the REST platform. You can send HTTP requests to the Agora server through your business server to realize real-time communication on the server side.

REST Platform Architecture

The Chat REST platform provides a multi-tenant architecture to manage resources in the form of a Collection. A Collection contains the following:

  • Database
  • Organizations (orgs)
  • Apps (apps)
  • Users (users)
  • Chat groups (chatgroups)
  • Chat messages (chatmessages)
  • Chat files (chatfiles)

The user data of different orgs is isolated from each other. Under the same org, the user data of different apps is also isolated from each other. The data structure of an org is as follows:

1642333129463

Prerequisites

Ensure that you meet the following requirements before calling the Chat RESTful API:

Features

User system integration

This group of methods enables you to implement user system management, including user registration, retrieving users, modifying user attributes, and deleting users.

NameMethodRequestDescription
Registering a userPOST/{org_name}/{app_name}/usersCreates a user account.
Registering multiple usersPOST/{org_name}/{app_name}/usersCreates multiple user accounts.
Retrieving a userGET/{org_name}/{app_name}/users/{username}Retrieves the information of the specified user.
Retrieving multiple users.GET/{org_name}/{app_name}/usersRetrieves the information of the specified users.
Deleting a userDELETE/{org_name}/{app_name}/users/{username}Deletes the specified user.
Deleting multiple usersDELETE/{org_name}/{app_name}/usersDeletes all the users in the app.
Modifying the passwordPUT/{org_name}/{app_name}/users/{username}/passwordChanges the user's password.
Banning a userPOST/{org_name}/{app_name}/users/{username}/deactivateBans a user.
Unbanning a userPOST/{org_name}/{app_name}/users/{username}/activateUnbans a user.
Forcing a user offlinePOST/{org_name}/{app_name}/users/{username}/disconnectForcibly moves a user offline.
Querying the online stateGET/{org_name}/{app_name}/users/{username}/statusQueries whether a user is online.
Querying the online state of multiple usersPOST/{org_name}/{app_name}/users/batch/statusQueries whether multiple users are online.
Querying the number of offline messagesGET/{org_name}/{app_name}/users/{owner_username}/offline_msg_countQueries the number of offline messages a user has.
Querying the delivery state of an offline messageGET/{org_name}/{app_name}/users/{username}/offline_msg_status/{msg_id}Queries the delivery state of an offline message.

Message push

This group of methods enables you to set the push message display mode, display nickname, and do-not-disturb mode.

NameMethodRequestDescription
Setting the display nicknamePUT/{org_name}/{app_name}/users/{username}Sets the display nickname of the push message.
Setting the display optionsPUT/{org_name}/{app_name}/users/{username}Sets whether the push messages are displayed as notifications only or details are visible.
Setting do-not-disturb (DND)PUT/{org_name}/{app_name}/users/{username}Sets whether to enable DND, and the time to enable and disable DND.

Sending messages and uploading/downloading files

This group of methods enables you to send text, image, voice, video, pass-through, extension, file, custom, and other types of messages, as well as to upload and download files from the server.

NameMethodRequestDescription
Sending a messagePOST/{org_name}/{app_name}/messagesApp admins use this method to send messages to users or groups, and support sending text, image, voice, video, pass-through, extension, and file messages.
Uploading filesPOST/{org_name}/{app_name}/chatfilesUploads voice and image files.
Downloading filesPOST/{org_name}/{app_name}/chatfiles/{uuid}Downloads voice and image files.
Retrieving historical messagesGET/{org_name}/{app_name}/chatmessages/${time}Retrieves chat historical messages
Retrieving the conversation listGET/{org_name}/{app_name}/user/{username}/user_channelsRetrieves a list of conversations of the specified user.
Recalling a messagePOST{org_name}/{app_name}/messages/recallRecalls a message two minutes after it is sent.
Deleting conversations from the serverDELETE/{orgName}/{appName}/users/{userName}/user_channelDeletes the conversation from the server.

User attributes

This group of methods enables you to set, retrieve, and delete user attributes.

NameMethodRequestDescription
Setting user attributesPUT/{org_name}/{app_name}/metadata/user/{username}Sets the user attributes for the specified user.
Retrieving user attributesGET/{org_name}/{app_name}/metadata/user/{username}Retrieves all the user attributes of the specified user.
Retrieving the user attributes of multiple usersPOST/{org_name}/{app_name}/metadata/user/getRetrieves multiple users' attributes by specifying the user name list and user attribute list.
Deleting user attributesDELETE/{org_name}/{app_name}/metadata/user/{username}Deletes all the user attributes for the specified user.
Retrieving the total size of user attributesGET/{org_name}/{app_name}/metadata/user/capacityGets the total size of user attributes for all the users in the app.

Contact management

This group of methods enables you to manage the user's contact list and block list.

NameMethodRequestDescription
Adding a contactPOST/{org_name}/{app_name}/users/{owner_username}/contacts/users/{friend_username}Adds the specified user as a contact.
Removing a contactDELETE/{org_name}/{app_name}/users/{owner_username}/contacts/users/{friend_username}Removes the specified user from the contact list.
Retrieving a contact listGET/{org_name}/{app_name}/users/{owner_username}/contacts/usersRetrieves the contact list.
Retrieving a block listGET/{org_name}/{app_name}/users/{owner_username}/blocks/usersRetrieves the block list.
Adding user to block listPOST/{org_name}/{app_name}/users/{owner_username}/blocks/usersAdd the specified user to the block list.
Removing user from block listDELETE/{org_name}/{app_name}/users/{owner_username}/blocks/users/{blocked_username}Removes the specified user from the block list.

Chat group management

This group of methods enables you to create, retrieve, modify, and delete chat groups.

NameMethodRequestDescription
Retrieving all chat groups in the app (Pagination)GET/{org_name}/{app_name}/chatgroupsRetrieves the information of all the groups in the app.
Retrieving all the chat groups the user joinsGET/{app_name}/users/{username}/joined_chatgroupsRetrieves all the groups the user joins by specifying the user name.
Retrieving chat group detailsGET/{org_name}/{app_name}/chatgroups/{group_ids}Retrieves the information of the group details by specifying the group ID.
Creating a chat groupPOST/{org_name}/{app_name}/chatgroupsCreates a chat group.
Modifying chat group informationPUT/{org_name}/{app_name}/chatgroups/{group_id}Modifies the group information.
Deleting a chat groupDELETE/{org_name}/{app_name}/chatgroups/{group_id}Deletes a chat group.

Chat group member management

This group of methods enables you to manage chat group members, including adding and removing chat group members, transferring chat group ownership, and retrieving lists of chat group admins and members.

NameMethodRequestDescription
Retrieving chat group member list (Pagination)GET/{org_name}/{app_name}/chatgroups/{group_id}/usersRetrieves the member list of the chat group by pagination.
Adding a chat group memberPOST/{org_name}/{app_name}/chatgroups/{group_id}/users/{username}Adds a user to the group member list.
Adding multiple group membersPOST/{org_name}/{app_name}/chatgroups/{chatgroupid}/usersAdds multiple users to the group member list.
Removing a chat group memberDELETE/{org_name}/{app_name}/chatgroups/{group_id}/users/{username}Removes the specified user from the group member list.
Removing multiple chat group membersDELETE/{org_name}/{app_name}/chatgroups/{group_id}/users/{usernames}Removes the specified users from the group members list.
Retrieving chat group admin listGET/{org_name}/{app_name}/chatgroups/{group_id}/adminRetrieves the group admin list.
Adding a chat group admin.POST/{org_name}/{app_name}/chatgroups/{group_id}/adminAdds the specified user to the group admin list.
Removing a chat group adminDELETE/{org_name}/{app_name}/chatgroups/{group_id}/admin/{oldadmin}Removes the specified user from the group admin list.
Transferring chat group ownershipPUT/{org_name}/{app_name}/chatgroups/{groupid}Transfers the group owner privileges.

Chat room management

This group of methods enables you to create, retrieve, modify, and delete chat rooms.

NameMethodRequestDescription
Retrieving all chat roomsGET/{org_name}/{app_name}/chatroomsRetrieves the information of all the chat rooms in the app.
Retrieving chat rooms a user joinsGET/{org_name}/{app_name}/users/{username}/joined_chatroomsRetrieves the chat rooms that a user joins by specifying the username.
Retrieving chat room detailsGET/{org_name}/{app_name}/chatrooms/{chatroom_id}Retrieves the details of the chat room by specifying the chat room ID.
Creating a chat roomPOST/{org_name}/{app_name}/chatroomsCreates a new chat room.
Modifying chat room informationPUT/{org_name}/{app_name}/chatrooms/{chatroom_id}Modifies the chat room information.
Deleting a chat roomDELETE/{org_name}/{app_name}/chatrooms/{chatroom_id}Deletes a chat room.

Chat room member management

This group of methods enables you to add, retrieve, modify, and delete members from the chat room.

NameMethodRequestDescription
Retrieving chat room member list (Pagination)GET/{org_name}/{app_name}/chatrooms/{chatroom_id}/usersRetrieves the member list of the chat room by pagination.
Adding a chat room memberPOST/{org_name}/{app_name}/chatrooms/{chatroomid}/users/{username}Adds the specified user to the chat room member list.
Adding multiple chat room membersPOST/{org_name}/{app_name}/chatrooms/{chatroomid}/usersAdds multiple specified users to the chat room member list.
Removing a chat room memberDELETE/{org_name}/{app_name}/chatrooms/{chatroomid}/users/{username}Removes the specified user from the chat room member list.
Removing multiple chat room membersDELETE/{org_name}/{app_name}/chatrooms/{chatroomid}/users/{usernames}Removes the specified users from the chat room member list.
Retrieving chat room admin listGET/{org_name}/{app_name}/chatrooms/{chatroom_id}/adminRetrieves the chat room admin list.
Adding a chat room adminPOST/{org_name}/{app_name}/chatrooms/{chatroom_id}/adminAdds the specified user to the chat room admin list.
Removing a chat room adminDELETE/{org_name}/{app_name}/chatrooms/{chatroom_id}/admin/{oldadmin}Remove the specified user from the chat room admin list.

Global mute

This group of methods enable you to mute any user ID in one-to-one chats, group chats, or chat rooms, preventing these users from sending messages to other chat users, chat groups, or chat rooms.

NameMethodRequestDescription
Globally mute a specified userPOST/{orgName}/{appName}/mutesMutes a specified user in one-to-one chats, chat groups, or chat rooms.
Query the detailed information of global-muteGET/{orgName}/{appName}/mutes/usernameQueries the detailed information of the global-mute settings of the specified user in one-to-one chats, group chats, or chatrooms.
Retrieve all globally muted usersGET/{orgName}/{appName}/mutesRetrieves all the users that have been globally muted in the app.

Reaction

This group of methods enable your chat users to reply the message with emojis.

NameMethodRequestDescription
Create a reactionPOST/{org_name}/{app_name}/reaction/user/{userId}Creates or adds a reaction to a specified message.
Retrieve reactions with message IDsGET/{org_name}/{app_name}/reaction/user/{userId}Retrieves the information of the reaction according to the message ID.
Delete a reactionDELETE/{org_name}/{app_name}/reaction/user/{userId}Deletes a reaction.
Retrieve the detailed information of the reactionGET/{org_name}/{app_name}/reaction/user/{userId}/detailRetrieves the detailed information of the reaction by specifying the message ID and reaction ID.

Request structure

Authorization

The Chat RESTful APIs requires Bearer HTTP authentication. Every time an HTTP request is sent, the following Authorization field must be filled in the request header:


_1
Authorization: Bearer ${token}

In order to improve the security of the project, Agora uses a token (dynamic key) to authenticate users before they log in to the chat system. The Chat RESTful API only supports authenticating users using app tokens. For details, see Authentication using App Token.

Server address

Under the same project, all requests are sent to the same domain name. For how to get the domain name, see Get the information of the Chat project.

Protocol

To ensure communication security, the Chat RESTful API only supports the HTTPS protocol.

Data Format

  • Request: See the code sample of each API for the data format of the request.
  • Response: The format of the response is JSON.

All request URLs and request bodies are case sensitive.

Page Content