Seacrh companies

Hey all,

I’m trying to do a fetch request to return some companies but I can’t seem to get it to work. Can someone let me know the correct syntax and what I am doing wrong. I have my headers set up correctly and my Api key is working as I can return the 1 company in the example they give in the documentation.

I am using https://api.company-information.service.gov.uk/search/companies as the Url and the query parameter of ?items_per_page=5

I get a response with 0 items.

Can anyone help?

You didn’t mention you were passing in any term to search for. If you check the Search Companies documentation you’ll see that that’s a q parameter. So (in curl) you’d have (I’ve edited this just to show one entry):

curl -u MY_API_KEY_HERE: "https://api.company-information.service.gov.uk/search/companies?q=asda&items_per_page=4&start_index=0"

Returning:

{
    "total_results": 121,
    "items": [
        {
            "kind": "searchresults#company",
            "description": "14217167 - Incorporated on  5 July 2022",
            "company_status": "active",
            "links": { "self": "/company/14217167" },
            "snippet": "",
            "address_snippet": "173 St. Dunstans Hill, Cheam, Sutton, England, SM1 2LR",
            "address": {
                "address_line_1": "St. Dunstans Hill",
                "postal_code": "SM1 2LR",
                "premises": "173",
                "address_line_2": "Cheam",
                "country": "England",
                "locality": "Sutton"
            },
            "company_type": "ltd",
            "matches": {
                "title": [ 1, 4 ],
                "snippet": [ ]
            },
            "company_number": "14217167",
            "title": "ASDA LIMITED",
            "description_identifier": [ "incorporated-on" ],
            "date_of_creation": "2022-07-05"
        },
        ... (another 3 company objects)
    ],
    "kind": "search#companies",
    "page_number": 1,
    "items_per_page": 4,
    "start_index": 0
}

It makes sense to pass both items_per_page and start_index - note that start_index is zero-based.

Using javascript fetch it may be convenient to use the URLSearchParams object to format the URL parameters for you:

const url = "https://api.company-information.service.gov.uk/search/companies?" + ( new UrlSearchParams( {q: "asda", "items_per_page": "4", "start_index": "0" } ) ).toString();

Thank you so much. I was confused by the q=.

Is there a way to search for a number of random companies? Or does it have to be a particular search term?

Not sure what you want to do?

If you want data on a single company then e.g. use the Company Profile endpoint and pass in the exact company number.

If you want to find a company by name (or part of the name), use Search Companies. This is a “fuzzy” search so there are no wildcards. Think of it like a Google / other search engine search. Companies House have an algorithm to try to find the most appropriate matches. Even if you pass in the whole name you will probably get multiple matches - see e.g:

If you want to look across a range of names alphabetically then use the alphabetical search endpoint. (I have not used this one myself, I don’t understand it).

For more control over a search, use the Advanced Search.

However you are thinking of searching, if you want to collect a large quantity of data / search a substantial fraction of companies, then Companies House have stated that the API is not the way to do that. In that case download one of the bulk data products. A 3rd party info page is available.