# Companies House API Issues

**URL:** <http://forum.companieshouse.gov.uk/t/companies-house-api-issues/11848>\
**Category:** API Issues\
**Created:** [July 16, 2025, 10:01am UTC](http://forum.companieshouse.gov.uk/t/companies-house-api-issues/11848 "2025-07-16T10:01:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![s.tank](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/s/41988e/32.png) [@s.tank](http://forum.companieshouse.gov.uk/u/s.tank)\
**Post date:** [July 16, 2025, 10:01am UTC](http://forum.companieshouse.gov.uk/t/companies-house-api-issues/11848/1 "2025-07-16T10:01:26Z")

</div>

Hi

I am currently having issues with the Companies House API and not sure what the issue is. I have created logins on Companies House and have created an app key but this still does not seem to be working. I cannot upload images as I am a new user or copy the links in the code as I cant create a topic with them in so copying the code as best as I can below.

Code 1:  
import pandas as pd  
import requests  
import json

url = “https:// **api**.companieshouse.gov.uk/search/companies?q={}”  
query = “Marks and Spencer”  
api\_key = “ **{Pasted my app key here}** ”

r = requests.get(“https:// **api**.companieshouse.gov.uk/company/04977362”,auth=(“ **{Pasted my app key here}** ”,‘’)).text  
r

Error 1:  
‘{“error”:“Invalid Authorization”,“type”:“ch:service”}’

Code 2:  
import pandas as pd  
import requests  
import urllib3  
import json

r = requests.get(“https:// **{Pasted my app key here}** :@api.companieshouse.gov.uk/company/00214436”)  
r

Error 2:

\<Response [401]\>

We’ve found that Response 401 means unauthorised access. Are you able to help me out with these issues?

---

<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:** [July 16, 2025, 12:31pm UTC](http://forum.companieshouse.gov.uk/t/companies-house-api-issues/11848/2 "2025-07-16T12:31:41Z")

</div>

When creating your app did you specify that you wanted a live app? The test / sandbox mode may not work correctly.

Depending on how you’re requesting data from Companies House you need to register your IP or the host name (if you’re using a javascript-style request). This should be done where you’ve registered your app.

If you are just using a localhost set up rather than e.g. a fixed IP there is a workaround for that, see this thread:

> [@Allow localhost JavaScript domain?](https://forum.companieshouse.gov.uk/t/allow-localhost-javascript-domain/83/12):
>
> Hello @david, A workaround is simply to give a hostname to your IP address, by editing /etc/hosts or its equivalent on your OS. 192.168.0.1 localhost my.localdomain And you can now register my.localdomain as a CH API “JavaScript domains”. Still, a status update would be appreciated, for something that was already on the backlog in 2015. Just remove the piece of code preventing localhost as a valid domain name, and you’re done.

If you are hosted on some environment with a range of host servers / IPs I think there’s a way to cover that but am not sure how. Search this forum / have a look at this thread:

> [@Getting 403 for all requests from AWS EC2](https://forum.companieshouse.gov.uk/t/getting-403-for-all-requests-from-aws-ec2/2367):
>
> Hi. I’m getting 403 Forbidden responses for requests to [https://api.companieshouse.gov.uk](https://api.companieshouse.gov.uk) from my live servers in AWS EC2. This currently happening consistently from every machine I’ve tried in eu-west-1 (Ireland) and eu-west-2 (London), including from IPs which I’ve had exclusively for many years. The api responds normally for requests with the same key from my dev environment. Can anyone please advise? Thanks.

Good luck.
