Skip to main content

Contact management

Contact management refers to operations such as adding and removing contacts, and adding and removing users from the block list.

This page shows how to call the Chat RESTful APIs to create and manage contacts.

Before calling the following methods, make sure you understand the call frequency limit as 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 Chat 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. The user ID must be 64 characters or less and cannot be empty. The following character sets are supported:
  • 26 lowercase English letters (a-z)
  • 26 uppercase English letters (A-Z)
  • 10 numbers (0-9)
  • "_", "-", "."
  • The username is case insensitive, so Aa and aa are the same username.
  • Ensure that each username under the same app is unique.
  • Do not set this parameter as a UUID, email address, phone number, or other sensitive information.
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.
uriStringThe request URI.
pathStringThe request path, which is part of the request URL. You can safely ignore this parameter.
entities JSONThe response entity.
entities.uuidStringThe user's UUID. A unique internal identifier generated by the Chat service for the user in this request. This is used for generating the user token.
entities.typeStringThe type of the object. You can safely ignore this parameter.
entities.createdNumberThe Unix timestamp (ms) when the user is registered.
entities.modifiedNumberThe Unix timestamp (ms) when the user information is last modified.
entities.usernameStringThe username. The unique account the user is logged in with.
entities.activatedBoolWhether the user is active:
  • true: The user is active.
  • false: The user is in banned.
  • 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.

    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.

    Adding a contact

    This method adds a user under the same App Key as contacts. The number of contacts supported differs by plan version; the maximum number of contacts supported by the free version is 100. For details, see Limitations.

    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}/users/{owner_username}/contacts/users/{friend_username}

    Path parameter

    ParameterTypeDescriptionRequired
    owner_usernameStringThe username of the local user.Yes
    friend_usernameStringThe username to be added as a contact.Yes

    For other parameters and detailed descriptions, see Common parameters.

    Request header

    ParameterTypeDescriptionRequired
    Content-TypeStringThe parameter type. Set it as application/json.Yes
    AcceptStringThe parameter type. Set it as application/json.Yes
    AuthorizationStringThe authentication token of the user or admin, 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. For the fields and descriptions of the response body, see Common parameter.

    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 POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/XXXX/XXXX/users/user1/contacts/users/user2'

    Response example


    _20
    {
    _20
    "path": "/users/4759aa70-XXXX-XXXX-925f-6fa0510823ba/contacts",
    _20
    "uri": "https://XXXX/XXXX/XXXX/users/4759aa70-eba5-11e8-925f-6fa0510823ba/contacts",
    _20
    "timestamp": 1542598913819,
    _20
    "organization": "XXXX",
    _20
    "application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
    _20
    "entities": [
    _20
    {
    _20
    "uuid": "b2aade90-XXXX-XXXX-a974-f3368f82e4f1",
    _20
    "type": "user",
    _20
    "created": 1542356523769,
    _20
    "modified": 1542597334500,
    _20
    "username": "user2",
    _20
    "activated": true,
    _20
    }
    _20
    ],
    _20
    "action": "post",
    _20
    "duration": 63,
    _20
    "applicationName": "XXXX"
    _20
    }

    Removing a contact

    This method removes the user from the contact list.

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

    HTTP request


    _1
    DELETE https://{host}/{org_name}/{app_name}/users/{owner_username}/contacts/users/{friend_username}

    Path parameter

    ParameterTypeDescriptionRequired
    owner_usernameStringThe username of the local user.Yes
    friend_usernameStringThe username to be removed from the contact list.Yes

    For other parameters and detailed descriptions, see Common parameters.

    Request header

    ParameterTypeDescriptionRequired
    AcceptStringThe parameter type. Set it as application/json.Yes
    AuthorizationStringThe authentication token of the user or admin, 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. For the fields and descriptions of the response body, see Common parameter.

    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 -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/XXXX/XXXX/users/user1/contacts/users/user2'

    Response example


    _20
    {
    _20
    "path": "/users/4759aa70-XXXX-XXXX-925f-6fa0510823ba/contacts",
    _20
    "uri": "https://XXXX/XXXX/XXXX/users/4759aa70-eba5-11e8-925f-6fa0510823ba/contacts",
    _20
    "timestamp": 1542599266616,
    _20
    "organization": "XXXX",
    _20
    "application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
    _20
    "entities": [
    _20
    {
    _20
    "uuid": "b2aade90-XXXX-XXXX-a974-f3368f82e4f1",
    _20
    "type": "user",
    _20
    "created": 1542356523769,
    _20
    "modified": 1542597334500,
    _20
    "username": "user2",
    _20
    "activated": true,
    _20
    }
    _20
    ],
    _20
    "action": "delete",
    _20
    "duration": 350,
    _20
    "applicationName": "XXXX"
    _20
    }

    Retrieving the contact list

    This method retrieves the local user's contact list.

    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}/users/{owner_username}/contacts/users

    Path parameter

    ParameterTypeDescriptionRequired
    owner_usernameStringThe username of the local user.Yes

    For other fields and descriptions, see Common parameter.

    Request header

    ParameterTypeDescriptionRequired
    AcceptStringThe parameter type. Set it as application/json.Yes
    AuthorizationStringThe authentication token of the user or admin, 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
    dataArrayThe contact list data.
    countNumberThe number of contacts.

    For other fields and descriptions, see Common parameter.

    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 -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/XXXX/XXXX/users/user1/contacts/users'

    Response example


    _12
    {
    _12
    "uri": "http://XXXX/XXXX/XXXX/users/user1/contacts/users",
    _12
    "timestamp": 1543819826513,
    _12
    "entities": [],
    _12
    "count": 2
    _12
    "action": "get",
    _12
    "data": [
    _12
    "user3",
    _12
    "user2"
    _12
    ],
    _12
    "duration": 12
    _12
    }

    Adding users to the block list

    Adds the specified user or users to the block list. Once you add a user to the block list, you can no longer receive messages from that user. The maximum number of users in the block list for each user is 500.

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

    HTTP request


    _1
    POST https://{host}/{org_name}/{app_name}/users/{owner_username}/blocks/users

    Path parameter

    For the descriptions of the path parameters of this method, see Common parameter.

    Request header

    ParameterTypeDescriptionRequired
    Content-TypeStringThe parameter type. Set it as application/json.Yes
    AcceptStringThe parameter type. Set it as application/json.Yes
    AuthorizationStringThe authentication token of the user or admin, 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

    The request body is a JSON object, which contains the following fields:

    FieldTypeDescriptionRequired
    usernamesAn array of usernamesThe usernames to be added to the block list, such as ["user1", "user2"].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
    dataArrayAn array of usernames to add to the block list.

    For other fields and descriptions, see Common parameter.

    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 POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' -d '{ "usernames": [ "user2" ] }' 'http://XXXX/XXXX/XXXX/users/user1/blocks/users'

    Response example


    _13
    {
    _13
    "uri": "https://XXXX/XXXX/XXXX",
    _13
    "timestamp": 1542600372046,
    _13
    "organization": "XXXX",
    _13
    "application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
    _13
    "entities": [],
    _13
    "action": "post",
    _13
    "data": [
    _13
    "user2"
    _13
    ],
    _13
    "duration": 110,
    _13
    "applicationName": "XXXX"
    _13
    }

    Retrieving the block list

    This method retrieves the current user's block list.

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

    HTTP request


    _1
    GET https://{host}/{org_name}/{app_name}/users/{owner_username}/blocks/users

    Path parameter

    ParameterTypeDescriptionRequired
    owner_usernameStringThe username of the local user.Yes

    For other parameters and detailed descriptions, see Common parameters.

    Request header

    ParameterTypeDescriptionRequired
    AcceptStringThe parameter type. Set it as application/json.Yes
    AuthorizationStringThe authentication token of the user or admin, 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
    dataArrayAn array of usernames in the block list.

    For other fields and descriptions, see Common parameter.

    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 -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/XXXX/XXXX/users/user1/blocks/users'

    Response example


    _11
    {
    _11
    "uri": "http://XXXX/XXXX/XXXX/users/user1/blocks/users",
    _11
    "timestamp": 1542599978751,
    _11
    "entities": [],
    _11
    "count": 1,
    _11
    "action": "get",
    _11
    "data": [
    _11
    "user2"
    _11
    ],
    _11
    "duration": 4
    _11
    }

    Removing a user from the block list

    This method removes the specified user from the block list. After removing a user from the block list, that user resumes their previous relationship with the local user, as a contact or a regular chat user, and can send and receive messages with the local user.

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

    HTTP request


    _1
    DELETE https://{host}/{org_name}/{app_name}/users/{owner_username}/blocks/users/{blocked_username}

    Path parameter

    ParameterTypeDescriptionRequired
    owner_usernameStringThe username of the local user.Yes
    blocked_usernameStringThe username to be removed from the block list.Yes

    For other parameters and detailed descriptions, see Common parameters.

    Request header

    ParameterTypeDescriptionRequired
    AcceptStringThe parameter type. Set it as application/json.Yes
    AuthorizationStringThe authentication token of the user or admin, 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 is successful. For fields and descriptions of the response body, see Common parameter.

    If the returned HTTP status code is not 200, the request fails. You can refer to Status codes(#code) for possible causes.

    Example

    Request example


    _1
    curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/XXXX/XXXX/users/user1/blocks/users/user2'

    Response example


    _20
    {
    _20
    "path": "/users/4759aa70-XXXX-XXXX-925f-6fa0510823ba/blocks",
    _20
    "uri": "https://XXXX/XXXX/XXXX/users/4759aa70-eba5-11e8-925f-6fa0510823ba/blocks",
    _20
    "timestamp": 1542600712985,
    _20
    "organization": "XXXX",
    _20
    "application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
    _20
    "entities": [
    _20
    {
    _20
    "uuid": "b2aade90-XXXX-XXXX-a974-f3368f82e4f1",
    _20
    "type": "user",
    _20
    "created": 1542356523769,
    _20
    "modified": 1542597334500,
    _20
    "username": "user2",
    _20
    "activated": true,
    _20
    }
    _20
    ],
    _20
    "action": "delete",
    _20
    "duration": 20,
    _20
    "applicationName": "XXXX"
    _20
    }

    Status codes

    For details, see HTTP Status Codes.

    Page Content