Get Started: Create Users and generate Tokens

Estimated reading time: 6 minutes

Now since we are familiar with the basic concepts and anatomy of a mesibo app, we will start creating a simple real-time app using Mesibo API for all the supported platforms - Android, iOS, Web (JavaScript), C++ (Linux, Mac, Raspberry Pi), and Python.

Before we begin coding for respective platforms, let’s learn how to create users and tokens which is common across all the platforms.

Prerequisites

Ensure that you have gone through the following prerequisites before you read further.

Type of APIs

At a high level, there are two types of mesibo APIs:

mesibo backend or server-side APIs

These are REST-based APIs that is primarily used by your backend servers to create mesibo users and to generate access tokens. It can also be used to perform various administrative tasks such as managing users and groups, managing apps, access statistics.

In this section, we will use mesibo backend APIs to create users and generate tokens.

mesibo real-time APIs

You will use these APIs from your user side apps e.g., from Android, iOS, Web, C++, Python, etc. These APIs allow the users of your app to communicate in real-time by providing APIs for 1-to-1 messaging, group messaging, voice and video calls, etc.

We will use real-time APIs in next all sections.

Create an Application and App Token

Before you create users, you need to create a mesibo application that will host all your users and groups. This is a one-time task.

Once you create a mesibo application, you will get an App Token that you need to use with mesibo backend API to create users and access tokens, groups, and other administrative tasks. Note that, all the users and groups are private to a mesibo application and no users from another app will be able to communicate with users of this app.

You can create a mesibo application from the console. Let’s say you are creating a new app FirstApp for Android, iOS, and web. Login to the mesibo console and create a new application FirstApp.

mesibo-api-key

Once your application is created, note down the App token. The App Token looks like the following:

cn9cvk6gnm15e7lrjb2k7ggggax5h90n5x7dp4sam6kwitl2hmg4cmwabet4zgdw

We will need this App Token to create users and access token for this Application.

App Token is secret and you should never expose it to your users. Hence, you MUST NOT use it in client-side APIs (Android, iOS, JS, etc)

Create Users and Access Tokens

Once you have created your application, it’s time to add users. Typically, you will add users dynamically on a need basis. However, for this sample app, you can create a few users and groups manually so that you can test messaging between them.

Note that all your users and groups are confined to an Application. So there is no conflict when the same user is created by another application.

You need to use Mesibo backend APIs to create users.

Backend API Playground

You may use Mesibo Backend API Playground to quickly familiarize yourself with the backend API syntax and parameters.

Create Users using Mesibo Backend APIs

Now we will create two users by using Mesibo backend API and the app token obtained in the previous step. In mesibo, each user is represented by an address. The address can be anything, for example, phone number, email, user-id, etc. There is no restriction on what you can as an address as long as it is unique, for example,

  • 123
  • 456

Each user requires an access token to use mesibo real-time APIs (for messaging, calls, conferencing, etc). You can generate an access token for each user using mesibo backend APIs. There are only two parameters require to generate an access token:

  1. Address
  2. App ID, which identifies the App (for example, com.example.app) and the platform (Android, iOS, Javascript, etc). You can use as many apps and platforms as required.

For example, if you are generating a token for a user who will log in using an Android App, the App ID will be the Android package name declared in the AndroidManifest.xml. For iOS apps, it is Bundle id declared in the Xcode project, for example, com.mesibo.firstapp. For all other platforms (Javascript, C++, Python, etc), you can use any string and use setAppName function. This is a security feature that restricts your users from using the user access token on intended platforms and the app only.

There is no restriction on the number of different apps with different App IDs. The users from different apps having completely different IDs can communicate with each other once you generate access tokens for them.

User Creation Request

https://api.mesibo.com/api.php?token=cn9cvk6gnm15e7lrjb2k7ggggax5h90n5x7dp4sam6kwitl2hmg4cmwabet4zgdw&op=useradd&appid=com.mesibo.firstapp&addr=123

Where

  • token = Application Token
  • appid = Android package name declared in the AndroidManifest.xml (and google-services.json, if applicable) or iOS Bundle id declared in the Xcode project (for example, com.mesibo.xxx). In the case of C++, Python, and Javascript, you can pass whatever appid you prefer. However, the same app id you will need to pass in setAppName API call. Note that, for security reasons, the token generated for a particular appid will only be usable on app matching that appid.
  • addr = end point address, for example, a user phone number.

You can find more about backend API in the reference section. The above API returns a JSON response like this,

Response

{
"user": {
	"uid":"5302",
	"token":"cn9cvk6gnm15e7lrjb2k7ggggax5h90n5x7dp4sam6kwitl2hmg4cmwabet4zgdw"
},
"op":"useradd",
"result":true
}

The token returned in the above API JSON response is the access token, that will be used by real-time API to connect to mesibo real-time server (using setAccessToken API).

You can now create more users in a similar fashion so that you can test messaging between them. You can also send messages to a particular user using the console in the ‘Users’ section.

It’s coding time now! We are now all set to create our first mobile app which can send and receive real-time messages.

From the next section onwards, we will start coding basic Mesibo applications on various platforms, starting with Android in the next section.

First Mesibo Application - Android >>

mesibo, android, ios