A simple .NET client wrapper for CompaniesHouse API.
CompaniesHouse.NET can be installed via the package manager console by executing the following commandlet:
PM> Install-Package CompaniesHouse
Once we have the package installed, we can then create a CompaniesHouseSettings
with a ApiKey which can be created via the CompaniesHouse API website
var settings = new CompaniesHouseSettings(apiKey);
We need to now create a CompaniesHouseClient
- passing in the settings that we've just created.
using(var client = new CompaniesHouseClient(settings))
{
// Do some work...
}
This is the object we'll use going forward for any interaction to the CompaniesHouse API, but don't forget to call Dispose
after you've finish (or wrap in a using
block).
To search for a resource, we first need to create a SearchRequest
with details of the search we require.
var request = new SearchRequest()
{
Query = "Jay2Base",
StartIndex = 10,
ItemsPerPage = 10
};
We can then pass the SearchRequest
object in to the SearchAllAsync
method and await on the task, this will then return all related resources.
var result = await client.SearchAllAsync(request);
foreach (var item in _result.Data.Items)
{
// Do something...
}
If we need to be more precise on the resources we require, we can then pass the request object in to the required search method, either SearchCompanyAsync
or SearchOfficerAsync
or SearchDisqualifiedOfficerAsync
and await on the task.
var result1 = await client.SearchCompanyAsync(request);
var result2 = await client.SearchOfficerAsync(request);
var result3 = await client.SearchDisqualifiedOfficerAsync(request);
To get a company profile, we pass a company number in to the GetCompanyProfileAsync
method and await on the task.
var result = await client.GetCompanyProfileAsync("10440441");
If there was no match for that company number then null
will be returned.
To get a list of officers for a company, we pass a company number in to the GetOfficersAsync
method and await on the task.
var result = await client.GetOfficersAsync("03977902");
We can also pass in some optional parameters of startIndex
and pageSize
which will allow us to page the results.
var result = await client.GetOfficersAsync("03977902", 10, 10);
To get a list of the filing history for a company, we can pass a company number to the GetCompanyFilingHistoryAsync
method and await on the task.
var result = await client.GetCompanyFilingHistoryAsync("10440441");
We can also pass in some optional parameters of startIndex
and pageSize
which will allow us to page the results.
var result = await client.GetCompanyFilingHistoryAsync("10440441", 10, 10);
To get the insolvency information for a company, we can pass a company number to the GetCompanyInsolvencyInformationAsync
method and await on the task.
var result = await client.GetCompanyInsolvencyInformationAsync("10440441");
If there was no insolvency information for the given company number then null
will be returned.
- Fork
- Hack!
- Pull Request