Connect via Postman says invalid authorisation header

Hi there, I’m trying to connect via Postman.

I have set the authorisation to “basic” and I have added my key. It’s asking for a username too, but I don’t seem to have one. Does anyone know what I should put in here? I have tried putting the key in both and also putting “API Key” in the user name. I can see the header is basic and I believe Postman automatically base64 encodes the header.

{    "error": "Invalid Authorization header",    "type": "ch:service"}

Can anyone help me?

I think this thread has you covered:

The way CH do this: the http “username” is their “API key” and there is no password. I think that should be fine with Postman but there are some tools which seem to prevent “blanks”.

If you want to download the actual filing documents there are a couple of details to that. I’ve an answer here which might help if you need that:

You can normally find what you want with some searching on this forum or reading the documentation. For example on this topic you might also try these threads:

Authorisation seems to be the biggest source of confusion. I guess this data / the API just has such a wide appeal that the numbers using it are large and the demographic is wide.

Thank you. Knowing not to put a password was extra information.

OK I followed these rules:

I have used basic authorisation.

I have put a colon at the end.

Postman automatically base 64 encodes it.

My url is: https://api.companieshouse.gov.uk/company/06623345/registered-office-address

My API key works on the website, so the API is correct.

Eventually I used https://www.base64decode.org/ to decode the header having followed all of the articles. This lead me to find out that my key was being used twice not once. Then I was able to find out where my username/password were still both set in Postman.

I set the collection to contain the authorisation as basic and only my key in the username followed by a colon.

I made sure password was empty.

I set the variables so I could use the base_url, hence I set the variable name base_url and https://api.companieshouse.gov.uk

Then I set it to get and {{base_url}}/company/06623345/registered-office-address which worked.

If anyone ever gets stuck in the future you can simply import this JSON file to Postman and all of the requests are set up already. All you need to do is right click on “collections” click on “edit” and then click on “authorisation” and “variables” and change them to your own. Don’t forget to add a colon after your key.

4 Likes

Thank you so much @eoin This worked.

1 Like

Can you please let us know what was the header and authorization details you put?
Please try to put some example… tried what have been mentioned by you but it is not working for me.
help appreciated.

No problems, glad it helped

your key followed by a colon. → :
e.g.
asdlfkjasdlfkjadsf:

no password.
authorisation type basic

are you using postman?

There is hardly any header information. Basic KEY
e.g. Basic adsoijasldkjfasldkfj

Yes I am using POSTMAN.
below are the details,

URL - https://api.companieshouse.gov.uk/company/06623345/registered-office-address

Headers
Authorization - Basic <my_KEY>:

here i am putting key generated on site.

Now i am getting error as “504 Gateway Timeout”

How you downloaded the API I made on Github? It has all of the calls in it properly. All you need to do is to put your key in the main configuration. Just click on the 3 dots and then click edit.

Make sure authorisation is Basic and put your key in as you have shown above. I didn’t put this into the headers I just let the config do it. I think it base64 encodes it automatically. Perhaps that’s the difference.

can you pls provide detail steps?

Eoin, may thanks for taking the time to do this. After spending many hours today trying to get the API working your script is now up and running in postman on my machine… very good of you!!!

Hello @eoin,

Thank you very much for the detailed steps.

I don’t know how many hours I have spent on this API to make it work but still no luck for me. I have followed your postman steps as well. Changed the API_Key followed by ‘:’ . Tried different ways to provide api_key as well including base64. However I am still unlucky.

My deadline for API integration is approaching and I am worrying to implement it in Python. I have a list of company names. All I want is their company number that is provided by this API in the response.

No matter what I try in python or postman… I still get the same error.

{

"error": "Invalid Authorization",

"type": "ch:service"

}

Could you please help in any manner…

Thanks in advance.