Adding Users to Your App

After creating your app, you need to add users who will be using the chat functionalities.

Adding Users from Your Backend

To add users from your backend, follow these steps:

  1. Generate an authorization token by encoding your appId and apiToken in base64.
  2. Use the token to authorize your request to add users.
  3. Make a POST request to the endpoint with the user details.

Generating Authorization Token

// Generate an authorization token in Node.js
const base64 = require('base-64');

const appId = 'your_app_id';
const apiToken = 'your_api_token';
const authToken = base64.encode(`${appId}:${apiToken}`);

console.log('Authorization Token:', authToken);

Authorization Headers

Include the authorization token in the request header as shown below:

Add User Authorization

Add User Request

Backend Add Users

Example Payload

// Example code for adding users in Node.js
const axios = require('axios');

const addUser = async () => {
  const token = 'your_generated_token';
  const appId = 'your_app_id';
  const user = {
    user_identifier: 'user@example.com',
    first_name: 'First',
    last_name: 'Last',
    email: 'user@example.com',
    phone: '1234567890'
  };

  try {
    const response = await axios.post('https://lab.admin-api.mfereji.io/v1/users', {
      app_id: appId,
      users: [user]
    }, {
      headers: {
        Authorization: `Bearer ${token}`
      }
    });
    console.log('User added successfully:', response.data);
  } catch (error) {
    console.error('Error adding user:', error);
  }
};

addUser();