Non-existing company number returns 500

Greetings!

Documentation for /company/{companyNumber} suggests that if non-existing company number is provided, API should return 404 instead of 500. Is this new/known issue?

e.g:
Request:
curl --location ‘https://api.company-information.service.gov.uk/company/07495895333
–header ‘Authorization: ••••••’

500 response:
{
“exception_id”: “x9e4yrfrf5j5”,
“error”: “Internal server error”
}

Probably shouldn’t give a 500 - that suggests an oversight in Companies House code.

For what it’s worth that’s not simply a “non-existent” company, it’s a completely invalid number. All things in their registry have an 8 character “number”. Presumably somewhere in their software has that as an assumption?

Playing around here, there are at least 3 cases. Feeding these in to the “company profile” endpoint e.g. with curl -I -X GET -u API_KEY_HERE: "https://api.company-information.service.gov.uk/company/NF004299"

Valid company number: NF004299 - this gives a 200 response and the expected JSON body.

Non-existent (but not completely invalid) company number: 99999999
This gives a 404 and the error body:

{
    "errors": [
        {
            "type": "ch:service",
            "error": "company-profile-not-found"
        }
    ]
}

Invalid CH number (one extra character): 999999999

As you say this gives a 500 and the body:

{
      "exception_id": "6wm4ym5vfxu3",
      "error": "Internal server error"
}
1 Like

Presumably the “fix” is on the user-side - simply parse anything we want to request from Companies House. For the moment, if it’s not exactly 8 characters - don’t send it! If you get a 404 back, the number didn’t exist.

If you want to e.g. regexp these then:

a) In the specifications (the XML Gateway Schemas) CH define this as [A-Z0-9]{8,8} - although that is wider than what is found in the data so that is probably “for simplicity” / “future expansion”.

There is some (old) official documentation on the number format referenced in this query:

https://forum.aws.chdev.org/t/valid-company-number-format/713

That is 2016 so now both missing some new entities and also there are some entries on there which no longer get created.

The ones added after that date are (not totally sure if this is comprehensive):

SG - Scottish Qualifying Partnership
RS - Registered Society
PC - Protected Cell Company
CE - Charitable incorporated organisation
CS - Scottish charitable incorporated organisation
FE - Further Education or 6th form college
OE - Overseas Entity

Hope this helps.

Adding a vote for a fix for this as well. 422 might be a better response if CH want to enforce a specific input format.

1 Like

We’ve been seeing this behaviour since around 8:10am on Saturday 14th September. Was a release rolled at that time? Was this a deliberate change of behaviour?

Thank you for the input! It indeed does return 404 if non-existent 8 character number is provided instead of 500. Probably this should be mentioned somewhere in the docs to avoid some confusion. Will workaround this for now.

@MArkWilliams do you have any insight into this?