# HTTP 401 failure when querying the API for company officers

**URL:** <http://forum.companieshouse.gov.uk/t/http-401-failure-when-querying-the-api-for-company-officers/8163>\
**Category:** API Issues\
**Created:** [July 9, 2024, 9:43am UTC](http://forum.companieshouse.gov.uk/t/http-401-failure-when-querying-the-api-for-company-officers/8163 "2024-07-09T09:43:13Z")\
**Posts on this page:** 15\
**Page:** 2

<div class="post-metadata">

**Author:** ![james5](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/j/848f3c/32.png) [@james5](http://forum.companieshouse.gov.uk/u/james5)\
**Post date:** [July 19, 2024, 5:43pm UTC](http://forum.companieshouse.gov.uk/t/http-401-failure-when-querying-the-api-for-company-officers/8163/21 "2024-07-19T17:43:54Z")

</div>

Also getting CORS errors with persons with significant control endpoint.

```
fetch("https://api.companieshouse.gov.uk/company/10993724/persons-with-significant-control", {
  "headers": {
    "authorization": "Basic API_KEY",
  },
  "referrer": "https://b2bfinance.com/",
  "referrerPolicy": "strict-origin-when-cross-origin",
  "body": null,
  "method": "GET",
  "mode": "cors",
  "credentials": "include"
});

```

Curl works as expected.

---

<div class="post-metadata">

**Author:** ![MArkWilliams](http://forum.companieshouse.gov.uk/user_avatar/forum.companieshouse.gov.uk/markwilliams/32/194_2.png) [@MArkWilliams](http://forum.companieshouse.gov.uk/u/MArkWilliams)\
**Post date:** [July 22, 2024, 12:20pm UTC](http://forum.companieshouse.gov.uk/t/http-401-failure-when-querying-the-api-for-company-officers/8163/22 "2024-07-22T12:20:44Z")

</div>

Please see [Company Officers API 401 CORS Issue](https://forum.aws.chdev.org/t/company-officers-api-401-cors-issue/7752)

---

<div class="post-metadata">

**Author:** ![MArkWilliams](http://forum.companieshouse.gov.uk/user_avatar/forum.companieshouse.gov.uk/markwilliams/32/194_2.png) [@MArkWilliams](http://forum.companieshouse.gov.uk/u/MArkWilliams)\
**Post date:** [July 22, 2024, 3:00pm UTC](http://forum.companieshouse.gov.uk/t/http-401-failure-when-querying-the-api-for-company-officers/8163/23 "2024-07-22T15:00:10Z")

</div>

Still investigating sorry.  
This is proving difficult to track down.

---

<div class="post-metadata">

**Author:** ![devops2](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/d/f19dbf/32.png) [@devops2](http://forum.companieshouse.gov.uk/u/devops2)\
**Post date:** [July 24, 2024, 9:42am UTC](http://forum.companieshouse.gov.uk/t/http-401-failure-when-querying-the-api-for-company-officers/8163/24 "2024-07-24T09:42:17Z")

</div>

Hi @MArkWilliams,

Thanks for the last update. Are there any reportable updates on this issue today? Please don’t hesitate to let me know if you require any more information from our side to aid in your investigation.

Regards

---

<div class="post-metadata">

**Author:** ![MArkWilliams](http://forum.companieshouse.gov.uk/user_avatar/forum.companieshouse.gov.uk/markwilliams/32/194_2.png) [@MArkWilliams](http://forum.companieshouse.gov.uk/u/MArkWilliams)\
**Post date:** [July 24, 2024, 11:32am UTC](http://forum.companieshouse.gov.uk/t/http-401-failure-when-querying-the-api-for-company-officers/8163/25 "2024-07-24T11:32:50Z")

</div>

No, sorry, nothing reportable. The random nature is proving a problem.

---

<div class="post-metadata">

**Author:** ![brendan.kitley](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/b/f4b2a3/32.png) [@brendan.kitley](http://forum.companieshouse.gov.uk/u/brendan.kitley)\
**Post date:** [July 25, 2024, 1:47pm UTC](http://forum.companieshouse.gov.uk/t/http-401-failure-when-querying-the-api-for-company-officers/8163/26 "2024-07-25T13:47:13Z")

</div>

HI @MArkWilliams. I’m not sure if this is any help, but our feed appears to have stabilised over the last few days. I’ll keep monitoring, but others may still be experiencing issues.  
 ![image](http://discourselive.s3.dualstack.eu-west-1.amazonaws.com/original/2X/b/b77492a21a87e020d9837221ecf4ca25c7a5ce06.png)

---

<div class="post-metadata">

**Author:** ![MArkWilliams](http://forum.companieshouse.gov.uk/user_avatar/forum.companieshouse.gov.uk/markwilliams/32/194_2.png) [@MArkWilliams](http://forum.companieshouse.gov.uk/u/MArkWilliams)\
**Post date:** [July 26, 2024, 8:16am UTC](http://forum.companieshouse.gov.uk/t/http-401-failure-when-querying-the-api-for-company-officers/8163/27 "2024-07-26T08:16:49Z")

</div>

Actually, that is very helpful, thank you.  
During investigations, we have been restarting parts of the service and that might account for the recent improvement. Investigations still on-going though.

---

<div class="post-metadata">

**Author:** ![devops2](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/d/f19dbf/32.png) [@devops2](http://forum.companieshouse.gov.uk/u/devops2)\
**Post date:** [July 29, 2024, 11:41am UTC](http://forum.companieshouse.gov.uk/t/http-401-failure-when-querying-the-api-for-company-officers/8163/30 "2024-07-29T11:41:46Z")

</div>

Hi @MArkWilliams, thanks for your continued investigation. Unfortunately, we’re still seeing errors our side, the latest happening @ 2024-07-29 10:36:05,042 BST:

`Failed to query [https://api.company-information.service.gov.uk/company/13360403/filing-history?start_index=0&items_per_page=35]. HTTP Status [401]`

Regards

---

<div class="post-metadata">

**Author:** ![rdinita](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/r/a3d4f5/32.png) [@rdinita](http://forum.companieshouse.gov.uk/u/rdinita)\
**Post date:** [July 30, 2024, 7:45am UTC](http://forum.companieshouse.gov.uk/t/http-401-failure-when-querying-the-api-for-company-officers/8163/31 "2024-07-30T07:45:10Z")

</div>

Hi @MArkWilliams We’ve also seeing this particular issue, but only when attempting to use this endpoint ([Companies House Public Data API: Company profile](https://developer-specs.company-information.service.gov.uk/companies-house-public-data-api/reference/company-profile/company-profile)) - the general search endpoint seems to work fine ([Companies House Public Data API: Search companies](https://developer-specs.company-information.service.gov.uk/companies-house-public-data-api/reference/search/search-companies?v=latest))

We’re getting a 403 Forbidden error on the OPTIONS request and a CORS issue on the preflight (`Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.`).

This is happening when programmatically attempting to fetch data using Javascript. It was fine until recently (although I can’t say exactly the last time this worked, it’s been a while since we’ve attempted to use the direct company profile GET endpoint, mainly relying on the general search one).

---

<div class="post-metadata">

**Author:** ![se.mintesnot.bezabhi](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/s/e9a140/32.png) [@se.mintesnot.bezabhi](http://forum.companieshouse.gov.uk/u/se.mintesnot.bezabhi)\
**Post date:** [July 31, 2024, 7:42am UTC](http://forum.companieshouse.gov.uk/t/http-401-failure-when-querying-the-api-for-company-officers/8163/32 "2024-07-31T07:42:33Z")

</div>

I believe the error, { error: ‘Invalid Authorization header’, type: ‘ch:service’ }, is happening because of the API key encoding. On the companies house dashboard the key is in hex format. When trying to use that key in axios call the url, [https://api.companieshouse.gov.uk/search/companies?q=${searchTerm}](https://api.companieshouse.gov.uk/search/companies?q=%24%7BsearchTerm%7D), have been returning a response with status code 400, Bad request. Inside the response the returned data have the object, {error: ‘Invalid Authorization header’, type: ‘ch:service’ }.

So I have converted the API key to base64 and it start working. Using postman it is possible to get the base64. Use the authorization tab to add Basic Authorization, username - API key and password - blank. Send a get request, then go to Headers tab where you can get the Authorization in base64.

---

<div class="post-metadata">

**Author:** ![t.lloyd](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/t/d6d6ee/32.png) [@t.lloyd](http://forum.companieshouse.gov.uk/u/t.lloyd)\
**Post date:** [August 7, 2024, 1:49pm UTC](http://forum.companieshouse.gov.uk/t/http-401-failure-when-querying-the-api-for-company-officers/8163/33 "2024-08-07T13:49:48Z")

</div>

Hi @MArkWilliams, has there been any update on this issue since the last review?

---

<div class="post-metadata">

**Author:** ![devops2](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/d/f19dbf/32.png) [@devops2](http://forum.companieshouse.gov.uk/u/devops2)\
**Post date:** [August 12, 2024, 4:03pm UTC](http://forum.companieshouse.gov.uk/t/http-401-failure-when-querying-the-api-for-company-officers/8163/34 "2024-08-12T16:03:33Z")

</div>

Hi @MArkWilliams, do you have any update regarding the resolution of this issue please?

Regards

---

<div class="post-metadata">

**Author:** ![george.morriss](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/g/ce7236/32.png) [@george.morriss](http://forum.companieshouse.gov.uk/u/george.morriss)\
**Post date:** [August 15, 2024, 9:10am UTC](http://forum.companieshouse.gov.uk/t/http-401-failure-when-querying-the-api-for-company-officers/8163/35 "2024-08-15T09:10:26Z")

</div>

Hi @MArkWilliams do we have an update on this?

---

<div class="post-metadata">

**Author:** ![devops2](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/d/f19dbf/32.png) [@devops2](http://forum.companieshouse.gov.uk/u/devops2)\
**Post date:** [August 20, 2024, 4:14pm UTC](http://forum.companieshouse.gov.uk/t/http-401-failure-when-querying-the-api-for-company-officers/8163/36 "2024-08-20T16:14:19Z")

</div>

Hi @MArkWilliams, there have not been any updates regarding this issue for 25 days now. Can you please provide an update on this issue. Is this considered resolved on your side or are you still investigating?

Regards

---

<div class="post-metadata">

**Author:** ![MArkWilliams](http://forum.companieshouse.gov.uk/user_avatar/forum.companieshouse.gov.uk/markwilliams/32/194_2.png) [@MArkWilliams](http://forum.companieshouse.gov.uk/u/MArkWilliams)\
**Post date:** [August 29, 2024, 11:41am UTC](http://forum.companieshouse.gov.uk/t/http-401-failure-when-querying-the-api-for-company-officers/8163/37 "2024-08-29T11:41:19Z")

</div>

A fix has gone in for this CORS issue.  
If you are making CORS requests you will need to ensure the api key that you are using has your site in the js\_domains array.

[Previous page](http://forum.companieshouse.gov.uk/t/http-401-failure-when-querying-the-api-for-company-officers/8163.md?page=1)
