In-app Chat
  • iOS : Objective-C
  • Android
  • Web
  • Flutter
  • React Native
  • Unity3D
  • Windows
  • macOS
  • Introduction
    • Overview
    • Basic concepts
  • Sample app
  • Getting started
  • Client SDKs
    • SDK downloads
    • Release notes
    • Upgrade guide
  • Guides
    • Authentication
    • Manage users
    • Room
    • Group
    • Messaging
    • Call invitation (signaling)
    • Manage sessions
  • Offline push notifications
  • Error codes
  • Client APIs
  • Server APIs
  • Documentation
  • In-app Chat
  • Server APIs
  • User related
  • Check friendships

Check friendships

Last updated:2024-04-10 16:29

Overview

You can call this operation to batch check the friendships between a user and up to 20 users. If you need a higher limit (50 at maximum), please contact the ZEGOCLOUD technical support team.

ZEGOCLOUD allows one-way or two-way check of friendships. In this example, the friendship between users A and B is checked.

  • One-way check: Only checks whether user B is in the friend list of user A.
  • Two-way check: Checks whether users A and B are in the friend list of the other.

Below are possible results.

Check Type Value Description
B in the Friend List of A A in the Friend List of B
One-way
1
Uncertain
2
✔️
Uncertain
Two-way
3
4
✔️
5
✔️
6
✔️
✔️

Operation prototype

  • Request method: POST
  • Request URL: https://zim-api.zego.im/?Action=CheckFriendsRelation
  • Protocol: HTTPS
  • QPS limit: 20 calls per second

Request parameters

The following table describes only the operation-specific request parameters and some common request parameters. For the complete list of common request parameters, see the Public request parameters section of the Accessing Server APIs topic.

Parameter Type Required Description
FromUserId
String
Yes
The ID of the registered user whose friendships are to be checked.
UserIds
Array of String
Yes
The list of users to be checked. Up to 20 user IDs can be included.
CheckType
Number
Yes
The check type. Valid values:
  • 0: two-way check.
  • 1: one-way check.

The FromUserId and UserIds parameters can contain only digits, letters, and the following characters: '!', '#', '$', '%', '&', '(', ')', '+', '-', ':', ';', '<', '=', '.', '>', '?', '@', '[', ']', '^', '_', ' ', '{', '}', '|', '~'.

## Sample request
  • Request URL:

    https://zim-api.zego.im/?Action=CheckFriendsRelation
    &<Common request parameters>
  • Request body:

    {
        "FromUserId": "zego_user",
        "UserIds": [
            "user_id1",
            "user_id2",
            "user_id3",
            "user_id4"
        ],
        "CheckType": 0
    }

Response parameters

Parameter Type Description
Code
Number
The return code.
When you request to check the friendships between FromUserId and multiple users, take note of the following items:
  • If one or more friendships are successfully checked, 0 is returned. For more information, see Fails.
  • If all friendships fail to be checked, a corresponding code is returned. For more information, see Return codes.
Message
String
The description of the request result.
RequestId
String
The request ID.
Successes
Array of Object
The list of successful results.
UserId
String
The ID of the user whose friendship with FromUserId is successfully checked.
Relation
Number
The relationship type. For more information, see Overview.
Fails
Array of Object
The list of failed results.

  • If `Code` is `0`:
    • If `Fails` is empty, the friendships between `FromUserId` and all specified users are successfully checked.
    • If `Fails` is not empty, the friendships between `FromUserId` and some specified users fail to be checked. In this case, see `SubCode`.
  • If `Code` is not `0`:
    • If `Fails` is empty, one or more parameters are invalid, the QPS limit is exceeded, or a system error occurs.
    • If `Fails` is not empty, the friendships between `FromUserId` and all specified users fail to be checked.
UserID
String
The ID of the user whose friendship with FromUserId fails to be checked.
SubCode
Number
The code returned when the request fails.
Relation
Number
The relationship type. This parameter is valid only if CheckType is set to 0. Valid values: 1 and 2. For more information, see Overview.

Sample response

{
    "Code": 0,
    "Message": "success",
    "RequestId": "343649807833778782",
    "Succ": [
        {
            "UserId": "user_id1",
            "Relation": 4
        },
        {
            "UserId": "user_id2",
            "Relation": 4
        }
    ],
    "Fails": [
        {
            "UserId": "user_id3",
            "SubCode": 660000001,
            "Relation": 1
        },
        {
            "UserId": "user_id4",
            "SubCode": 660000001,
            "Relation": 2
        }
    ]
}

Return codes

The following table describes only the return codes related to the business logic of the operation. For the complete list of return codes, see Return codes.

Return Code Description Solution
660000001
A common service error occurred.
Please try again, or contact ZEGOCLOUD technical support team.
660000002
Invalid parameter.
Check the input parameter.
660300005
The QPS limit specified in AppID is exceeded.
Please try again later.
Page Directory