CBRIS (Mauritius)

reference Facts, options, APIs

On this page

This example looks up an organization’s Business Registration Number (BRN) in the Companies and Businesses Registration Integrated System (CBRIS) of Mauritius’s Corporate and Business Registration Department, by using the CBRIS-Search-Basic-API that Mauritius Network Services (MNS), the CBRIS operator, sells on its API Mall. For each golden record it stores the registered name, former name, file number, status, category, type, incorporation date, defunct date, winding-up status, and registered address.

Enricher version: V2
API key: the consumer key and consumer secret of an API Mall application subscribed to CBRIS-Search-Basic-API (a paid call package from MNS)

To set up the enricher, see Add REST API enricher, then use the settings and script on this page.

Settings

  • Accepted Business Domain – /Organization, or the business domain that holds your companies.

  • Version – V2 (recommended).

  • API Key – your API Mall application’s consumer key and consumer secret, separated by a colon: consumerKey:consumerSecret. The script uses them to get an access token. If the field is empty or has no colon, the script adds nothing and doesn’t call the API.

  • Filters – we recommend a rule that only accepts golden records where organization.brn has a value. Otherwise, every record without a BRN is listed on the enricher’s Logs tab as having returned no results.

Vocabulary and Properties

organization.brn

organization.brn holds the BRN, one letter followed by 8 digits (for example C07000001). If your data uses another vocabulary key, change this field and the BRN_KEY value at the top of the script.

Request and response

Base URL: https://gateway-apimall.mns.mu/cbris-search-basic
Endpoint: GET /basicCompanyDetails?searchCriteria=BRN&searchParam={brn}
Authentication: OAuth2 access token in the Authorization: Bearer header. The script gets the token from https://apimall.mns.mu/oauth2/token with the client credentials grant.
Rate limits: none per second (the API’s throttling tier is Unlimited), but each call counts against the yearly call quota of your package.

