---
title: OrgBook BC (Canada, British Columbia)
url: https://documentation.cluedin.net/govern/rest-api-enricher-samples/orgbook-british-columbia
content_type: reference
section: Govern & improve > REST API enricher samples
---

# OrgBook BC (Canada, British Columbia)

> reference: Facts, options, APIs.

This example looks up an organization's British Columbia registration number (for example `BC0578072`, `FM0000001` or `A0076250`) in [OrgBook BC](https://orgbook.gov.bc.ca/), the Province of British Columbia's public directory of the registrations issued by the BC Corporate Registry. For each golden record it stores the registered name, the Canada Revenue Agency business number, the registration type, whether the registration is active or historical, the registration and status dates, and the home jurisdiction. No API key is needed.

**Enricher version:** V2  
**API key:** not needed

### OrgBook BC and the BC Registries Business API

OrgBook BC publishes only the basic facts of each registration. It has **no addresses, directors, officers or filings**. BC Registries' own [Business API](https://developer.api.bcregistry.gov.bc.ca/) has those, but it needs a BC Registries account and an API key, and searches are charged fees. This sample uses OrgBook BC so that it works without an account. If you have Business API access, you can adapt the script to call it instead.

To set up the enricher, see [Add REST API enricher](https://documentation.cluedin.net/govern/enrichment/rest-api.md#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** – leave empty.

- **Filters** – we recommend a rule that only accepts golden records where `organization.bcRegistrationNumber` has a value. Otherwise, every record without a registration number is listed on the enricher's **Logs** tab as having returned no results.

## Vocabulary and Properties

```
organization.bcRegistrationNumber
```

`organization.bcRegistrationNumber` holds the BC registration number (incorporation number): a prefix of one to three letters, such as `BC` (BC company), `FM` (sole proprietorship or partnership), `A` (extraprovincial company), `S` (society) or `CP` (cooperative), followed by seven digits. If your data uses another vocabulary key, change this field and the `REGISTRATION_NUMBER_KEY` value at the top of the script.

## Request and response

**Base URL:** `https://orgbook.gov.bc.ca/api/v4`  
**Endpoint:** `GET /search/topic?q={registrationNumber}&inactive=any&latest=true&revoked=false`  
**Authentication:** none  
**Rate limits:** none published. Each request takes about half a second.

The API is described in OrgBook BC's [Swagger documentation](https://orgbook.gov.bc.ca/api/). The script searches for the registration number, including historical registrations (`inactive=any`), and uses the result whose `source_id` is that number:

```http
GET https://orgbook.gov.bc.ca/api/v4/search/topic?q=BC0578072&inactive=any&latest=true&revoked=false
Accept: application/json
```

Shortened response (real response for lululemon athletica canada inc.; `credential_set` and `credential_type` left out):

```json
{
  "total": 1,
  "page_size": 10,
  "page": 1,
  "results": [
    {
      "id": 594679,
      "source_id": "BC0578072",
      "type": "registration.registries.ca",
      "names": [
        { "id": 840808, "text": "LULULEMON ATHLETICA CANADA INC.", "language": null, "type": "entity_name", "credential_id": 861822 },
        { "id": 3242553, "text": "872184155", "language": null, "type": "business_number", "credential_id": 3358408 }
      ],
      "addresses": [],
      "attributes": [
        { "id": 5858233, "type": "registration_date", "format": "datetime", "value": "1999-01-12T08:00:00+00:00", "credential_id": 861822, "credential_type_id": 1 },
        { "id": 5858235, "type": "entity_name_effective", "format": "datetime", "value": "2007-09-11T22:44:39+00:00", "credential_id": 861822, "credential_type_id": 1 },
        { "id": 5858237, "type": "entity_status", "format": "category", "value": "ACT", "credential_id": 861822, "credential_type_id": 1 },
        { "id": 5858238, "type": "entity_status_effective", "format": "datetime", "value": "1999-01-12T08:00:00+00:00", "credential_id": 861822, "credential_type_id": 1 },
        { "id": 5858239, "type": "entity_type", "format": "category", "value": "BC", "credential_id": 861822, "credential_type_id": 1 },
        { "id": 5858240, "type": "home_jurisdiction", "format": "jurisdiction", "value": "BC", "credential_id": 861822, "credential_type_id": 1 },
        { "id": 5858241, "type": "reason_description", "format": "category", "value": "Filing:NOALA", "credential_id": 861822, "credential_type_id": 1 }
      ],
      "inactive": false,
      "revoked": false,
      "effective_date": "2007-09-11T15:44:39-07:00",
      "revoked_date": null
    }
  ]
}
```

A response with no result whose `source_id` is the registration number (usually `"total": 0`) means that the number isn't in OrgBook.

## Properties added by the enricher

| Property | Response field | Example |
| -------- | -------------- | ------- |
| `orgbook.registrationNumber` | `source_id` | `BC0578072` |
| `orgbook.name` | `names` entry of type `entity_name` | `LULULEMON ATHLETICA CANADA INC.` |
| `orgbook.businessNumber` | `names` entry of type `business_number` (9-digit CRA business number) | `872184155` |
| `orgbook.entityType` | description of the `entity_type` attribute, as OrgBook BC shows it | `BC Company` |
| `orgbook.entityTypeCode` | `entity_type` attribute | `BC` |
| `orgbook.status` | `entity_status` attribute: `Active` (`ACT`) or `Historical` (`HIS`) | `Active` |
| `orgbook.statusEffectiveDate` | `entity_status_effective` attribute, as `YYYY-MM-DD` | `1999-01-12` |
| `orgbook.registrationDate` | `registration_date` attribute, as `YYYY-MM-DD` | `1999-01-12` |
| `orgbook.nameEffectiveDate` | `entity_name_effective` attribute, as `YYYY-MM-DD` | `2007-09-11` |
| `orgbook.homeJurisdiction` | `home_jurisdiction` attribute, for example `BC`, `FD` (federal) or `OT` (other) | `BC` |
| `orgbook.registeredJurisdiction` | `registered_jurisdiction` attribute, when given | `BC` |

A property is added only when OrgBook returns a value for it. Older and historical registrations often have no registration date or business number. An unknown registration type is kept in `orgbook.entityTypeCode` without a description.

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 `OrgBook BC` with the key prefix `orgbook`, 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 and dashes are removed and letters are capitalized, and numbers that lost their leading zeros are padded to seven digits, so `bc 578072` is looked up as `BC0578072`. A valid number has one to three letters followed by one to seven digits, not all zeros. Golden records without a valid number, including numbers without a letter prefix, are skipped without calling the API.

- The search also matches names and other text, so the script only uses the result whose `source_id` is the registration number. If there is more than one, a current registration comes before a historical one.

- Historical registrations (dissolved, amalgamated, cancelled and so on) are returned with `orgbook.status` = `Historical`.

- OrgBook gives times in UTC. The script converts them to dates in Pacific time (UTC−7), so a registration at midnight in Vancouver keeps its date. A time between 11 PM and midnight in winter can be given as the next day.

- If the number isn't in OrgBook, or the API returns an error, the script logs the reason and adds nothing, and nothing is cached.

- If the API reports that it is too busy (HTTP 429), the script throws an error that makes the enricher try the golden record again later.

- Successful results are cached for 24 hours per registration number. 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.

- To try the setup, create a golden record with `organization.bcRegistrationNumber` set to `BC0578072` (lululemon athletica canada inc.) or `FM0000001` (Lone Star Service, a general partnership).

## Limitations

- OrgBook BC has no addresses, directors, officers, share structure or filing history, so none of these are added. Use BC Registries' paid Business API for them.

- Only registrations from the BC Corporate Registry are used. Federally incorporated companies appear only if they are registered in British Columbia as extraprovincial companies (`A` numbers); for their federal record, see [Corporations Canada](https://documentation.cluedin.net/govern/rest-api-enricher-samples/corporations-canada.md).

- Lookups by name or by business number aren't supported.

- The `reason_description` attribute (the last filing or event, such as `Filing:NOALA`) isn't added.

## Process script

```javascript
// REST API enricher (V2) - British Columbia company lookup in OrgBook BC
//
// Looks up a golden record's BC registration number (for example BC0578072, FM0000001 or
// A0076250) in OrgBook BC (https://orgbook.gov.bc.ca/), the Province of British Columbia's public
// directory of the registrations issued by the BC Corporate Registry, and adds the result to the
// golden record as orgbook.* properties:
//
//   orgbook.registrationNumber     registration number that was looked up
//   orgbook.name                   registered name
//   orgbook.businessNumber         9-digit Canada Revenue Agency business number, when OrgBook has it
//   orgbook.entityType             registration type, for example BC Company or Sole Proprietorship
//   orgbook.entityTypeCode         registration type code, for example BC or SP
//   orgbook.status                 Active or Historical
//   orgbook.statusEffectiveDate    date of that status (YYYY-MM-DD)
//   orgbook.registrationDate       registration date (YYYY-MM-DD)
//   orgbook.nameEffectiveDate      date the current name took effect (YYYY-MM-DD)
//   orgbook.homeJurisdiction       home jurisdiction code, for example BC, or FD (federal) or OT (other) for extraprovincial companies
//   orgbook.registeredJurisdiction jurisdiction of the registration, when given
//
// OrgBook doesn't have addresses, directors or filings. BC Registries' Business API
// (https://developer.api.bcregistry.gov.bc.ca/) has them, but needs an account and charges fees.
//
// No API key is needed. See README.md next to this file for the enricher settings.
//
// A record gets no result (nothing is stored) when it has no valid registration number, when
// the number isn't in OrgBook, or when the API can't answer.

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

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

const ORGBOOK_URL = "https://orgbook.gov.bc.ca/api/v4/search/topic";

// How long to reuse an answer for the same registration number. 0 turns caching off.
const CACHE_MILLISECONDS = 24 * 60 * 60 * 1000;

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

// Labels that OrgBook BC itself shows (bcgov/orgbook-bc-client, src/i18n/en.json).
const ENTITY_TYPES = {
  A: "Extraprovincial Company", B: "Extraprovincial", BC: "BC Company", C: "Continuation In",
  CEM: "Cemetary", CP: "Cooperative", BEN: "Benefit Company", EPR: "Extraprovincial Registration",
  FI: "Financial Institution", FOR: "Foreign Registration", LIC: "Licensed (Extra-Pro)",
  LIB: "Public Library Association", LLC: "Limited Liability Company", PA: "Private Act", PAR: "Parish",
  PC: "Profession Company", PFS: "Pension Funded Society", QA: "CO 1860", QB: "CO 1862", QC: "CO 1878",
  QD: "CO 1890", QE: "CO 1897", REG: "Registraton (Extra-pro)", RLY: "Railways", SB: "Society Branch",
  T: "Trust", TMY: "Tramways", XCP: "Extraprovincial Cooperative", OTH: "Other", NON: "X Reference",
  ULC: "BC Unlimited Liability Company", CUL: "Continuation In as a BC ULC", UQA: "ULC CO 1860",
  UQB: "ULC CO 1862", UQC: "ULC CO 1878", UQD: "ULC CO 1890", UQE: "ULC CO 1897",
  CC: "BC Community Contribution Company", CCC: "Continuation In as a BC CC Company", S: "Society",
  XS: "Extraprovincial Society", SP: "Sole Proprietorship", GP: "General Partnership",
  LP: "Limited Partnership", XP: "Extraprovincial Limited Partnership", LL: "Limited Liability Partnership",
  XL: "Extrapro Limited Liability Partnership", MF: "Miscellaneous Firm", CS: "Continued In Society",
};

const STATUSES = { ACT: "Active", HIS: "Historical" };

// OrgBook times are UTC; the register works in Pacific time (UTC-8, or UTC-7 in summer).
const PACIFIC_OFFSET_MILLISECONDS = 7 * 60 * 60 * 1000;

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 "BC0578072", "bc 0578072", "BC-578072", "FM0000001", "A0076250", etc.: 1 to 3 letters
// and up to 7 digits. Numbers that lost their leading zeros are padded to 7 digits.
// Returns the registration number or null.
function parseRegistrationNumber(raw) {
  const text = raw.toUpperCase().replace(/[\s.\-]/g, "");
  const match = /^([A-Z]{1,3})(\d{1,7})$/.exec(text);
  if (!match || /^0+$/.test(match[2])) {
    return null;
  }
  return match[1] + ("0000000" + match[2]).slice(-7);
}

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

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

// "1999-01-12T08:00:00+00:00" (midnight in Vancouver) becomes "1999-01-12".
function formatDate(value) {
  const text = clean(value);
  if (!text || !/^\d{4}-\d{2}-\d{2}/.test(text)) {
    return null;
  }
  const time = Date.parse(text);
  return isNaN(time) ? text.substring(0, 10) : new Date(time - PACIFIC_OFFSET_MILLISECONDS).toISOString().substring(0, 10);
}

// Reads the first value of each type from OrgBook's names or attributes (small lists).
function valuesByType(items, field) {
  const values = {};
  const list = Array.isArray(items) ? items : [];
  for (let i = 0; i < list.length; i++) {
    const type = list[i] && list[i].type;
    if (type && values[type] === undefined && clean(list[i][field])) {
      values[type] = clean(list[i][field]);
    }
  }
  return values;
}

// Calls the API. Returns the OrgBook topic for the number, an empty object when it isn't in
// OrgBook, or null when the API can't answer.
function lookUp(registrationNumber) {
  const apiResponse = http.send({
    url: `${ORGBOOK_URL}?q=${registrationNumber}&inactive=any&latest=true&revoked=false`,
    method: "GET",
    headers: [{ Key: "Accept", Value: "application/json" }],
  });

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

  if (status === "TooManyRequests") {
    throw new Error("TooManyRequests - OrgBook BC is throttling requests, the record will be retried");
  }

  if (status !== "OK" || !body || !Array.isArray(body.results)) {
    log(`OrgBook BC could not look up ${registrationNumber}. HTTP ${status}. ${String(apiResponse.Content || "").substring(0, 200)}`);
    return null;
  }

  // The search also matches names and other text, so only the topic with this registration
  // number is used.
  const topics = body.results.filter((topic) => topic && clean(topic.source_id) &&
    clean(topic.source_id).toUpperCase() === registrationNumber);
  if (topics.length === 0) {
    log(`OrgBook BC has no registration ${registrationNumber}.`);
    return {};
  }
  // A current registration comes before a historical one.
  const current = topics.filter((topic) => topic.inactive !== true);
  return current.length > 0 ? current[0] : topics[0];
}

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

  const cacheKey = `orgbook:${registrationNumber}`;
  const cached = CACHE_MILLISECONDS > 0 ? cache.get(cacheKey) : null;
  let data = cached ? parseJson(String(cached)) : null;

  if (!data) {
    const topic = lookUp(registrationNumber);
    if (!topic || !topic.source_id) {
      return [];
    }

    const names = valuesByType(topic.names, "text");
    const attributes = valuesByType(topic.attributes, "value");
    const entityTypeCode = attributes.entity_type || null;
    const statusCode = attributes.entity_status || null;

    data = {
      "orgbook.registrationNumber": registrationNumber,
      "orgbook.name": names.entity_name || null,
      "orgbook.businessNumber": names.business_number || null,
      "orgbook.entityType": (entityTypeCode && ENTITY_TYPES[entityTypeCode]) || null,
      "orgbook.entityTypeCode": entityTypeCode,
      "orgbook.status": (statusCode && STATUSES[statusCode]) || statusCode,
      "orgbook.statusEffectiveDate": formatDate(attributes.entity_status_effective),
      "orgbook.registrationDate": formatDate(attributes.registration_date),
      "orgbook.nameEffectiveDate": formatDate(attributes.entity_name_effective),
      "orgbook.homeJurisdiction": attributes.home_jurisdiction || null,
      "orgbook.registeredJurisdiction": attributes.registered_jurisdiction || null,
    };

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

    if (CACHE_MILLISECONDS > 0) {
      cache.set(cacheKey, JSON.stringify(data), CACHE_MILLISECONDS);
    }
  }

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

response = JSON.stringify(run());
```

Up: [REST API enricher samples](https://documentation.cluedin.net/govern/rest-api-enricher-samples.md)
