Just thought I would add this, in case someone else has already faced it. I noticed that with .NET 4 on I can use dynamic rather than define explicitly the JSON object(s),
So trying this our I am using the c# source
var url = theURL + “/search”;
if (theSearchtext.Length > 0)
url = string.Format("{0}?q='{1}'",url, theSearchtext);
HttpResponseMessage response = client.GetAsync(url).Result;
if (response.IsSuccessStatusCode)
{
tbOutput.Text = string.Empty;
var theCompanies = response.Content.ReadAsStringAsync().Result;
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
dynamic jsonDe = JsonConvert.DeserializeObject(theCompanies);
int myIndex = 0;
if (jsonDe.total_results > 0)
{
tbOutput.Text = "Total number of Companies found: " + jsonDe.total_results+"\r\n";
tbOutput.AppendText(string.Format("\r\nItems grouped in {0}", jsonDe.items.Count));
foreach (var item in jsonDe.items)
{
tbOutput.AppendText(string.Format("\r\n{0} :: {1} :: {2}", myIndex++, item.company_number, item.title));
}
}
Using the text string “Profile Business” this produces the output
Total number of Companies found: 58996
Items grouped in 20
0 :: 09283478 :: PROFILE BUSINESS SOLUTIONS LTD
1 :: 02990482 :: PROFILE BUSINESS SERVICES LIMITED
2 :: 05881052 :: FX COMPARED LIMITED
3 :: 09914479 :: BUSINESS PROFILES LIMITED
4 :: 04582250 :: PROFILE - THE BUSINESS SOLUTIONS COMPANY LIMITED
5 :: 07675750 :: PROFILE 4 BUSINESS SUPPORT LIMITED
6 :: 04482012 :: HIGH PROFILE BUSINESS SERVICES LIMITED
7 :: :: ANGLIAN BUSINESS CONSULTANCY SERVICES
8 :: :: ANGLIAN BUSINESS CONSULTANCY SERVICES
As you can see once I get passed company 6 the Title is repeated and there is no company number. Using the q value of “Profile Business” on the web based Try It
https://developer.companieshouse.gov.uk/api/docs/search/companies/companysearch.html#here
Below is the output of company 6 and company 7. I can see that the structure is different. The structure also doesn’t match the “Items” structure defined in
https://developer.companieshouse.gov.uk/api/docs/search-overview/CompanySearch-resource.html
This may be down to my misunderstanding of what would be happening or the documentation is out of sync.
Any advice greatfully received.
{
“kind”: “searchresults#company”,
“description_identifier”: [
“dissolved-on”
],
“address_snippet”: “6 Spring Gardens, Woodford Green, Essex, England, IG8 7DD”,
“company_status”: “dissolved”,
“snippet”: “”,
“links”: {
“self”: “/company/04482012”
},
“company_number”: “04482012”,
“description”: “04482012 - Dissolved on 14 February 2012”,
“address”: {
“region”: “Essex”,
“address_line_1”: “Spring Gardens”,
“premises”: "6 ",
“locality”: “Woodford Green”,
“postal_code”: “IG8 7DD”,
“country”: “England”
},
“matches”: {
“snippet”: ,
“title”: [
6,
12,
14,
21
]
},
“title”: “HIGH PROFILE BUSINESS SERVICES LIMITED”,
“date_of_cessation”: “2012-02-14”,
“company_type”: “ltd”,
“date_of_creation”: “2002-07-10”
},
{
“matches”: {
“title”: [
1,
7
],
“snippet”: [
1,
8
]
},
“company_type”: “ltd”,
“date_of_creation”: “2008-05-27”,
“date_of_cessation”: “2012-09-11”,
“title”: “PROFILE YOU LIMITED”,
“description”: “06602233 - Dissolved on 11 September 2012”,
“address”: {
“address_line_2”: “Hale”,
“country”: “United Kingdom”,
“postal_code”: “WA15 9NJ”,
“locality”: “Altrincham”,
“premises”: "2 ",
“address_line_1”: “Park Road”,
“region”: “Cheshire”
},
“company_number”: “06602233”,
“links”: {
“self”: “/company/06602233”
},
“snippet”: "BUSINESS SERVICES 8 ",
“description_identifier”: [
“dissolved-on”
],
“kind”: “searchresults#company”,
“address_snippet”: “2 Park Road, Hale, Altrincham, Cheshire, United Kingdom, WA15 9NJ”,
“company_status”: “dissolved”
},