Status code 401

im getting error when trying to get company’s info.
such a simple task yet, i dont know what is wrong.

first of all, do my app key should be Stream key?
endpoint url should be:

i getting error StatusCode: 401, ReasonPhrase: ‘Unauthorized’,

thank you

There are several APIs and how you access them depends on which one you want to access.
You seem to be calling Companies Search in the Public Data API.

This is not the same as the Streaming API.

For accessing the Public Data API you need to use http Basic Authorization (this is supplied via http headers) and you’ll need an API key from Companies House, for their live service, and your server IP or web URI needs to be registered with them. Looking at those requirements one by one:

a) Register an application


b) When registering the application I would choose “live” rather than “test”.

c) If your application is accessing Companies House from a client environment (e.g. javascript run within a browser) register the uris you’ll be calling Companies House from.
If you are using a locally hosted web server e.g. localhost see the threads on this:

OR if your application runs on a server register the external IP address of your server.

d) Create a key

To access the public data API you’ll be providing your “API key” via “http Basic” authorization. The trick here is that the API key goes in the http Basic “username” slot / position, and the http Basic password is blank / empty. Exactly how you do that depends on what program / software you are using to make the http request to Companies House. For example, if you were using curl you would enter

curl -u MY_API_KEY_HERE: “

Note the colon (":") after your API key - the password would normally go here but when calling Companies House there is no password.

I would strongly recommend using curl or some other simple tool if calling Companies House from a server environment. That will enable you to check that you have a working API key and that your server IP has been registered with Companies House.

See Companies House documentation on this (essentially the same as I’ve written above).

Good luck.