This page shows how to call Chat RESTful APIs to set the display name, display style, push notification mode, and do-not-disturb (DND) mode.
Before calling the following methods, ensure that you meet the following:
The following table lists common request and response parameters of the Chat RESTful APIs:
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 organization name, see Get the information of the Chat 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 the Chat project. | Yes |
username |
String | The unique login account of the user. | Yes |
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 . |
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. |
path |
String | The request path, which is part of the request URL. You can safely ignore this parameter. |
uri |
String | The request URI. |
entities |
JSON | The response entities. |
data |
JSON | The response details. |
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. The Chat RESTful API only supports authenticating users using app tokens. For details, see Authentication using App Token.
Sets the nickname displayed in push notifications.
For each App Key, the total call frequency limit of this method and the method to set the display style is 100 per second.
PUT https://{host}/{org_name}/{app_name}/users/{username}
For the descriptions of path parameters, see Common Parameters.
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type |
String | The content type. Set it as application/json . |
Yes |
Accept |
String | The parameter type. Set it as application/json . |
Yes |
Authorization |
String | The authentication token of the user or administrator, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. |
Yes |
Parameter | Type | Description | Required |
---|---|---|---|
nickname |
String | The nickname displayed in push notifications. The length of the nickname cannot exceed 100 characters, and the following character sets are supported: The nickname can be different from the nickname in the user profile; however, Agora recommend that you use the same nickname for both. Therefore, if either nickname is updated, the other should be changed at the same time. To update the nickname in the user profile, see Setting user attributes. |
No |
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
uuid |
String | A unique internal identifier generated by the Chat service for the user in this request. |
type |
String | The type of the chat. "user" indicates a one-to-one chat. |
created |
Number | The Unix timestamp (ms) when the user account is registered. |
modified |
Number | The Unix timestamp (ms) when the user information is last modified. |
username |
String | The ID of the user. |
activated |
Bool | Whether the user account is active:true : The user account is active.false : The user account is deactivated. To unban a deactivated user account, refer to Unbanning a user. |
nickname |
String | The nickname displayed in push notifications. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
curl -X PUT -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMte3bGuOukEeiTkNP4grL7iwAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnKdc-ZgBPGgBFTrLhhyK8woMEI005emtrLJFJV6aoxsZSioSIZkr5kw' -d '{ "nickname": "testuser" }' 'http://a1.agora.com/agora-demo/testapp/users/user1'
{
"action": "put",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"path": "/users",
"uri": "https://a1.agora.com/agora-demo/testapp/users",
"entities": [
{
"uuid": "4759aa70-eba5-11e8-925f-6fa0510823ba",
"type": "user",
"created": 1542595573399,
"modified": 1542596083687,
"username": "user1",
"activated": true,
"nickname": "testuser"
} ],
"timestamp": 1542596083685,
"duration": 6,
"organization": "agora-demo",
"applicationName": "testapp"
}
Sets the display style of push notifications.
For each App Key, the total call frequency limit of this method and the method to set the display name is 100 per second.
PUT https://{host}/{org_name}/{app_name}/users/{username}
For the descriptions of path parameters, see Common Parameters.
Parameter | Type | Description | Required |
---|---|---|---|
Authorization |
String | The authentication token of the user or administrator, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. |
Yes |
Parameter | Type | Description | Required |
---|---|---|---|
notification_display_style |
Int | The display style of push notifications:0 : The push title is "You have a new message", and the push content is "Click to check".1 : The push title is "You have a new message", and the push content contains the nickname of the sender and the content of the offline message. |
Yes |
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
uuid |
String | A unique internal identifier generated by the Chat service for the user in this request. |
type |
String | The type of the chat. "user" indicates a one-to-one chat. |
created |
Number | The Unix timestamp (ms) when the user account is registered. |
modified |
Number | The Unix timestamp (ms) when the user information is last modified. |
username |
String | The ID of the user. |
activated |
Bool | Whether the user account is active:true : The user account is active.false : The user account is deactivated. To unban a deactivated user account, refer to Unbanning a user. |
notification_display_style |
String | The display style of push notifications. |
nickname |
String | The nickname displayed in push notifications. |
notifier_name |
String | The name of the push certificate. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
curl -X PUT -H "Authorization: Bearer YWMtSozP9jHNEeSQegV9EKeAQAAAUlmBR2bTGr-GP2xNh8GhUCdKViBFDSEF2E" -i https://a1.agora.com/agora-demo/testapp/users/a -d '{"notification_display_style": "1"}'
{
"action" : "put",
"application" : "17d59e50-0aee-11e8-8092-0dc80c0f5e99",
"path" : "/users",
"uri" : "https://a1.agora.com/agora-demo/testapp/users",
"entities" : [
{
"uuid" : "3b8c9890-7b9a-11e8-9d88-f50bf55cafad",
"type" : "user",
"created" : 1530276298905,
"modified" : 1534407146060,
"username" : "user1",
"activated" : true,
"notification_display_style" : 1,
"nickname" : "testuser",
"notifier_name" : "2882303761517426801"
} ],
"timestamp" : 1534407146058,
"duration" : 3,
"organization" : "1112171214115068",
"applicationName" : "testapp"
}
Sets the push notification and DND modes at both the app and conversation levels.
For each App Key, the call frequency limit of this method is 100 per second.
PUT https://{host}/{org}/{app}/users/{username}/notification/{type}/{key}
Parameter | Type | Description | Required |
---|---|---|---|
type |
String | The type of the chat:user : one-to-one chats.chatgroup : Group chats. |
Yes |
key |
String | The identifier of the chat:type is set to user , key indicates the user ID of the peer user.type is set to chatgroup , key indicates the ID of the chat group. |
Yes |
type
to user
and key
to the user ID of the current user.For the descriptions of other path parameters, see Common Parameters.
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type |
String | The content type. Set it as application/json . |
Yes |
Authorization |
String | The authentication token of the user or administrator, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. |
Yes |
Parameter | Type | Description | Required |
---|---|---|---|
type |
String | The push notification mode:DEFAULT : Inherits the setting at the app level.ALL : Receives push notifications for all offline messages.AT : Only receives push notifications for mentioned messages.NONE : Do not receive push notifications for offline messages. |
No |
ignoreInterval |
String | The DND time frame in the format of {HH:MM-HH:MM}, for example, 08:30-10:00. The range of HH is [00,23] in hours, while the range of MM is [00,59]. This parameter is valid only when type is set to user and key is set to the user ID of the current user in the request header, meaning the DND time frame only takes effect on an app rather than a specific conversation. |
No |
ignoreDuration |
Long | The DND duration in milliseconds. The range is [0,604800000], where 0 indicates that this parameter is invalid and 604800000 indicates that the DND mode lasts for 7 days. |
No |
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
type |
String | The push notification mode. |
ignoreInterval |
String | The DND time frame. |
ignoreDuration |
Long | The DND duration. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
curl -L -X PUT '{url}/{org_name}/{app_name}/users/{username}/notification/user/{key}' \
-H 'Authorization: Bearer {token}' \
-H 'Content-Type: application/json' \
--data-raw '{
"type":"NONE",
"ignoreInterval":"21:30-08:00",
"ignoreDuration":86400000
}'
{
"path": "/users",
"uri": "https://localhost/hx/hxdemo/users/notification/user/hxtest",
"timestamp": 1647503749918,
"organization": "hx",
"application": "17fe201b-ad9b-4a3a-83df-1ed1ebd7b227",
"action": "put",
"data": {
"type": "NONE",
"ignoreDuration": 1647590149924,
"ignoreInterval": "21:30-08:00"
},
"duration": 20,
"applicationName": "hxdemo"
}
Retrieves the push notification and DND modes at both the app and conversation levels.
For each App Key, the call frequency limit of this method is 100 per second.
GET https://{host}/{org}/{app}/users/{username}/notification/{type}/{key}
Parameter | Type | Description | Required |
---|---|---|---|
type |
String | The type of the chat:user : one-to-one chats.chatgroup : Group chats. |
Yes |
key |
String | The identifier of the chat:type is set to user , key indicates the user ID of the peer user.type is set to chatgroup , key indicates the ID of the chat group. |
Yes |
For the descriptions of other path parameters, see Common Parameters.
Parameter | Type | Description | Required |
---|---|---|---|
Authorization |
String | The authentication token of the user or administrator, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. |
Yes |
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
type |
String | The push notification mode. |
ignoreInterval |
String | The DND time frame. |
ignoreDuration |
Long | The DND duration. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
curl -L -X GET '{url}/{org}/{app}/users/{username}/notification/chatgroup/{key}' \
-H 'Authorization: Bearer {token}'
{
"path": "/users",
"uri": "https://localhost/hx/hxdemo/users/notification/chatgroup/12312312321",
"timestamp": 1647503749918,
"organization": "hx",
"application": "17fe201b-ad9b-4a3a-83df-1ed1ebd7b227",
"action": "get",
"data": {
"type": "NONE",
"ignoreDuration": 1647590149924,
"ignoreInterval": "21:30-08:00"
},
"duration": 20,
"applicationName": "hxdemo"
}
Sets the preferred language of push notifications.
For each App Key, the call frequency limit of this method is 100 per second.
PUT https://{host}/{org}/{app}/users/{username}/notification/language
For the descriptions of path parameters, see Common Parameters.
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type |
String | The content type. Set it as application/json . |
Yes |
Authorization |
String | The authentication token of the user or administrator, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. |
Yes |
Parameter | Type | Description | Required |
---|---|---|---|
translationLanguage |
String | The code for the language that the user prefers to see push notifications in. If set to an empty string, the server pushes the notifications of the original language directly. | Yes |
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
language |
String | The code for the language that the user prefers to see push notifications in. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
curl -L -X PUT '{url}/{org}/{app}/users/{username}/notification/language' \
-H 'Authorization: Bearer {token}' \
-H 'Content-Type: application/json' \
--data-raw '{
"translationLanguage":"EU"
}'
{
"path": "/users",
"uri": "https://localhost/hx/hxdemo/users/notification/language",
"timestamp": 1648089630244,
"organization": "hx",
"application": "17fe201b-ad9b-4a3a-83df-1ed1ebd7b227",
"action": "put",
"data": {
"language": "EU"
},
"duration": 66,
"applicationName": "hxdemo"
}
Retrieves the preferred language of push notifications.
For each App Key, the call frequency limit of this method is 100 per second.
GET https://{host}/{org}/{app}/users/{username}/notification/language
For the descriptions of path parameters, see Common Parameters.
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type |
String | The content type. Set it as application/json . |
Yes |
Authorization |
String | The authentication token of the user or administrator, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. |
Yes |
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
language |
String | The code for the language that the user prefers to see push notifications in. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
curl -L -X GET '{url}/{org}/{app}/users/{username}/notification/language' \
-H 'Authorization: Bearer {token}'
{
"path": "/users",
"uri": "https://localhost/hx/hxdemo/users/notification/language",
"timestamp": 1648089630244,
"organization": "hx",
"application": "17fe201b-ad9b-4a3a-83df-1ed1ebd7b227",
"action": "put",
"data": {
"language": "EU"
},
"duration": 66,
"applicationName": "hxdemo"
}
Creates a template for push notifications.
For each App Key, the call frequency limit of this method is 100 per second.
POST https://{host}/{org}/{app}/notification/template`
For the descriptions of path parameters, see Common Parameters.
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type |
String | The content type. Set it as application/json . |
Yes |
Authorization |
String | The authentication token of the user or administrator, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. |
Yes |
Parameter | Type | Description | Required |
---|---|---|---|
name |
String | The name of the push template. | Yes |
title_pattern |
String | The custom title of the push template. You can add variables in the title, such as {0}. | Yes |
content_pattern |
String | The custom content of the push template. You can add variables in the content, such as {0} and {1}. | Yes |
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
name |
String | The name of the push template. |
createAt |
Number | The Unix timestamp (ms) when the template is created. |
updateAt |
Number | The Unix timestamp (ms) when the template is last modified. |
title_pattern |
String | The custom title of the push template. |
content_pattern |
String | The custom content of the push template. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
curl -X POST '{url}/{org}/{app}/notification/template' \
-H 'Authorization: Bearer {token}' \
-H 'Content-Type: application/json' \
--data-raw '{
"name": "test7",
"title_pattern": "Hello,{0}",
"content_pattern": "Test,{0}"
}'
{
"uri": "https://localhost/hx/hxdemo/notification/template",
"timestamp": 1646989584108,
"organization": "hx",
"application": "17fe201b-ad9b-4a3a-83df-1ed1ebd7b227",
"action": "post",
"data": {
"name": "test7",
"createAt": 1646989584124,
"updateAt": 1646989584124,
"title_pattern": "Hello,{0}",
"content_pattern": "Test,{0}"
},
"duration": 26,
"applicationName": "hxdemo"
}
Retrieves the specified template for push notifications.
For each App Key, the call frequency limit of this method is 100 per second.
GET https://{host}/{org}/{app}/notification/template/{name}
Parameter | Type | Description | Required |
---|---|---|---|
name |
String | The name of the push template. | Yes |
For the descriptions of other path parameters, see Common Parameters.
Parameter | Type | Description | Required |
---|---|---|---|
Authorization |
String | The authentication token of the user or administrator, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. |
Yes |
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
name |
String | The name of the push template. |
createAt |
Number | The Unix timestamp (ms) when the template is created. |
updateAt |
Number | The Unix timestamp (ms) when the template is last modified. |
title_pattern |
String | The custom title of the push template. |
content_pattern |
String | The custom content of the push template. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
curl -X GET '{url}/{org}/{app}/notification/template/{name}' \
-H 'Authorization: Bearer {token}'
{
"uri": "https://localhost/hx/hxdemo/notification/template/test7",
"timestamp": 1646989686393,
"organization": "hx",
"application": "17fe201b-ad9b-4a3a-83df-1ed1ebd7b227",
"action": "get",
"data": {
"name": "test7",
"createAt": 1646989584124,
"updateAt": 1646989584124,
"title_pattern": "Hello,{0}",
"content_pattern": "Test,{0}"
},
"duration": 11,
"applicationName": "hxdemo"
}
Deletes the specified template for push notifications.
For each App Key, the call frequency limit of this method is 100 per second.
DELETE https://{host}/{org}/{app}/notification/template/{name}
Parameter | Type | Description | Required |
---|---|---|---|
name |
String | The name of the push template. | Yes |
For the descriptions of other path parameters, see Common Parameters.
Parameter | Type | Description | Required |
---|---|---|---|
Authorization |
String | The authentication token of the user or administrator, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. |
Yes |
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
name |
String | The name of the push template. |
createAt |
Number | The Unix timestamp (ms) when the template is created. |
updateAt |
Number | The Unix timestamp (ms) when the template is last modified. |
title_pattern |
String | The custom title of the push template. |
content_pattern |
String | The custom content of the push template. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
curl -X DELETE '{url}/{org}/{app}/notification/template' \
-H 'Authorization: Bearer {token}'
{
"uri": "https://localhost/hx/hxdemo/notification/template",
"timestamp": 1646989686393,
"organization": "hx",
"application": "17fe201b-ad9b-4a3a-83df-1ed1ebd7b227",
"action": "delete",
"data": {
"name": "test7",
"createAt": 1646989584124,
"updateAt": 1646989584124,
"title_pattern": "Hello,{0}",
"content_pattern": "Test,{0}"
},
"duration": 11,
"applicationName": "hxdemo"
}
For details, see HTTP Status Codes.