Getting started overview
Integrating with the UK Companies House API involves a sequence of steps designed to provide access to public company data. The process typically includes registering for a developer account, generating API credentials, and then constructing and executing your first authenticated API request. The Companies House developer documentation specifies the necessary procedures for obtaining access and interacting with their services Companies House developer documentation portal. Most data access through the API is provided without charge, although certain bulk datasets or certified documents may incur fees as detailed on the Companies House service fees page.
The API provides access to various datasets, including company profiles, filing history, and officer information. Understanding the structure of the API and its authentication mechanism is foundational for successful integration. Companies House uses API keys for authentication, which are typically managed through a developer console after account creation. Official SDKs are available for Python, Java, Ruby, PHP, and Node.js, providing wrappers around the HTTP requests to simplify integration Companies House SDK information.
This guide focuses on the practical steps to initiate your API integration, from account setup to making a successful first call. It is intended for developers and technical buyers who require programmatic access to UK company data for applications such as company registration checks, monitoring changes, or conducting due diligence.
Create an account and get keys
To begin using the UK Companies House API, you must first create a developer account. This account provides access to the developer console where you can manage your applications and generate API keys.
Account Registration
- Access the Developer Hub: Navigate to the Companies House Developer Hub.
- Register a New Account: Follow the prompts to create a new user account. This typically involves providing an email address and setting a password. You may be required to verify your email address.
- Log In: Once registered, log in to your new developer account.
Generate API Keys
After logging into the Developer Hub, you can create and manage your API keys. Companies House API keys are used to authenticate your requests and link them to your developer account.
- Create an Application: Within the developer console, locate the option to create a new application. You may need to provide a name and a description for your application. This helps organize your API key usage.
- Generate Your API Key: Once an application is created, the system will provide you with an API key. This key is a unique string that you will include in the headers of your API requests for authentication.
- Secure Your Key: Treat your API key as sensitive credentials. Do not embed it directly in client-side code, commit it to public repositories, or share it unnecessarily. Best practices suggest using environment variables or a secrets management service. For example, Google Cloud Secret Manager documentation describes methods for securing API keys and other credentials.
Your first request
Once you have obtained your API key, you can make your first API request. This example uses the Company Profile API to retrieve information about a specific company, as detailed in the Companies House Company Profile API reference. The authentication mechanism requires the API key to be passed in the Authorization header using Basic Authentication, where the username is your API key and the password field is left blank.
Example: Retrieve Company Profile (cURL)
Replace YOUR_API_KEY with your actual API key and COMPANY_NUMBER with a valid UK company registration number (e.g., 00000006 for Companies House itself).
curl -u "YOUR_API_KEY:" "https://api.companieshouse.gov.uk/company/COMPANY_NUMBER"
A successful response will return a JSON object containing details about the specified company, such as its name, address, and status.
{
"company_name": "COMPANIES HOUSE",
"company_number": "00000006",
"company_status": "active",
"registered_office_address": {
"address_line_1": "Companies House",
"locality": "Cardiff",
"postal_code": "CF14 3UZ"
},
"type": "other",
"date_of_creation": "1844-01-01",
"jurisdiction": "england-wales"
// ... other company details
}
Example: Retrieve Company Profile (Python)
Using Python's requests library, you can achieve the same result:
import requests
api_key = "YOUR_API_KEY"
company_number = "00000006" # Example: Companies House itself
url = f"https://api.companieshouse.gov.uk/company/{company_number}"
response = requests.get(url, auth=(api_key, ''))
if response.status_code == 200:
print(response.json())
else:
print(f"Error: {response.status_code} - {response.text}")
This Python script makes an authenticated GET request and prints the JSON response or an error message if the call is unsuccessful.
Quick Reference Table for First Request
| Step | What to Do | Where |
|---|---|---|
| 1. Get API Key | Register on Companies House Developer Hub, create application, generate key. | Companies House Developer Hub |
| 2. Choose Endpoint | Select an API endpoint, e.g., Company Profile API. | Company Profile API Reference |
| 3. Construct Request | Formulate the HTTP GET request with your API key in the Basic Auth header. | Your code editor/terminal |
| 4. Execute Request | Send the cURL command or run the Python script. | Your terminal/IDE |
| 5. Verify Response | Check for a 200 OK status code and valid JSON data. | Terminal output/IDE console |
Common next steps
After successfully making your first API call, you can explore further functionalities and integrate the Companies House API more deeply into your applications. Common next steps include:
- Explore Other Endpoints: Investigate other available APIs such as the Company Search API, Filing History API, or Officers API to retrieve a wider range of company data. Each API reference provides detailed information on available parameters and expected responses.
- Implement Error Handling: Develop robust error handling in your application to manage various HTTP status codes and API error messages. The Companies House API will return specific status codes (e.g., 401 for unauthorized, 404 for not found) and error bodies to indicate issues.
- SDK Integration: If you are working with Python, Java, Ruby, PHP, or Node.js, consider utilizing the official SDKs available. These SDKs abstract away the HTTP request details and provide language-specific interfaces for interacting with the API, potentially simplifying development and maintenance Companies House developer guide.
- Rate Limits and Usage: Familiarize yourself with the API's rate limits to ensure your application behaves responsibly and avoids temporary blocks. Details on rate limits are typically found within the Companies House developer guide. Implement exponential backoff or token bucket algorithms for handling rate limit responses.
- Webhooks for Events: For real-time updates on company events (e.g., new filings), investigate Companies House's webhook functionality. Webhooks allow the API to push notifications to your application when specified events occur, eliminating the need for constant polling. For general information on securing webhooks, refer to Twilio's webhook security guide.
- Data Storage and Processing: Plan how your application will store, process, and display the retrieved company data. Consider data privacy regulations like GDPR, which Companies House adheres to Companies House legal information, when handling any personal data.
Troubleshooting the first call
Encountering issues during your initial API calls is common. Here are some troubleshooting steps for typical problems:
- 401 Unauthorized: This indicates an issue with your API key.
- Check API Key: Ensure your API key is correct and has not been mistyped or expired. Regenerate it in the Companies House Developer Hub if necessary.
- Basic Auth Format: Verify that the Basic Authentication header is correctly formatted, with your API key as the username and an empty string (or blank) as the password. For cURL, ensure the
-u "YOUR_API_KEY:"format is used. - Permissions: Confirm that your API key has the necessary permissions for the endpoint you are trying to access.
- 404 Not Found: This usually means the resource you are requesting does not exist or the URL is incorrect.
- Endpoint URL: Double-check the base URL and the specific endpoint path against the Companies House API reference documentation.
- Resource Identifier: Ensure the company number or other identifier you are using is valid and correctly formatted. For example, company numbers are typically 8 digits, padded with leading zeros if shorter.
- 429 Too Many Requests: This indicates you have exceeded the API rate limits.
- Rate Limiting: Implement retry logic with exponential backoff. Wait for a period before retrying the request. Consult the Companies House developer guide on rate limits.
- 5xx Server Error: These are server-side issues with the Companies House API itself.
- Check Status Page: Look for announcements on the Companies House Developer Hub or their official communication channels for service outages.
- Retry: Often, 5xx errors are transient. Implement retries with a delay.
- JSON Decoding Errors: If your code struggles to parse the response, the issue might be with the received data.
- Inspect Raw Response: Print the raw response text before attempting to parse it as JSON to verify its content and structure.