The endpoint, parameters, authentication and response schema are from the API’s OpenAPI specification on the API Mall (API CBRIS-Search-Basic-API, version 1.0.0). The token endpoint is from the API Mall’s OpenID Connect discovery document (https://apimall.mns.mu/oauth2/oidcdiscovery/.well-known/openid-configuration).

How to get credentials

  1. Sign up on the MNS API Mall developer portal.
  2. Buy a CBRIS Basic call package from MNS (contact customer.service@mns.mu). The API Mall price list lists packages from 25,000 calls a year (Mini 25) to 2,000,000 calls a year.
  3. In the developer portal, create an application, subscribe it to CBRIS-Search-Basic-API, and generate its production keys. Enter the consumer key and consumer secret in the API Key field as consumerKey:consumerSecret.

Requests

First, the script gets an access token (once, then it reuses the token until 5 minutes before it expires):

POST https://apimall.mns.mu/oauth2/token
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials&client_id=<consumer key>&client_secret=<consumer secret>

Then it sends one request per golden record:

GET https://gateway-apimall.mns.mu/cbris-search-basic/basicCompanyDetails?searchCriteria=BRN&searchParam=C07000001
Authorization: Bearer <access token>
Accept: application/json

Illustrative response, shaped like CompanySearchBasicResponse in the OpenAPI specification (the values are made up; we couldn’t call the API without a paid subscription):

{
  "message": "SUCCESS",
  "organisationBasicInfo": {
    "companyDetails": {
      "orgNo": "C07000001",
      "orgFileNo": "C07000001",
      "orgName": "EXAMPLE TRADING LTD",
      "formerOrgName": "EXAMPLE LTD",
      "orgLastStaCd": "Live",
      "categoryDesc": "Domestic",
      "subCategoryDesc": "Company Limited by Shares",
      "orgTypeCd": "Private",
      "orgNatureCd": "Domestic",
      "orgIncorpDate": "2007-01-15",
      "defunctDate": "",
      "windingUpStatus": null,
      "companyAddress": "1 Example Street, Port Louis"
    },
    "officeBearersList": [],
    "shareHoldersList": [],
    "statedCapitalsList": [],
    "annualReturnList": []
  }
}

Without valid credentials, the gateway answers HTTP 401 ({"code":"900902","message":"Missing Credentials", ...}), or HTTP 500 or 401 with code 900900 or 900901 for a token it doesn’t accept.

Properties added by the enricher

Property Response field (organisationBasicInfo.companyDetails) Example (illustrative)
cbris.brn the BRN that was looked up C07000001
cbris.fileNumber orgFileNo C07000001
cbris.name orgName EXAMPLE TRADING LTD
cbris.formerName formerOrgName EXAMPLE LTD
cbris.status orgLastStaCd Live
cbris.category categoryDesc Domestic
cbris.subCategory subCategoryDesc Company Limited by Shares
cbris.type orgTypeCd Private
cbris.nature orgNatureCd Domestic
cbris.incorporationDate orgIncorpDate, as YYYY-MM-DD 2007-01-15
cbris.defunctDate defunctDate, as YYYY-MM-DD 2020-06-30
cbris.windingUpStatus windingUpStatus Wound up
cbris.address companyAddress 1 Example Street, Port Louis

A property is added only when CBRIS returns a value for it. The specification doesn’t define the date format, so the script accepts YYYY-MM-DD (with or without a time) and DD/MM/YYYY; a date in another format is left out. Check the first real results and adjust toDate in the script if needed.

If the enricher has a Preview tab, the results appear there first. To add them to golden records, go to the Map tab, select Map Data, and choose Auto Mapping. Select the business domain, enter a new vocabulary named CBRIS with the key prefix cbris, and then create the mapping. Auto mapping also uses name as the golden record name, so remove that from the mapping if you want to keep your existing names. Then process the data on the Process tab. If the enricher has no Preview tab, the properties are added to the golden record as soon as it is enriched.

How the script handles input and errors

  • Spaces, dots, slashes and dashes are removed and letters are capitalized, so c07 000 001 is looked up as C07000001. Golden records without a BRN (one letter and 8 digits) are skipped without calling the API. The BRN has no check digit.

  • If the API Key field is empty or isn’t consumerKey:consumerSecret, the script adds nothing and doesn’t call the API.

  • If the token endpoint rejects the consumer key and secret (HTTP 400, 401 or 403), the script throws an error, so the golden record is listed on the Logs tab with a message to check the API Key field.

  • If the gateway rejects the access token (HTTP 401 or 403, or a WSO2 9009xx error code, which the gateway sometimes sends with HTTP 500), the script gets a new token and tries once more. If that fails too, it throws an error that asks you to check the credentials and that the application is subscribed to CBRIS-Search-Basic-API.

  • If the BRN isn’t found (no companyDetails with a name in the answer) or the API returns another error, the script logs the reason and adds nothing.

  • If the API reports that it is too busy (HTTP 429, or the WSO2 throttling code 9008xx), the script throws an error that makes the enricher try the golden record again later.

  • Successful results are cached for 24 hours per BRN. Not-found answers and errors aren’t cached. To change this, edit CACHE_MILLISECONDS in the script.

Testing the enricher

  • Test connection checks only that the script runs. It doesn’t call the API or the token endpoint.

  • To try the setup, create a golden record with organization.brn set to the BRN of a company you know, for example one from the free CBRIS Online Search.

Limitations

  • MNS charges for API use, per call package. Every lookup, including BRNs that aren’t found, uses a call. Keep the cache on and use a filter so that records without a BRN aren’t sent.

  • This sample hasn’t been run against the live API (it needs a paid subscription). The response fields come from the OpenAPI specification, which doesn’t give example values, date formats or the not-found answer. Check the first results on the Preview tab.

  • Only the company details are added. Office bearers, shareholders, stated capital, charges, annual returns, financial statements and business details (businessDetailsList) are in the same response but aren’t added; office bearers and shareholders are personal data.

  • Only search by BRN is used. The API can also search by company file number (FILE_NO) or name (COMPANY_NAME).

Process script

// REST API enricher (V2) - Mauritian company lookup in CBRIS
//
// Looks up a golden record's Mauritian Business Registration Number (BRN) in the Companies and
// Businesses Registration Integrated System (CBRIS) of the Corporate and Business Registration
// Department, using the paid "CBRIS-Search-Basic-API" that Mauritius Network Services (MNS), the
// CBRIS operator, publishes on its API Mall (https://apimall.mns.mu/devportal/), and adds the
// result to the golden record as cbris.* properties:
//
//   cbris.brn                 Business Registration Number that was looked up
//   cbris.fileNumber          company file number (orgFileNo)
//   cbris.name                registered name
//   cbris.formerName          former name
//   cbris.status              status of the company, as CBRIS returns it (orgLastStaCd)
//   cbris.category            category (categoryDesc)
//   cbris.subCategory         sub-category (subCategoryDesc)
//   cbris.type                company type (orgTypeCd)
//   cbris.nature              nature of the company (orgNatureCd)
//   cbris.incorporationDate   date of incorporation (YYYY-MM-DD)
//   cbris.defunctDate         date the company became defunct (YYYY-MM-DD)
//   cbris.windingUpStatus     winding-up status
//   cbris.address             registered office address
//
// Needs an API Mall application subscribed to CBRIS-Search-Basic-API (a paid call package from
// MNS). Enter the application's consumer key and consumer secret in the enricher's API Key field
// as consumerKey:consumerSecret. The script gets an access token itself and reuses it until
// shortly before it expires. See README.md next to this file for the enricher settings.
//
// A record gets no result (nothing is stored) when it has no valid BRN, when the BRN isn't
// registered, or when the API can't answer. Missing credentials make no call; rejected
// credentials fail the record with an error that says so.

// ---- Settings -------------------------------------------------------------------------

// Vocabulary key to read. Add the same key to the Vocabulary and Properties field.
const BRN_KEY = "organization.brn";

const CBRIS_URL = "https://gateway-apimall.mns.mu/cbris-search-basic/basicCompanyDetails";
const TOKEN_URL = "https://apimall.mns.mu/oauth2/token";

// The {APIKey} placeholder is replaced with the API Key field value (consumerKey:consumerSecret).
const API_KEY = "{APIKey}";

// How long to reuse an answer for the same BRN. 0 turns caching off. Every call counts against
// your MNS call package, so keep the cache on.
const CACHE_MILLISECONDS = 24 * 60 * 60 * 1000;

// ---- Script ---------------------------------------------------------------------------

function getValue(key) {
  // A plain loop rather than vocabularies.find(...): vocabularies is a .NET list, and when
  // .find is called from inside a function, later calls return the first call's match.
  const items = vocabularies || [];
  for (let i = 0; i < items.length; i++) {
    if (items[i].Key === key) {
      const value = items[i].Value;
      return value === null || value === undefined ? "" : String(value).trim();
    }
  }
  return "";
}

// Accepts "C07000001", "c07 000 001", "C07-000001", etc. Returns the BRN in capitals, or null when
// it isn't a BRN (one letter and 8 digits; the BRN has no check digit).
function parseBrn(raw) {
  const text = raw.toUpperCase().replace(/[\s.\-\/]/g, "");
  return /^[A-Z]\d{8}$/.test(text) ? text : null;
}

function clean(value) {
  if (value === null || value === undefined) {
    return null;
  }
  const text = String(value).replace(/\s+/g, " ").trim();
  return text === "" || text.toLowerCase() === "null" ? null : text;
}

function parseJson(text) {
  try {
    return JSON.parse(text);
  } catch (e) {
    return null;
  }
}

// The API specification doesn't define a date format. Accepts YYYY-MM-DD (with or without a
// time) and DD/MM/YYYY or DD-MM-YYYY; anything else is left out.
function toDate(value) {
  const text = clean(value);
  if (!text) {
    return null;
  }
  if (/^\d{4}-\d{2}-\d{2}/.test(text)) {
    return text.substring(0, 10);
  }
  const match = /^(\d{2})[\/\-](\d{2})[\/\-](\d{4})/.exec(text);
  return match ? `${match[3]}-${match[2]}-${match[1]}` : null;
}

function credentials() {
  const value = clean(API_KEY) || "";
  const separator = value.indexOf(":");
  if (separator <= 0 || separator === value.length - 1) {
    return null;
  }
  return { clientId: value.substring(0, separator), clientSecret: value.substring(separator + 1) };
}

// WSO2 API gateway error codes: 9009xx are authentication failures (sometimes sent with HTTP 500),
// 9008xx are throttling.
function gatewayCode(body) {
  return body && body.code ? String(body.code) : "";
}

// Gets an access token with the OAuth2 client credentials grant.
function requestToken(creds) {
  const tokenResponse = http.send({
    url: TOKEN_URL,
    method: "POST",
    headers: [
      { Key: "Content-Type", Value: "application/x-www-form-urlencoded" },
      { Key: "Accept", Value: "application/json" },
    ],
    body:
      "grant_type=client_credentials" +
      `&client_id=${encodeURIComponent(creds.clientId)}` +
      `&client_secret=${encodeURIComponent(creds.clientSecret)}`,
  });

  const status = String(tokenResponse.HttpStatus || "");
  const body = parseJson(tokenResponse.Content);

  if (status === "TooManyRequests") {
    throw new Error("TooManyRequests - the MNS API Mall token endpoint is busy, the record will be retried");
  }

  if (status === "OK" && body && body.access_token) {
    return { accessToken: String(body.access_token), expiresIn: Number(body.expires_in) || 3600 };
  }

  const reason = body && (body.error || body.error_description) ? `${body.error || ""} ${body.error_description || ""}`.trim() : `HTTP ${status}`;
  if (status === "BadRequest" || status === "Unauthorized" || status === "Forbidden") {
    throw new Error(`MNS API Mall rejected the consumer key and secret in the API Key field (${reason}).`);
  }
  log(`Could not get an MNS API Mall access token. ${reason}. ${String(tokenResponse.Content || "").substring(0, 200)}`);
  return null;
}

// Returns an access token, from the cache when there's one that hasn't expired.
function getAccessToken(creds, forceNew) {
  const cacheKey = `cbris:token:${creds.clientId}`;
  if (!forceNew) {
    const cached = cache.get(cacheKey);
    if (cached) {
      return String(cached);
    }
  }

  const token = requestToken(creds);
  if (!token) {
    return null;
  }
  // Reuse the token until 5 minutes before it expires (at least 1 minute). A forced new token
  // isn't cached, because cache.set does nothing when the key already exists.
  if (!forceNew) {
    cache.set(cacheKey, token.accessToken, Math.max(60, token.expiresIn - 300) * 1000);
  }
  return token.accessToken;
}

function callApi(brn, accessToken) {
  return http.send({
    url: `${CBRIS_URL}?searchCriteria=BRN&searchParam=${encodeURIComponent(brn)}`,
    method: "GET",
    headers: [
      { Key: "Authorization", Value: `Bearer ${accessToken}` },
      { Key: "Accept", Value: "application/json" },
    ],
  });
}

function isAuthFailure(status, body) {
  return status === "Unauthorized" || status === "Forbidden" || gatewayCode(body).indexOf("9009") === 0;
}

// Calls the API. Returns the company details, or null when there's no answer to store.
function lookUp(brn, creds) {
  const accessToken = getAccessToken(creds, false);
  if (!accessToken) {
    return null;
  }

  let apiResponse = callApi(brn, accessToken);
  let status = String(apiResponse.HttpStatus || "");
  let body = parseJson(apiResponse.Content);

  // A cached token can stop working before it expires. Try once more with a new token.
  if (isAuthFailure(status, body)) {
    const newToken = getAccessToken(creds, true);
    if (!newToken) {
      return null;
    }
    apiResponse = callApi(brn, newToken);
    status = String(apiResponse.HttpStatus || "");
    body = parseJson(apiResponse.Content);
  }

  if (status === "TooManyRequests" || gatewayCode(body).indexOf("9008") === 0) {
    throw new Error("TooManyRequests - the CBRIS API is busy, the record will be retried");
  }

  if (isAuthFailure(status, body)) {
    const message = body ? body.description || body.message || "" : String(apiResponse.Content || "").substring(0, 200);
    throw new Error(`The CBRIS API rejected the credentials in the API Key field (HTTP ${status}). Check that the application is subscribed to CBRIS-Search-Basic-API. ${message}`.trim());
  }

  const info = body && body.organisationBasicInfo;
  const details = info && info.companyDetails;
  if (status === "OK" && details && clean(details.orgName)) {
    return details;
  }

  // A BRN that isn't registered, 4xx, 5xx and others
  const detail = body && body.message ? String(body.message) : String(apiResponse.Content || "").substring(0, 200);
  log(`CBRIS could not look up ${brn}. HTTP ${status}. ${detail}`);
  return null;
}

function run() {
  const brn = parseBrn(getValue(BRN_KEY));
  if (!brn) {
    // No valid BRN on this record (this is also what Test connection hits, because it passes
    // placeholder values instead of real ones).
    return [];
  }

  const creds = credentials();
  if (!creds) {
    log("The CBRIS API needs credentials. Enter consumerKey:consumerSecret in the enricher's API Key field.");
    return [];
  }

  const cacheKey = `cbris:${brn}`;
  const cached = CACHE_MILLISECONDS > 0 ? cache.get(cacheKey) : null;
  let details = cached ? parseJson(String(cached)) : null;

  if (!details) {
    details = lookUp(brn, creds);
    if (!details) {
      return [];
    }
    if (CACHE_MILLISECONDS > 0) {
      cache.set(cacheKey, JSON.stringify(details), CACHE_MILLISECONDS);
    }
  }

  const data = {
    "cbris.brn": brn,
    "cbris.fileNumber": clean(details.orgFileNo),
    "cbris.name": clean(details.orgName),
    "cbris.formerName": clean(details.formerOrgName),
    "cbris.status": clean(details.orgLastStaCd),
    "cbris.category": clean(details.categoryDesc),
    "cbris.subCategory": clean(details.subCategoryDesc),
    "cbris.type": clean(details.orgTypeCd),
    "cbris.nature": clean(details.orgNatureCd),
    "cbris.incorporationDate": toDate(details.orgIncorpDate),
    "cbris.defunctDate": toDate(details.defunctDate),
    "cbris.windingUpStatus": clean(details.windingUpStatus),
    "cbris.address": clean(details.companyAddress),
  };

  // Leave out values CBRIS didn't return, so they don't overwrite existing data with blanks.
  Object.keys(data).forEach((key) => {
    if (data[key] === null) {
      delete data[key];
    }
  });

  return [{ Data: data, Score: 100 }];
}

response = JSON.stringify(run());