Status code 400

Hello, Im trying to write a python code to get company profile from company registration number. I am however getting an error
“error”: “Empty Authorization header”,
“type”: “ch:service”

My code as follow:
import requests

api_key = “MY_API_KEY”
companyNumber = 99999999

url = f"{companyNumber}"

headers = {
“Authorization”: f"Bearer {api_key}",
“Content-Type”: “text/json”

response = requests.get(url, headers=headers)

You need to use http basic authorization - not supply a bearer token (which the API key is not). Noting that the Companies House API key is the username part of a the http basic authorization username:password string format (the whole is base64 encoded) and the password is blank.

The Public Data API - which you’re trying to access - uses http basic authorization. Companies House have documented this here:

and here:

Plenty of posts on this site also walk you through how to do this, use the “search” icon at the top right of the site.

1 Like

Thank you so much, your response has resolved my issue