Browse Platform API
Platform API

Import friends

Copy

Use Import friends to establish friend relationships in bulk during migration or backend initialization.

HTTP request

POST {API_ADDRESS}/friend/import_friend

Request example

curl --request POST "${API_ADDRESS}/friend/import_friend" \
  --header "Content-Type: application/json; charset=utf-8" \
  --header "operationID: ${OPERATION_ID}" \
  --header "token: ${ADMIN_TOKEN}" \
  --data-raw '{
  "ownerUserID": "user_001",
  "friendUserIDs": [
    "user_002",
    "user_003"
  ]
}'
Keep administrator tokens on trusted backend services only. Client applications should use user tokens issued by your backend.

Request body

{
  "ownerUserID": "user_001",
  "friendUserIDs": [
    "user_002",
    "user_003"
  ]
}
ParameterRequiredTypeDescription
ownerUserIDYesstringUser who will own the imported friend relationships.
friendUserIDsYesarrayUser IDs to import as friends. Keep the count below the server request limit.

Response

OpenIM usually returns 200 OK when the request reaches the service. Use errCode in the JSON response to determine business success; errCode === 0 means the operation succeeded.

{
  "errCode": 0,
  "errMsg": "",
  "errDlt": "",
  "data": {}
}

Response fields

FieldTypeDescription
errCodeintBusiness error code. 0 means success.
errMsgstringShort error message.
errDltstringDetailed error information for troubleshooting.
dataobjectEndpoint-specific response data.
dataobjectEndpoint-specific response data.

Error response

When a request fails, OpenIM returns the same error envelope. See Error codes for the full handling model.

{
  "errCode": 1004,
  "errMsg": "RecordNotFoundError",
  "errDlt": ": [1004]RecordNotFoundError"
}
ScenarioPossible causeRecommended action
Authentication failedtoken is missing, expired, or not an administrator token.Issue a new administrator token and keep it on the backend.
Traceability is weakoperationID is missing or reused across many requests.Generate a unique operationID for every request and log it with the response.
Validation failedThe request body has an invalid type, missing field, or unsupported enum value.Compare the payload with the request table and retry after correcting the fields.

Permissions and limits

  • Call this endpoint from a trusted backend service.
  • Log operationID, the endpoint path, and the response error fields for troubleshooting.
  • Treat write operations as state-changing. If a retry follows an uncertain failure, check the resource state first.