Skip to main content

You are viewing Agora Docs forBetaproducts and features. Switch to Docs

Android
iOS
Web
Windows
Unity
Flutter
React Native

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

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
org_nameStringThe 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_nameStringThe 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

ParameterTypeDescription
actionStringThe request method.
organizationStringThe unique identifier assigned to each company (organization) by the Chat service. This is the same as org_name.
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. This is the same as app_name.
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:


_1
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


_1
POST https://{host}/{org_name}/{app_name}/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


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

Response example


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

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


_1
PUT https://{host}/{org_name}/{app_name}/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


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

Response example


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

Deleting a thread

Deletes the specified thread.

HTTP request


_1
DELETE https://{host}/{org_name}/{app_name}/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


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

Response example


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

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


_1
GET https://{host}/{org_name}/{app_name}/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


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

    Response example


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

    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


    _1
    GET https://{host}/{org_name}/{app_name}/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 chat 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


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

    Response example


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

    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


    _1
    GET https://{host}/{org_name}/{app_name}/threads/chatgroups/{group_id}/user/{username}?limit={limit}&cursor={cursor}&sort={sort}

    Path parameter

    ParameterTypeDescriptionRequired
    group_idStringThe ID of the chat 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 chat 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


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

    Response example


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

    Status codes

    For details, see HTTP Status Codes.

    vundefined