Mesibo Backend APIs - User Management

Estimated reading time: 6 minutes

Before your users can use mesibo services, mesibo need to know about your users so that mesibo can enable real-time messaging, calls, and conference between them.

mesibo identifies each user by a unique random string, called address. The address can be anything, for example, phone number, email address, your enterprise user ID, etc. You need to create a mesibo user for each of your app users.

mesibo will generate an authentication token when you create a user. This user token is also called the access token. You need to send this token to your apps so that your app can initialize mesibo Mesibo Real-time APIs using this token. Refer to the Get Started tutorial to learn more about it.

mesibo backend user-management APIs allow you to create and edit users and able to generate access tokens. You can anytime add, edit or delete users or access tokens using backend APIs as explained below.

Adding a User

To add a user and to generate a user access token, you need to send the following JSON request to the backend API:

{
  "op":"useradd",
  "token": "ptlk9hdel1gqxf3p0s15f5f5gtusldej18tl794suzit",
  "user": {
	"address":"xyz@example.com",
	"name":"User Name",

  	"token": {
		"appid": "com.example.mesiboapp",
		"expiry": 525600
  	}
  }
}

Following are the request parameters, some of them are OPTIONAL.

  • op = “useradd”
  • token = Application Token obtained from the mesibo console
  • user.address = User Address (unique string). For example, phone number, email address, enterprise user ID, etc.
  • user.flags =User Flags [Optional]
  • user.active = enable user, default true (active) [Optional]
  • user.token = Access token object with parameters as explained below. The access token will not be generated if this object is not present in the request. [Optional]
  • user.token.appid = Android package name declared in the AndroidManifest.xml (and google-services.json), Or iOS Bundle id declared in the Xcode project. The generated token will be applicable for the app having this package name or Bundle id only. For all other platforms, you can pass any non-numeric, dotted string (for example, com.yourdomain.yourapp), and the same need to be passed to the setAppName function. Use lower case only.
  • user.token.expiry = token expiry in minutes, default 1 year [Optional]. You should generate the token for a long duration instead of regenerating it. Regenerating tokens too many times may be charged.
  • user.profile.name = Name of the user [Optional]
  • user.profile.image = Image URL of the user [Optional]
  • user.profile.tn = base64 tn of the user [Optional]
  • user.profile.status = Status text of the user [Optional]
  • user.profile.description = Description text of the user [Optional]

If the request is successful, the response will be like,

{ 
  "user": {
	"uid":123,
	"address":"xyz@example.com",
	"token":"79a818d76fe45fb5a3ac395a0a98251c3db2eetb7b0d4aa0"
  },
  "op":"useradd",
  "result":true
}

where,

  • user.address = User address that was sent in the request
  • user.uid = Numerical unique user ID generated by the backend. You can use this UID instead of the address in other requests.
  • user.token = Access token which you should use in the real-time API

You should save user information (UID, Address, Access Token, etc.) from the response to your own database so that you can access them later.

Modifying a User

To edit an existing user, send the following JSON request to the backend API. You need to use the address or the UID obtained from the useradd operation.

{
  "op":"userset",
  "token": "ptlk9hdel1gqxf3p0s15f5f5gtusldej18tl794suzit",
  "user": {
	"uid":123
  }
  "profile": {
	"name":"User Name",
	"image":"https://example.com/image.jpg",
	"description":"Some description",
  }
}
  • op = “userset”

The userset request is the same as the useradd request. The only difference is that the user MUST already exist for the userset request to succeed. The request will fail if the user does not exist.

The request and response parameters are the same as the ones in useradd operation.

Deleting a User

Delete an existing user using address or UID obtained from the useradd operation.

{
  "op":"userdel",
  "token": "ptlk9hdel1gqxf3p0s15f5f5gtusldej18tl794suzit",
  "user": {
	"uid":123
  }
}
  • op = “userdel”
  • token = Application Token obtained from the mesibo console
  • uid = User ID

If the request is successful, the response will be like,

{ 
  "user": { 
	  "uid":123 
  },
  "op":"userdel",
  "result":true
}

Delete a User Access Token

Delete an existing user access token without deleting a user. The user will be logged-out but mesibo will store all received messages for the user. Those messages will be delivered when the user logs in the next time with a new token.

To delete the user token, send userset request with user.token.remove parameter:

{
  "op":"userset",
  "token": "ptlk9hdel1gqxf3p0s15f5f5gtusldej18tl794suzit",
  "user": {
	"uid":123

  	"token": {
		"remove": true
  	}
  }
}

Get Users (on-premise hosted backend only)

Get users using an address or a UID. You can use a pattern to get matching users.

On Cloud, this API is only for development purposes only, and hence it is rate-limited and a maximum of 20 users will be returned. The reason is that many mesibo customers have millions of users and it is not practical to retrieve them. You should store your users locally instead of obtaining from the mesibo. You MUST not use this API in production and excessive use can be blocked. However, no such limitations apply for on-premise.

To get users, send usersget request with address or uid parameter and the count. You can also send empty request (without address or uid).

{
  "op":"usersget",
  "token": "ptlk9hdel1gqxf3p0s15f5f5gtusldej18tl794suzit",
  "count": 50
  "user": {
	"uid":123
  }
}

You can also use ‘*’ wildcards in address field to get multiple users matching the pattern, for example,

{
  "op":"usersget",
  "token": "ptlk9hdel1gqxf3p0s15f5f5gtusldej18tl794suzit",
  "count": 50
  "user": {
	"address": "hello*"
  }
}
chat api backend, server-side api guide, chat app backend references, mesibo backend api, php, rest api