Skip to content

Latest commit

 

History

History
267 lines (220 loc) · 5.64 KB

File metadata and controls

267 lines (220 loc) · 5.64 KB

API Reference

USERS • CHATSCONTACTSFILESWEBSOCKETJSON


A collection of methods for managing users. Authentication can differ for each, pay attention to the headers. Request body is a JSON object, but placeholders for data types instead of concrete samples might be used like so: <UUID> or "…" for strings.


1. Registering a user

Registers and logs in a new user. Response will contain DeviceSession.accessToken which you should put to the request header.

Path:

POST /users

Request body:

{
   "name": "…",
   "username": "…",
   "password": "…",
   "deviceInfo": <DeviceInfo>
}

Response: UserInfo object.

See also: DeviceInfo


2. Logging in user

Logs in user from a particular device. Response will contain DeviceSession.accessToken which you should put to the request header.

Path:

POST /users/login

Headers:

Authorization: Basic <username:password>

Request body:

{
   "deviceInfo": <DeviceInfo>
}

Response: UserInfo object.

See also: DeviceInfo, DeviceSession


3. Get current user

Gets all the information of the current user.

Path:

GET /users/me

Headers:

Authorization: Bearer <token>

Response: UserInfo object.


4. Logout user

Logs out user and invalidates DeviceSession.accessToken.

Path:

POST /users/me/logout

Headers:

Authorization: Bearer <token>

Response: OK

See also: DeviceSession


5. Change password

Changes password for the user. Requires both DeviceSession.accessToken and the old password.

Path:

PUT /users/me/changePassword

Headers:

Authorization: Bearer <token>

Request body:

{
   "oldPassword": "…",
   "newPassword": "…"
}

Response: OK


6. Set account key

Sets the account key which is necessary for restoration of the account in case of password loss.

Path:

PUT /users/me/setAccountKey

Headers:

Authorization: Bearer <token>

Request body:

{
   "password": "…",
   "accountKey": "…"
}

Response: OK


7. Reset password

Resets user's password in case of a valid account key provided.

Path:

PUT /users/resetPassword

Request body:

{
   "userId": <Int>,
   "accountKey": "…",
   "newPassword": "…"
}

Response: OK


8. Update user

Updates user's information, such as name and about.

Path:

PUT /users/me

Headers:

Authorization: Bearer <token>

Request body:

{
   "name": "…",
   "about": "…"
}

Response: OK


9. Update device session

Updates user's device session information, such as deviceName and deviceToken.

Path:

PUT /users/me/device

Headers:

Authorization: Bearer <token>

Request body:

{
   "deviceName": "…", // f.e. "My laptop"
   "deviceToken": "…" // Push token (APNS or Android)
}

Response: OK


10. Get user info

Gets all the public information about a user.

Path:

GET /users/<id>

Response: UserInfo object.


11. Search for users

Looks for people by their name or username using substring.

Path:

GET /users/?s=foo

Response: an array of UserInfo objects.


12. Add photo

Adds a photo to the current user. Media should be uploaded beforehand. See Files section.

Path:

POST /users/me/photos

Headers:

Authorization: Bearer <token>

Request body:

{
   "photo": {
      "id": <UUID>,      // should be obtained beforehand by uploading a file
      "fileType": "png",
      "fileSize": 100000 // in bytes
   }
}

Response: OK


13. Delete photo

Deletes the photo from the current user together with all the media.

Path:

DELETE /users/me/photos/<UUID>

Headers:

Authorization: Bearer <token>

Response: OK


14. Deregistering user

Deletes user with all the associated data (created chats, messages, settings etc.). Can't be undone. Use with caution.

Path:

DELETE /users/me

Headers:

Authorization: Basic <username:password>

Response: OK