Skip to main content

Offline push

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:

  • You understand the call frequency limit of the Chat RESTful APIs as described in Limitations.

  • You have activated the advanced features for push in Agora Console. Advanced features allow you to set the push notification mode, do-not-disturb mode, and custom push template.

You must contact support@agora.io to disable the advanced features for push as this operation will delete all the relevant configurations.

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 the Chat 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 the Chat project.Yes
usernameStringThe unique login account of the user.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.
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.
pathStringThe request path, which is part of the request URL. You can safely ignore this parameter.
uriStringThe request URI.
entities JSONThe response entity.
dataJSONThe response details.

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.

Set the display name in push notifications

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.

HTTP request


_1
PUT https://{host}/{org_name}/{app_name}/users/{username}

Path parameter

For the descriptions of path parameters, see Common Parameters.

Request header

ParameterTypeDescriptionRequired
Content-TypeStringThe content type. Set it as application/json.Yes
AcceptStringThe parameter type. Set it as application/json.Yes
AuthorizationStringThe 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

Request body

ParameterTypeDescriptionRequired
nicknameStringThe nickname displayed in push notifications. The length of the nickname cannot exceed 100 characters, and the following character sets are supported:
  • 26 lowercase English letters (a-z)
  • 26 uppercase English letters (A-Z)
  • 10 numbers (0-9)
  • Chinese characters
  • Special characters
  • The nickname can be different from the nickname in the user profile; however, Agora recommends 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

    HTTP response

    Response body

    If the returned HTTP status code is 200, the request succeeds, and the response body contains the following fields:

    ParameterTypeDescription
    uuidStringA unique internal identifier generated by the Chat service for the user in this request.
    typeStringThe type of the chat. "user" indicates a One-to-one chat.
    createdNumberThe Unix timestamp (ms) when the user account is registered.
    modifiedNumberThe Unix timestamp (ms) when the user information is last modified.
    usernameStringThe ID of the user.
    activatedBoolWhether 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.
  • nicknameStringThe 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.

    Example

    Request example


    _1
    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'

    Response example


    _20
    {
    _20
    "action": "put",
    _20
    "application": "8be024f0-e978-11e8-b697-5d598d5f8402",
    _20
    "path": "/users",
    _20
    "uri": "https://a1.agora.com/agora-demo/testapp/users",
    _20
    "entities": [
    _20
    {
    _20
    "uuid": "4759aa70-eba5-11e8-925f-6fa0510823ba",
    _20
    "type": "user",
    _20
    "created": 1542595573399,
    _20
    "modified": 1542596083687,
    _20
    "username": "user1",
    _20
    "activated": true,
    _20
    "nickname": "testuser"
    _20
    } ],
    _20
    "timestamp": 1542596083685,
    _20
    "duration": 6,
    _20
    "organization": "agora-demo",
    _20
    "applicationName": "testapp"
    _20
    }

    Set the display style in push notifications

    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.

    HTTP request


    _1
    PUT https://{host}/{org_name}/{app_name}/users/{username}

    Path parameter

    For the descriptions of path parameters, see Common Parameters.

    Request header

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

    Request body

    ParameterTypeDescriptionRequired
    notification_display_styleIntThe display style of push notifications:
  • (Default) 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

    HTTP response

    Response body

    If the returned HTTP status code is 200, the request succeeds, and the response body contains the following fields:

    ParameterTypeDescription
    uuidStringA unique internal identifier generated by the Chat service for the user in this request.
    typeStringThe type of the chat. "user" indicates a One-to-one chat.
    createdNumberThe Unix timestamp (ms) when the user account is registered.
    modifiedNumberThe Unix timestamp (ms) when the user information is last modified.
    usernameStringThe ID of the user.
    activatedBoolWhether 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_styleIntThe display style of push notifications. This parameter is returned only if you specify it when sending the request.
    nicknameStringThe nickname displayed in push notifications.
    notifier_nameStringThe 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.

    Example

    Request example


    _1
    curl -X PUT -H "Authorization: Bearer YWMtSozP9jHNEeSQegV9EKeAQAAAUlmBR2bTGr-GP2xNh8GhUCdKViBFDSEF2E" -i https://a1.agora.com/agora-demo/testapp/users/a -d '{"notification_display_style": "1"}'

    Response example


    _22
    {
    _22
    "action" : "put",
    _22
    "application" : "17d59e50-0aee-11e8-8092-0dc80c0f5e99",
    _22
    "path" : "/users",
    _22
    "uri" : "https://a1.agora.com/agora-demo/testapp/users",
    _22
    "entities" : [
    _22
    {
    _22
    "uuid" : "3b8c9890-7b9a-11e8-9d88-f50bf55cafad",
    _22
    "type" : "user",
    _22
    "created" : 1530276298905,
    _22
    "modified" : 1534407146060,
    _22
    "username" : "user1",
    _22
    "activated" : true,
    _22
    "notification_display_style" : 1,
    _22
    "nickname" : "testuser",
    _22
    "notifier_name" : "2882303761517426801"
    _22
    } ],
    _22
    "timestamp" : 1534407146058,
    _22
    "duration" : 3,
    _22
    "organization" : "1112171214115068",
    _22
    "applicationName" : "testapp"
    _22
    }

    Set up push notifications

    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.

    HTTP request


    _1
    PUT https://{host}/{org}/{app}/users/{username}/notification/{chattype}/{key}

    Path parameter

    ParameterTypeDescriptionRequired
    chattypeStringThe type of the chat:
  • user: One-to-one chats.
  • chatgroup: Group chats.
  • Yes
    keyStringThe identifier of the chat:
  • If type is set to user, key indicates the user ID of the peer user.
  • If type is set to chatgroup, key indicates the ID of the chat group.
  • Yes

    To set up push notifications at the app level, you can set type to user and key to the user ID of the current user.
    For the descriptions of other path parameters, see Common Parameters.

    Request header

    ParameterTypeDescriptionRequired
    Content-TypeStringThe content type. Set it as application/json.Yes
    AuthorizationStringThe 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

    Request body

    ParameterTypeDescriptionRequired
    typeStringThe 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
    ignoreIntervalStringThe 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 in the requested URL 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
    ignoreDurationLongThe 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

    HTTP response

    Response body

    If the returned HTTP status code is 200, the request succeeds, and the response body contains the following fields:

    ParameterTypeDescription
    typeStringThe push notification mode.
    ignoreIntervalStringThe DND time frame.
    ignoreDurationLongThe 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.

    Example

    Request example


    _8
    curl -L -X PUT '{url}/{org_name}/{app_name}/users/{username}/notification/user/{key}' \
    _8
    -H 'Authorization: Bearer {token}' \
    _8
    -H 'Content-Type: application/json' \
    _8
    --data-raw '{
    _8
    "type":"NONE",
    _8
    "ignoreInterval":"21:30-08:00",
    _8
    "ignoreDuration":86400000
    _8
    }'

    Response example


    _15
    {
    _15
    "path": "/users",
    _15
    "uri": "https://localhost/hx/hxdemo/users/notification/user/hxtest",
    _15
    "timestamp": 1647503749918,
    _15
    "organization": "hx",
    _15
    "application": "17fe201b-ad9b-4a3a-83df-1ed1ebd7b227",
    _15
    "action": "put",
    _15
    "data": {
    _15
    "type": "NONE",
    _15
    "ignoreDuration": 1647590149924,
    _15
    "ignoreInterval": "21:30-08:00"
    _15
    },
    _15
    "duration": 20,
    _15
    "applicationName": "hxdemo"
    _15
    }

    Retrieve the settings of push notifications

    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.

    HTTP request


    _1
    GET https://{host}/{org}/{app}/users/{username}/notification/{chattype}/{key}

    Path parameter

    ParameterTypeDescriptionRequired
    chattypeStringThe type of the chat:
  • user: One-to-one chats.
  • chatgroup: Group chats.
  • Yes
    keyStringThe identifier of the chat:
  • If type is set to user, key indicates the user ID of the peer user.
  • If type is set to chatgroup, key indicates the ID of the chat group.
  • Yes

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

    Request header

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

    HTTP response

    Response body

    If the returned HTTP status code is 200, the request succeeds, and the response body contains the following fields:

    ParameterTypeDescription
    typeStringThe push notification mode.
    ignoreIntervalStringThe DND time frame.
    ignoreDurationLongThe 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.

    Example

    Request example


    _2
    curl -L -X GET '{url}/{org}/{app}/users/{username}/notification/chatgroup/{key}' \
    _2
    -H 'Authorization: Bearer {token}'

    Response example


    _15
    {
    _15
    "path": "/users",
    _15
    "uri": "https://localhost/hx/hxdemo/users/notification/chatgroup/12312312321",
    _15
    "timestamp": 1647503749918,
    _15
    "organization": "hx",
    _15
    "application": "17fe201b-ad9b-4a3a-83df-1ed1ebd7b227",
    _15
    "action": "get",
    _15
    "data": {
    _15
    "type": "NONE",
    _15
    "ignoreDuration": 1647590149924,
    _15
    "ignoreInterval": "21:30-08:00"
    _15
    },
    _15
    "duration": 20,
    _15
    "applicationName": "hxdemo"
    _15
    }

    Set the preferred language of push notifications

    Sets the preferred language of push notifications.

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

    HTTP request


    _1
    PUT https://{host}/{org}/{app}/users/{username}/notification/language

    Path parameter

    For the descriptions of path parameters, see Common Parameters.

    Request header

    ParameterTypeDescriptionRequired
    Content-TypeStringThe content type. Set it as application/json.Yes
    AuthorizationStringThe 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

    Request body

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

    HTTP response

    Response body

    If the returned HTTP status code is 200, the request succeeds, and the response body contains the following fields:

    ParameterTypeDescription
    languageStringThe 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.

    Example

    Request example


    _6
    curl -L -X PUT '{url}/{org}/{app}/users/{username}/notification/language' \
    _6
    -H 'Authorization: Bearer {token}' \
    _6
    -H 'Content-Type: application/json' \
    _6
    --data-raw '{
    _6
    "translationLanguage":"EU"
    _6
    }'

    Response example


    _13
    {
    _13
    "path": "/users",
    _13
    "uri": "https://localhost/hx/hxdemo/users/notification/language",
    _13
    "timestamp": 1648089630244,
    _13
    "organization": "hx",
    _13
    "application": "17fe201b-ad9b-4a3a-83df-1ed1ebd7b227",
    _13
    "action": "put",
    _13
    "data": {
    _13
    "language": "EU"
    _13
    },
    _13
    "duration": 66,
    _13
    "applicationName": "hxdemo"
    _13
    }

    Retrieve the preferred language of push notifications

    Retrieves the preferred language of push notifications.

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

    HTTP request


    _1
    GET https://{host}/{org}/{app}/users/{username}/notification/language

    Path parameter

    For the descriptions of path parameters, see Common Parameters.

    Request header

    ParameterTypeDescriptionRequired
    Content-TypeStringThe content type. Set it as application/json.Yes
    AuthorizationStringThe 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

    HTTP response

    Response body

    If the returned HTTP status code is 200, the request succeeds, and the response body contains the following fields:

    ParameterTypeDescription
    languageStringThe 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.

    Example

    Request example


    _2
    curl -L -X GET '{url}/{org}/{app}/users/{username}/notification/language' \
    _2
    -H 'Authorization: Bearer {token}'

    Response example


    _13
    {
    _13
    "path": "/users",
    _13
    "uri": "https://localhost/hx/hxdemo/users/notification/language",
    _13
    "timestamp": 1648089630244,
    _13
    "organization": "hx",
    _13
    "application": "17fe201b-ad9b-4a3a-83df-1ed1ebd7b227",
    _13
    "action": "put",
    _13
    "data": {
    _13
    "language": "EU"
    _13
    },
    _13
    "duration": 66,
    _13
    "applicationName": "hxdemo"
    _13
    }

    Create a push template

    Creates a template for push notifications.

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

    HTTP request


    _1
    POST https://{host}/{org}/{app}/notification/template`

    Path parameter

    For the descriptions of path parameters, see Common Parameters.

    Request header

    ParameterTypeDescriptionRequired
    Content-TypeStringThe content type. Set it as application/json.Yes
    AuthorizationStringThe 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

    Request body

    ParameterTypeDescriptionRequired
    nameStringThe name of the push template.Yes
    title_patternStringThe custom title of the push template. You can add variables in the title, such as 0.Yes
    content_patternStringThe custom content of the push template. You can add variables in the content, such as 0 and 1.Yes

    HTTP response

    Response body

    If the returned HTTP status code is 200, the request succeeds, and the response body contains the following fields:

    ParameterTypeDescription
    nameStringThe name of the push template.
    createAtNumberThe Unix timestamp (ms) when the template is created.
    updateAtNumberThe Unix timestamp (ms) when the template is last modified.
    title_patternStringThe custom title of the push template.
    content_patternStringThe 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.

    Example

    Request example


    _8
    curl -X POST '{url}/{org}/{app}/notification/template' \
    _8
    -H 'Authorization: Bearer {token}' \
    _8
    -H 'Content-Type: application/json' \
    _8
    --data-raw '{
    _8
    "name": "test7",
    _8
    "title_pattern": "Hello,{0}",
    _8
    "content_pattern": "Test,{0}"
    _8
    }'

    Response example


    _16
    {
    _16
    "uri": "https://localhost/hx/hxdemo/notification/template",
    _16
    "timestamp": 1646989584108,
    _16
    "organization": "hx",
    _16
    "application": "17fe201b-ad9b-4a3a-83df-1ed1ebd7b227",
    _16
    "action": "post",
    _16
    "data": {
    _16
    "name": "test7",
    _16
    "createAt": 1646989584124,
    _16
    "updateAt": 1646989584124,
    _16
    "title_pattern": "Hello,{0}",
    _16
    "content_pattern": "Test,{0}"
    _16
    },
    _16
    "duration": 26,
    _16
    "applicationName": "hxdemo"
    _16
    }

    Retrieve a push template

    Retrieves the specified template for push notifications.

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

    HTTP request


    _1
    GET https://{host}/{org}/{app}/notification/template/{name}

    Path parameter

    ParameterTypeDescriptionRequired
    nameStringThe name of the push template.Yes

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

    Request header

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

    HTTP response

    Response body

    If the returned HTTP status code is 200, the request succeeds, and the response body contains the following fields:

    ParameterTypeDescription
    nameStringThe name of the push template.
    createAtNumberThe Unix timestamp (ms) when the template is created.
    updateAtNumberThe Unix timestamp (ms) when the template is last modified.
    title_patternStringThe custom title of the push template.
    content_patternStringThe 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.

    Example

    Request example


    _2
    curl -X GET '{url}/{org}/{app}/notification/template/{name}' \
    _2
    -H 'Authorization: Bearer {token}'

    Response example


    _16
    {
    _16
    "uri": "https://localhost/hx/hxdemo/notification/template/test7",
    _16
    "timestamp": 1646989686393,
    _16
    "organization": "hx",
    _16
    "application": "17fe201b-ad9b-4a3a-83df-1ed1ebd7b227",
    _16
    "action": "get",
    _16
    "data": {
    _16
    "name": "test7",
    _16
    "createAt": 1646989584124,
    _16
    "updateAt": 1646989584124,
    _16
    "title_pattern": "Hello,{0}",
    _16
    "content_pattern": "Test,{0}"
    _16
    },
    _16
    "duration": 11,
    _16
    "applicationName": "hxdemo"
    _16
    }

    Delete a push template

    Deletes the specified template for push notifications.

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

    HTTP request


    _1
    DELETE https://{host}/{org}/{app}/notification/template/{name}

    Path parameter

    ParameterTypeDescriptionRequired
    nameStringThe name of the push template.Yes

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

    Request header

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

    HTTP response

    Response body

    If the returned HTTP status code is 200, the request succeeds, and the response body contains the following fields:

    ParameterTypeDescription
    nameStringThe name of the push template.
    createAtNumberThe Unix timestamp (ms) when the template is created.
    updateAtNumberThe Unix timestamp (ms) when the template is last modified.
    title_patternStringThe custom title of the push template.
    content_patternStringThe 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.

    Example

    Request example


    _2
    curl -X DELETE '{url}/{org}/{app}/notification/template' \
    _2
    -H 'Authorization: Bearer {token}'

    Response example


    _16
    {
    _16
    "uri": "https://localhost/hx/hxdemo/notification/template",
    _16
    "timestamp": 1646989686393,
    _16
    "organization": "hx",
    _16
    "application": "17fe201b-ad9b-4a3a-83df-1ed1ebd7b227",
    _16
    "action": "delete",
    _16
    "data": {
    _16
    "name": "test7",
    _16
    "createAt": 1646989584124,
    _16
    "updateAt": 1646989584124,
    _16
    "title_pattern": "Hello,{0}",
    _16
    "content_pattern": "Test,{0}"
    _16
    },
    _16
    "duration": 11,
    _16
    "applicationName": "hxdemo"
    _16
    }

    Status codes

    For details, see HTTP Status Codes.