Create, delete, and retrieve threads
This page shows how to create, modify, delete, and retrieve a thread by calling Chat RESTful APIs. Before calling the following methods, ensure that you understand the call frequency limit described in Limitations.
Common parameters
The following table lists common request and response parameters of the Chat RESTful APIs:
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
host | String | The domain name assigned by the Chat service to access RESTful APIs. For how to get the domain name, see Get the information of your project. | Yes |
org_name | String | The unique identifier assigned to each company (organization) by the Chat service. For how to get the org name, see Get the information of your project. | Yes |
app_name | String | The unique identifier assigned to each app by the Chat service. For how to get the app name, see Get the information of your project. | Yes |
Response parameters
Parameter | Type | Description |
---|---|---|
action | String | The request method. |
organization | String | The unique identifier assigned to each company (organization) by the Chat service. This is the same as org_name . |
application | String | A unique internal ID assigned to each app by the Chat service. You can safely ignore this parameter. |
applicationName | String | The unique identifier assigned to each app by the Chat service. This is the same as app_name . |
data | JSON | The details of the response. |
timestamp | Number | The Unix timestamp (ms) of the HTTP response. |
duration | Number | The duration (ms) from when the HTTP request is sent to the time the response is received. |
uri | String | The request URI. |
path | String | The request path, which is part of the request URI. You can safely ignore this parameter. |
entities | JSON | The response entity. |
properties | String | The request property. |
Authorization
Chat RESTful APIs require Bearer HTTP authentication. Every time an HTTP request is sent, the following Authorization
field must be filled in the request header:
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. Chat RESTful APIs only support authenticating users using app tokens. For details, see Authentication using App Token.
Creating a thread
Creates a thread.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
For the descriptions of the path parameters, see Common Parameters.
Request header
For the descriptions of the request headers, see Authorization.
Request body
Parameter | Type | Description | Required |
---|---|---|---|
group_id | String | The ID of the group to which the thread belongs. | Yes |
name | String | The name of the thread. The maximum length of the thread name is 64 characters. | Yes |
msg_id | String | The ID of the message based on which the thread is created. | Yes |
owner | String | The username of the thread creator. | Yes |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the data field in the response body contains the following parameters:
Parameter | Type | Description |
---|---|---|
thread_id | String | The ID of the thread. |
For other fields and descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible causes.
Example
Request example
Response example
Modifying a thread
Changes the name of the specified thread.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
thread_id | String | The ID of the thread. | Yes |
For the descriptions of the other path parameters, see Common Parameters.
Request header
For the descriptions of the request headers, see Authorization.
Request body
Parameter | Type | Description | Required |
---|---|---|---|
name | String | The updated name of the thread. The maximum length of the thread name is 64 characters. | Yes |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the data field in the response body contains the following parameters:
Parameter | Type | Description |
---|---|---|
name | String | The updated name of the thread. |
For other fields and descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible causes.
Example
Request example
Response example
Deleting a thread
Deletes the specified thread.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
thread_id | String | The ID of the thread. | Yes |
For the descriptions of the other path parameters, see Common Parameters.
Request header
For the descriptions of the request headers, see Authorization.
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the data field in the response body contains the following parameters:
Parameter | Type | Description |
---|---|---|
status | String | Whether the thread is deleted. ok indicates that the thread is deleted. |
For other fields and descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible causes.
Example
Request example
Response example
Retrieving all the threads under the app
Retrieves all the threads under the app.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
limit | String | The maximum number of threads to retrieve per page. The range is [1, 50]. The default value is 50. | No |
cursor | String | The page from which to start retrieving threads. Pass in null or an empty string at the first query. | No |
sort | String | The order in which to list the query results:asc : In chronological order of thread creation.desc : In reverse chronological order of thread creation. | No |
For the descriptions of the other path parameters, see Common Parameters.
Request header
For the descriptions of the request headers, see Authorization.
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the entity field in the response body contains the following parameters:
Parameter | Type | Description |
---|---|---|
id | String | The ID of the thread. |
properties.cursor | String | The cursor that indicates the starting position of the next query. |
For other fields and descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible causes.
Example
Request example
Response example
Retrieving all the threads a user joins under the app
Retrieves all the threads a user joins under the app.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
For the descriptions of the path parameters, see Common Parameters.
Query parameter
Parameter | Type | Description | Required |
---|---|---|---|
limit | String | The maximum number of threads to retrieve per page. The range is [1, 50]. The default value is 50. | No |
cursor | String | The page from which to start retrieving threads. Pass in null or an empty string at the first query. | No |
sort | String | The order in which to list the query results:asc : In chronological order of thread creation.desc : In reverse chronological order of thread creation. | No |
For the descriptions of the other path parameters, see Common Parameters.
Request header
For the descriptions of the request headers, see Authorization.
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the entity field in the response body contains the following parameters:
Parameter | Type | Description |
---|---|---|
name | String | The thread name. |
owner | String | The thread creator. |
id | String | The thread ID. |
msgId | String | The ID of the message based on which the thread is created. |
groupId | String | The ID of the chat group to which the thread belongs. |
created | String | The Unix timestamp when the thread is created. |
properties.cursor | String | The cursor that indicates the starting position of the next query. |
For other fields and descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible causes.
Example
Request example
Response example
Retrieving all the threads a user joins under a chat group
Retrieves all the threads a user joins under a chat group.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
group_id | String | The ID of the chat group. | Yes |
username | String | The unique login account of the user. | Yes |
For the descriptions of the other path parameters, see Common Parameters.
Query parameter
Parameter | Type | Description | Required |
---|---|---|---|
limit | String | The maximum number of threads to retrieve per page. The range is [1, 50]. The default value is 50. | No |
cursor | String | The page from which to start retrieving threads. Pass in null or an empty string at the first query. | No |
sort | String | The order in which to list the query results:asc : In chronological order of thread creation.desc : In reverse chronological order of thread creation. | No |
Request header
For the descriptions of the request headers, see Authorization.
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the entity field in the response body contains the following parameters:
Parameter | Type | Description |
---|---|---|
name | String | The thread name. |
owner | String | The thread creator. |
id | String | The thread ID. |
msgId | String | The ID of the message based on which the thread is created. |
groupId | String | The ID of the chat group to which the thread belongs. |
created | String | The Unix timestamp when the thread is created. |
For other fields and descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible causes.
Example
Request example
Response example
Status codes
For details, see HTTP Status Codes.