I’m not sure why you’ve got a URL-encoded closing single quote / apostrophe on the end of the URL you report there? That probably won’t help you, if that’s what you’re trying to send…
Given that apparently Companies House do have some ongoing CORS issues when calling via AJAX (what you’re doing with typescript / react) this complicates things. Many people are making apparently valid requests which are failing currently.
The standard pattern for investigating “401 issues” is:
a) If at all possible use a basic, well-known tool like Curl to send the simplest possible request to the server to ensure all is working and give you detailed feedback on the process. Curl is good for this, it’s very verbose. This is to check that:
- the API key is correct
- your application details are correctly registered with Companies House - as you mention you need to register the javascript domain, if using a local server there’s a workaround for that etc.), you should choose to create a live application not test/sandbox
- the URL you are requesting is correct (starting with the request for a company profile is a good idea as there are no parameters to worry about).
b) Ensure you’ve understood HTTP Basic and how the Companies House API key fits into that (e.g. it is the username in this scheme, the password is blank / empty).
c) Ensure you understand how your programming language / environment works with http basic (if you’re doing a fetch it’s up to you to build the header correctly, other tools / environments often work differently).
Good luck.