I am getting error "The remote server returned an error: (404) Not Found"

I am wondering with company house api.

I am trying to call api with some company registration number.

company house api returning The remote server returned an error: (404) Not Found error if i am passing wrong company registration number.

If i am passing correct company registration number it gives me JASON response.

So how we can identified that company is not found or wrong company registration number from api response as give 404 error.

Please guide us.

Many thanks

@jayesh_baldha,

Could you provide the URL that you are requesting?

Thanks

@mfairhurst

https://api.companieshouse.gov.uk/company/Orange156’ throwing 404 error

Whereas, ‘https://api.companieshouse.gov.uk/company/05965465’ is working fine.

thanks

URL construction requires company number ie api.companieshouse.gov.uk/company/ followed by the company number of the company you are interested in. ‘Orange156’ is not a company number and therefore returns a 404 not found because it cannot find it…

Hello,
Sorry to post in this topic but I was not sure if it was worth starting a new topic

I can call API from localhost, it returns JSON response. However, when I run it from my live website the IP and domains of which are in the API key settings, it returns 404 response.

Any idea why this could be?

Thanks.

@oxieking83,

Is this for every call made? Can you provide details of which endpoint and any parameters provided?

Thanks

@mfairhurst

It is : https://api.companieshouse.gov.uk/company/" + companyID

string credentials = String.Format("{0}:{1}", “MyAPIKey:”,"");
byte[] bytes = Encoding.ASCII.GetBytes(credentials);
string base64 = Convert.ToBase64String(bytes);
string authorization = String.Concat("Basic ", base64);
HttpWebRequest webReq = )HttpWebRequest)WebRequest.Create(“https://api.companieshouse.gov.uk/company/” + companyID);
webReq.UseDefaultCredentials = true;
webReq.Headers.Add(“Authorization”, authorization);
webReq.Method = “GET”;
webReq.ContentType = “application/json”;
HttpWebResponse webResp = (HttpWebResponse)webReq.GetResponse();

Sorry, actually now it gives 401 Error (when run live)
Thanks.

@oxieking83

If I’m reading the code correctly then you do not need to append the : at the end of your “MyAPIKey” in the following line of code

string credentials = String.Format("{0}:{1}", "MyAPIKey:","");

This colon is added through “{0}:{1}” with the api key replacing {0} and blank replacing {1} but with the colon in between.

Apologies if this is just a mistake in the posting of the code on the forum, please let me know.

Thanks

@mfairhurst