Companies House API using Node.js

We will show how to call Companies API using Node.js.

We will use ES6 Node.js node-fetch library for the Companies House BETA API

UPDATE – 24/12/2022 you can use node-fetch library to fetch data from Companies House API. See code snippets below. If you encounter the following error message:

import fetch, {Headers}  from "node-fetch"      ^^^^^^                                                                                          SyntaxError: Cannot use import statement outside a module

Then use:

const fetch = require('node-fetch');

Instead of

import fetch, {Headers}  from "node-fetch"

Installation instructions

Run npm install --save companies-house-api-es6

Usage

First you will need to create an account on companies house and get an API Key

Then you will need to include the library

const CHA = require('companies-house-api-es6');
const cha = new CHA('YOUR_API_KEY');

Example of calling Companies House API endpoint using node-fetch module

import fetch, {Headers}  from "node-fetch"
const fetch = require('node-fetch');

const args = process.argv.slice(2)
console.log(args[0])
var crn = args[0]
var url = 'https://api.companieshouse.gov.uk/company/' + crn;
var key = 'API Key';
var headers = new Headers ({
  'Authorization': 'Basic ' + btoa(key),
  'Content-Type': 'text/json',
  'Origin': '127.0.0.1'
});
var obj = {
  mode: 'cors',
  method: 'GET',
  cache: 'no-cache',
  headers: headers
};
fetch(url, obj)
.then((resp) => resp.json())
.then(data => console.log(data))
.catch(function(err) {
  console.log(err);
});

Result return

$ node crn.js 12020550
12020550
{
  links: {
    filing_history: '/company/12020550/filing-history',
    persons_with_significant_control: '/company/12020550/persons-with-significant-control',
    self: '/company/12020550',
    officers: '/company/12020550/officers'
  },
  registered_office_is_in_dispute: false,
  date_of_creation: '2019-05-28',
  has_charges: false,
  previous_company_names: [
    {
      effective_from: '2019-05-28',
      name: 'CETEL UK LIMITED',
      ceased_on: '2020-03-02'
    }
  ],
  company_number: '12020550',
  company_name: 'AXESS NETWORKS SOLUTIONS UK LTD',
  etag: '90348e60e3d476426c1caf1a69aac7dcdb8faa95',
  accounts: {
    next_accounts: {
      period_end_on: '2021-12-31',
      period_start_on: '2021-01-01',
      overdue: false,
      due_on: '2022-09-30'
    },
    next_due: '2022-09-30',
    accounting_reference_date: { month: '12', day: '31' },
    overdue: false,
    last_accounts: {
      made_up_to: '2020-12-31',
      type: 'small',
      period_start_on: '2020-01-01',
      period_end_on: '2020-12-31'
    },
    next_made_up_to: '2021-12-31'
  },
  registered_office_address: {
    country: 'United Kingdom',
    address_line_1: '2nd Floor 168 Shoreditch High Street',
    locality: 'London',
    postal_code: 'E1 6RA'
  },
  jurisdiction: 'england-wales',
  company_status: 'active',
  has_insolvency_history: false,
  sic_codes: [ '61900' ],
  confirmation_statement: {
    last_made_up_to: '2021-05-27',
    next_made_up_to: '2022-05-27',
    overdue: false,
    next_due: '2022-06-10'
  },
  undeliverable_registered_office_address: false,
  type: 'ltd',
  has_super_secure_pscs: false,
  can_file: true
}
$


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *