Create, delete, and retrieve threads

Updated

Agora Chat RESTful APIs for creating, deleting, and retrieving 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

ParameterTypeDescriptionRequired
hostStringThe 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
app_idStringThe unique identifier automatically assigned to each project by AgoraYes

Response parameters

ParameterTypeDescription
actionStringThe request method.
organizationStringThe unique identifier assigned to each company (organization) by the Chat service.
applicationStringA unique internal ID assigned to each app by the Chat service. You can safely ignore this parameter.
applicationNameStringThe unique identifier assigned to each app by the Chat service.
dataJSONThe details of the response.
timestampNumberThe Unix timestamp (ms) of the HTTP response.
durationNumberThe duration (ms) from when the HTTP request is sent to the time the response is received.
uriStringThe request URI.
pathStringThe request path, which is part of the request URI. You can safely ignore this parameter.
entities JSONThe response entity.
propertiesStringThe 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:

Authorization: Bearer ${YourAppToken}

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. An app can have up to 100,000 threads by default. To increase the limit, contact support@agora.io.

For each App Key, the call frequency limit of this method is 100 per second.

HTTP request

POST https://{host}/app-id/{app_id}/thread

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

ParameterTypeDescriptionRequired
group_idStringThe ID of the group to which the thread belongs.Yes
nameStringThe name of the thread. The maximum length of the thread name is 64 characters.Yes
msg_idStringThe ID of the message based on which the thread is created.Yes
ownerStringThe 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:

ParameterTypeDescription
thread_idStringThe 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

curl -X POST http://XXXX.com/XXXX/testapp/thread -H 'Authorization: Bearer ' -H 'Content-Type:application/json' -d '
{
    "group_id": 179800091197441,
    "name": "1",
    "owner": "test4",
    "msg_id": 1234
}'

Response example

{
    "action": "post",
    "applicationName": "testapp",
    "duration": 4,
    "data": {
        "thread_id": "177916702949377"
    },
    "organization": "XXXX",
    "timestamp": 1650869972109,
    "uri": "http://XXXX.com/XXXX/testy/thread"
}

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

PUT https://{host}/app-id/{app_id}/thread/{thread_id}

Path parameter

ParameterTypeDescriptionRequired
thread_idStringThe 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

ParameterTypeDescriptionRequired
nameStringThe 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:

ParameterTypeDescription
nameStringThe 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

curl -X PUT http://XXXX.com/XXXX/testapp/thread/177916702949377 -H 'Authorization: Bearer ' -d '{"name": "test4"}'

Response example

{
    "action": "put",
    "applicationName": "testapp",
    "duration": 4,
    "data": {
        "name": "test4"
    },
    "organization": "XXXX",
    "timestamp": 1650869972109,
    "uri": "http://XXXX.com/XXXX/testy/thread"
}

Deleting a thread

Deletes the specified thread.

HTTP request

DELETE https://{host}/app-id/{app_id}/thread/{thread_id}

Path parameter

ParameterTypeDescriptionRequired
thread_idStringThe 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:

ParameterTypeDescription
statusStringWhether 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

curl -X DELETE http://XXXX.com/XXXX/testapp/thread/177916702949377 -H 'Authorization: Bearer '

Response example

{
    "action": "delete",
    "applicationName": "testapp",
    "duration": 4,
    "data": {
        "status": "ok"
    },
    "organization": "XXXX",
    "timestamp": 1650869972109,
    "uri": "http://XXXX.com/XXXX/testy/thread"
}

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

GET https://{host}/app-id/{app_id}/thread?limit={limit}&cursor={cursor}&sort={sort}

Path parameter

ParameterTypeDescriptionRequired
limitStringThe maximum number of threads to retrieve per page. The range is [1, 50]. The default value is 50.No
cursorStringThe page from which to start retrieving threads. Pass in null or an empty string at the first query.No
sortStringThe order in which to list the query results: asc: In chronological order of thread creation. (Default) 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:

ParameterTypeDescription
idStringThe ID of the thread.
properties.cursorStringThe 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

curl -X GET http://XXXX.com/XXXX/testapp/thread -H 'Authorization: Bearer '

Response example

