Skip to content

Mbanq API Client for the use during the F10 hackathon

Notifications You must be signed in to change notification settings

Mbanq/mbanq-api-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mbanq-api-client

Intended to be used to handle authentication and calls to the Mbanq API in js based frontend applications.

This API client is used in the mbanq-hackathon-template

This package was created for the hackathon and is not intended to be used in production.

Create an API client

Mbanq API client is very use to use.

Firs you have to add it to your application:

npm i -S Mbanq/mbanq-api-client

Before you can make calls to the self-service API, you have to initialize a new API client and authenticate yourself.

To create the API client you have to do the following:

const Mbanq = require('@mbanq/api')

const Client = new Mbanq({
  baseURL: 'https://api.cloud.mbanq.com',
  tenantId: 'your-tenant-identifier',
  clientId: 'your-client-identifier',
  clientSecret: 'your-client-secret'
})
  • baseURL: default setting points to Mbanq's evaluation evironment https://api.cloud.mbanq.com. If you work with the evaluation environment you don't have to do anything
  • tenantId: Tenant identifier of your core banking instance that you created in the console application e.g. Mbanq Cloud Console
  • clientId: Client identifier of the App you created for the API use
  • clientSecret: Client secret of the App you created for the API use

Authenticate yourself

Once you created an API client, you have to authenticate yourself before you start making calls to the API. To authenticate yourself you have to call Client.auth() function with js object that contains your username and password - see example below.

Client.auth({ username: 'web1', password: 'password' })

After the successful Client.auth() call, you should have the API tokens in the localStorage of your browser and you can start calling the API.

Calling the API

The mbanq-api-client offers you an easy way of making calls to Mbanq API. It offers a very limited set of functionality and is only intended to be used for small MVPs.

Once you created the Mbanq APi Client with the use of your tenantId, clientId and clientSecret and authenticated yourself by running Client.auth(credentials) you can start making calls to the api:

const api = Client.api()

// if you wanna do it right
// you should use a `try` and `catch` block

const yourFunction = async () => {
  try {
    const user = await api.user()
    const clients = await api.clients()
    const firstClientsAccounts = await api.accounts(clients.pageItems[0].id)
  } catch (error) {
    return error
  }
}

Supported API Calls

Since the mbanq-api-client was created just for the hackathon, it has a relatively limited functionality.

Following API calls are currently supported:

  • user() - to get the user details
  • clients(id) - to get all clients of a user or a client with a particular id
  • accounts(clientId) - to get all the accounts of a certain client
  • transferTemplates() - to get the accounts a transfer can be created from and to
  • createTransfer(transfer) - to create a 3rd party transfer (to another client of the same bank)
  • transactions(clientId) - to get the savings account transactions for a certain client

Creating a transfer

Before you create a transfer you can check which accounts you can send money to, by calling api.transferTemplates().

Once you know the accounts that are eligible for money transfers you can call api.createTransfer(transfer) where transfer object has to have the following data:

  const transfer = {
    fromOfficeId: 1,
    fromClientId: 11,
    fromAccountType: 2,
    fromAccountId: 11,
    toOfficeId: 1,
    toClientId: 12,
    toAccountType: 2,
    toAccountId: 12,
    dateFormat: 'dd MMMM yyyy',
    locale: 'en',
    transferDate: '4 September 2019',
    transferAmount: '1.00',
    transferDescription: 'Subject of the transfer'
  }

  const sendMoney = async (transfer) => {
  try {
    return await api.createTransfer(transfer)
  } catch (error) {
    return error
  }
}

Report a problem

Whenever you experience a problem with this template or the mbanq-api-client

Create an Issue