🏢 Companies House API Test Tool

Test your API connection and verify PSC data

Step 1: Configure Your API Key

Get your free API key at: developer.company-information.service.gov.uk

Step 2: Test API Connection

📋 Test with Known Companies (click to test):

MARINE AND GENERAL MUTUAL LIFE - 00006400
Long-established company with clear PSC data
DAVIES CRANE HIRE LIMITED - 07039346
Example from your template
SMITH ENGINEERING SERVICES LTD - 13474631
Recent company with standard PSC structure

Test Results:

Step 3: Implementation Options

🖥️ Local Testing (Current Setup)

For local testing, you need to use a CORS proxy because browsers block direct API calls from local files.

Important: The CORS proxy is for testing only. For production, use one of these options:

Option 1: Use a Local Server

# If you have Python installed:
python -m http.server 8000

# Or with Node.js:
npx http-server

# Then open: http://localhost:8000

Option 2: Chrome with Disabled Security (Testing Only)

# Windows:
chrome.exe --user-data-dir="C:/temp" --disable-web-security

# Mac:
open -n -a /Applications/Google\ Chrome.app --args --user-data-dir="/tmp/chrome" --disable-web-security

# Linux:
google-chrome --disable-web-security --user-data-dir="/tmp"

🌐 Server Setup

For production use, create a simple backend proxy:

Node.js Express Server:

// server.js
const express = require('express');
const axios = require('axios');
const app = express();

app.use(express.static('public'));

app.get('/api/company/:number', async (req, res) => {
    try {
        const response = await axios.get(
            `https://api.company-information.service.gov.uk/company/${req.params.number}`,
            {
                headers: {
                    'Authorization': 'Basic ' + Buffer.from(process.env.API_KEY + ':').toString('base64')
                }
            }
        );
        res.json(response.data);
    } catch (error) {
        res.status(error.response?.status || 500).json({ error: error.message });
    }
});

app.get('/api/company/:number/persons-with-significant-control', async (req, res) => {
    // Similar implementation for PSC endpoint
});

app.listen(3000, () => {
    console.log('Server running on http://localhost:3000');
});

Environment Variables (.env):

API_KEY=your-companies-house-api-key-here

💻 Integration Code for Your Application

Add this to your main application:

// Companies House API Integration
class CompaniesHouseAPI {
    constructor(apiKey, useProxy = false) {
        this.apiKey = apiKey;
        this.useProxy = useProxy;
        this.baseURL = useProxy 
            ? 'https://api.allorigins.win/raw?url=' + encodeURIComponent('https://api.company-information.service.gov.uk')
            : 'https://api.company-information.service.gov.uk';
    }

    async getCompany(companyNumber) {
        const url = `${this.baseURL}/company/${companyNumber}`;
        return this.makeRequest(url);
    }

    async getPSCs(companyNumber) {
        const url = `${this.baseURL}/company/${companyNumber}/persons-with-significant-control`;
        return this.makeRequest(url);
    }

    async getOfficers(companyNumber) {
        const url = `${this.baseURL}/company/${companyNumber}/officers`;
        return this.makeRequest(url);
    }

    async makeRequest(url) {
        try {
            const response = await fetch(url, {
                headers: {
                    'Authorization': 'Basic ' + btoa(this.apiKey + ':')
                }
            });
            
            if (!response.ok) {
                throw new Error(`API Error: ${response.status}`);
            }
            
            return await response.json();
        } catch (error) {
            console.error('API Request failed:', error);
            throw error;
        }
    }
}

// Usage in your app:
const api = new CompaniesHouseAPI('your-api-key', true); // true for local testing

async function verifyPSC(companyNumber, expectedName, expectedAddress) {
    try {
        const pscs = await api.getPSCs(companyNumber);
        
        for (const psc of pscs.items) {
            if (psc.name && psc.name.includes(expectedName)) {
                const match = {
                    nameMatch: psc.name === expectedName,
                    addressMatch: compareAddresses(psc.address, expectedAddress),
                    actualData: psc
                };
                return match;
            }
        }
        
        return { found: false };
    } catch (error) {
        console.error('Verification failed:', error);
        return { error: error.message };
    }
}