{
    "action": "get",
    "applicationName": "testapp",
    "duration": 7,
    "entities": [
        {
            "id": "179786360094768"
        }
    ],
    "organization": "XXXX",
    "properties": {
        "cursor": "ZGNiMjRmNGY1YjczYjlhYTNkYjk1MDY2YmEyNzFmODQ6aW06dGhyZWFkOmVhc2Vtb2ItZGVtbyN0ZXN0eToxNzk3ODYzNjExNDMzMTE"
    },
    "timestamp": 1650869750247,
    "uri": "http://XXXX.com/XXXX/testy/thread"
}

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

GET https://{host}/app-id/{app_id}/threads/user/{username}?limit={limit}&cursor={cursor}&sort={sort}

Path parameter

For the descriptions of the path parameters, see Common Parameters.

Query parameter

ParameterTypeDescriptionRequired
limitStringThe maximum number of threads to retrieve per page. The range is [1, 50]. The default value is 50.No
cursorStringThe page from which to start retrieving threads. Pass in null or an empty string at the first query.No
sortStringThe order in which to list the query results: asc: In chronological order of thread creation. (Default) 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:

ParameterTypeDescription
nameStringThe thread name.
ownerStringThe thread creator.
idStringThe thread ID.
msgIdStringThe ID of the message based on which the thread is created.
groupIdStringThe ID of the group to which the thread belongs.
createdStringThe Unix timestamp when the thread is created.
properties.cursorStringThe 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

curl -X GET http://XXXX.com/XXXX/testapp/threads/user/test4 -H 'Authorization: Bearer '

Response example

{
    "action": "get",
    "applicationName": "testapp",
    "duration": 4,
    "entities": [
        {
            "name": "1",
            "owner": "test4",
            "id": "17XXXX69",
            "msgId": "1920",
            "groupId": "17XXXX61",
            "created": 1650856033420
        }
    ],
    "organization": "XXXX",
    "properties": {
        "cursor": "ZGNiMjRmNGY1YjczYjlhYTNkYjk1MDY2YmEyNzFmODQ6aW06dGhyZWFkOmVhc2Vtb2ItZGVtbyN0ZXN0eToxNzk3ODYzNjAwOTQ3Nzg"
    },
    "timestamp": 1650869972109,
    "uri": "http://XXXX.com/XXXX/testy/threads/user/test4"
}

Retrieving all the threads a user joins under a group

Retrieves all the threads a user joins under a group.

For each App Key, the call frequency limit of this method is 100 per second.

HTTP request

GET https://{host}/app-id/{app_id}/threads/chatgroups/{group_id}/user/{username}?limit={limit}&cursor={cursor}&sort={sort}

Path parameter

ParameterTypeDescriptionRequired
group_idStringThe ID of the group.Yes
usernameStringThe unique login account of the user.Yes

For the descriptions of the other path parameters, see Common Parameters.

Query parameter

ParameterTypeDescriptionRequired
limitStringThe maximum number of threads to retrieve per page. The range is [1, 50]. The default value is 50.No
cursorStringThe page from which to start retrieving threads. Pass in null or an empty string at the first query.No
sortStringThe order in which to list the query results: asc: In chronological order of thread creation. (Default) 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.

For the last page of data, the response still contains cursor and the number of retrieved threads is smaller than the value of limit in the request. If there is no more thread data returned in the response, you have retrieved data of all threads in this group.

ParameterTypeDescription
nameStringThe thread name.
ownerStringThe thread creator.
idStringThe thread ID.
msgIdStringThe ID of the message based on which the thread is created.
groupIdStringThe ID of the group to which the thread belongs.
createdStringThe 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

curl -X GET http://XXXX.com/XXXX/testapp/threads/user/test4 -H 'Authorization: Bearer '

Response example

{
    "action": "get",
    "applicationName": "testapp",
    "duration": 4,
    "entities": [
        {
            "name": "1",
            "owner": "test4",
            "id": "17XXXX69",
            "msgId": "1920",
            "groupId": "17XXXX61",
            "created": 1650856033420
        }
    ],
    "organization": "XXXX",
    "properties": {
        "cursor": "ZGNiMjRmNGY1YjczYjlhYTNkYjk1MDY2YmEyNzFmODQ6aW06dGhyZWFkOmVhc2Vtb2ItZGVtbyN0ZXN0eToxNzk3ODYzNjAwOTQ3Nzg"
    },
    "timestamp": 1650869972109,
    "uri": "http://XXXX.com/XXXX/testy/threads/user/test4"
}

Status codes

For details, see HTTP Status Codes.