# Search Company Do not Return Proper Data while searching By Company Number

**URL:** <http://forum.companieshouse.gov.uk/t/search-company-do-not-return-proper-data-while-searching-by-company-number/2388>\
**Category:** Data Issues\
**Created:** [April 30, 2019, 10:54am UTC](http://forum.companieshouse.gov.uk/t/search-company-do-not-return-proper-data-while-searching-by-company-number/2388 "2019-04-30T10:54:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kunalmandloi](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/k/278dde/32.png) [@kunalmandloi](http://forum.companieshouse.gov.uk/u/kunalmandloi)\
**Post date:** [April 30, 2019, 10:54am UTC](http://forum.companieshouse.gov.uk/t/search-company-do-not-return-proper-data-while-searching-by-company-number/2388/1 "2019-04-30T10:54:02Z")

</div>

I am accessing Company House Api for searching Company Details. For accesiing API I have created a webservice in C#

```
public string GetCompanyDetailsByNumber(string Email, string password, string strCompanyNumber)
{
    string theURL = "https://api.companieshouse.gov.uk";
    var url = theURL + "/search/companies?q= '" + strCompanyNumber.Trim() + "' ";
    HttpWebRequest client = (HttpWebRequest)WebRequest.Create(new Uri(url));
    string results = string.Empty;
    client.Method = "GET";
    client.ContentType = "application/json";
    client.Host = "api.companieshouse.gov.uk";
     client.Headers.Add("Authorization", "Basic MY apI kEY");
    client.Accept = "text/plain,*/*; q=0.01";
    HttpWebResponse response;
    using (response = client.GetResponse() as HttpWebResponse)
    {
        // Get the response stream  
        StreamReader reader = new StreamReader(response.GetResponseStream());
        results = reader.ReadToEnd();
        // DataTable tester = (DataTable)JsonConvert.DeserializeObject( results, (typeof(DataTable)));
    }

    return results;
}

```

Above returns data when its search by Name but do not reutrn data when search by Company Number  
Kindly guide

---

<div class="post-metadata">

**Author:** ![MArkWilliams](http://forum.companieshouse.gov.uk/user_avatar/forum.companieshouse.gov.uk/markwilliams/32/194_2.png) [@MArkWilliams](http://forum.companieshouse.gov.uk/u/MArkWilliams)\
**Post date:** [April 30, 2019, 11:18am UTC](http://forum.companieshouse.gov.uk/t/search-company-do-not-return-proper-data-while-searching-by-company-number/2388/2 "2019-04-30T11:18:58Z")

</div>

First off, if you know the company number (the full 8 characters) you do not need to search, you can get the company data directly

> **[Get the basic company information](https://developer.company-information.service.gov.uk/api/docs/company/company_number/readCompanyProfile.html)**

BUT I just followed the documentation on [https://developer.companieshouse.gov.uk/api/docs/search/companies/companysearch.html](https://developer.companieshouse.gov.uk/api/docs/search/companies/companysearch.html)  
and called :-  
GET /search/companies?q=00006400  
and got back :-  
{  
“start\_index”: 0,  
“items\_per\_page”: 20,  
“items”: [  
{  
“company\_type”: “private-limited-shares-section-30-exemption”,  
“links”: {  
“self”: “/company/00006400”  
},  
“address”: {  
“address\_line\_1”: “Bressenden Place”,  
“country”: “England”,  
“postal\_code”: “SW1E 5DH”,  
“premises”: "10 ",  
“locality”: “London”  
},  
“description”: “00006400 - Incorporated on 26 June 1872”,  
“company\_status”: “active”,  
“date\_of\_creation”: “1872-06-26”,  
“title”: “THE GIRLS’ DAY SCHOOL TRUST”,  
“kind”: “searchresults#company”,  
“company\_number”: “00006400”,  
“description\_identifier”: [  
“incorporated-on”  
],  
“address\_snippet”: “10 Bressenden Place, London, England, SW1E 5DH”  
}  
],  
“page\_number”: 1,  
“kind”: “search#companies”,  
“total\_results”: 1  
}

---

<div class="post-metadata">

**Author:** ![kunalmandloi](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/k/278dde/32.png) [@kunalmandloi](http://forum.companieshouse.gov.uk/u/kunalmandloi)\
**Post date:** [April 30, 2019, 1:12pm UTC](http://forum.companieshouse.gov.uk/t/search-company-do-not-return-proper-data-while-searching-by-company-number/2388/3 "2019-04-30T13:12:21Z")

</div>

I am creating URl [https://api.companieshouse.gov.uk/company/‘CompanyNumber’](https://api.companieshouse.gov.uk/company/'CompanyNumber') but its not working throwing exception  
{“error”:“Empty Authorization header”,“type”:“ch:service”}  
Kindly Guide

---

<div class="post-metadata">

**Author:** ![voracityemail](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/v/b77776/32.png) [@voracityemail](http://forum.companieshouse.gov.uk/u/voracityemail)\
**Post date:** [April 30, 2019, 6:05pm UTC](http://forum.companieshouse.gov.uk/t/search-company-do-not-return-proper-data-while-searching-by-company-number/2388/4 "2019-04-30T18:05:14Z")

</div>

The code you posted above contains:

> client.Headers.Add(“Authorization”, “Basic MY apI kEY”);

You need something like (spelling it out):

```
String username = "MY apI kEY";
String password = "";
String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
client.Headers.Add("Authorization", "Basic " + encoded);

```

Since the error is “Empty Authorization header” then that suggests the source of the problem e.g. there’s a problem with the value you’re sending. You need to have one space after “Basic” - at least that works for me - and then base64 encode your api key. This includes the ‘:’ between the username [API key] and the [blank] password.

Not being a C# coder I used Google to look up client.Headers.Add() and authentication and this found the following on StackOverflow:

> <https://stackoverflow.com/questions/25852551/how-to-add-basic-authentication-header-to-webrequest>

…which references also:

> <https://stackoverflow.com/questions/4334521/httpwebrequest-using-basic-authentication>

…which is where I stole the code above.
