Trouble pulling accounts

Hi

I’ve written a deluge script to pull accounts from CH but I keep getting a response with no filing history even though there is. Any ideas?

The response; { filing_history_status: ‘filing-history-available’ , items: array(0) , items_per_page: 25 , start_index: 0 , total_count: 0 }

Below is the code

void automation.CompaniesHouseAccountsPDF1()
{
company_numbers = list();
company_numbers.add(“1234”);
company_numbers.add(“45678”);
company_numbers.add(“9101112”);
company_numbers.add(“1179939”);
companies_house_api_key = “XXX”;
workdrive_folder_id = “XXX”;
pdf_files = list();
for each company_number in company_numbers
{
url = “https://api.company-information.service.gov.uk/company/” + company_number + “/filing-history”;
headers = Map();
encoded_key = zoho.encryption.base64Encode(companies_house_api_key + “:”);
headers.put(“Authorization”,"Basic " + encoded_key);
response = invokeurl
[
url :url
type :GET
headers:headers
];
info response;
info response.get(“category”);
info response.get(“items”);
if(response != null && response.contains(“items”))
{
for each item in response.get(“items”)
{
if(item.contains(“category”) && item.get(“category”) == “accounts”)
{
document_url = “https://find-and-update.company-information.service.gov.uk/company/” + company_number + “/filing-history/” + item.get(“transaction_id”) + “/document”;
if(item.contains(“description_values”) && item.get(“description_values”).contains(company_number))
{
desc = item.get(“description_values”);
}
file_name = company_number + “.pdf”;
file_content = invokeurl
[
url :document_url
type :GET
headers:headers
];
info file_content;
header = Map();
header.put(“Accept”,“application/vnd.api+json”);
list_of_text = List();
list_of_text.add({“paramName”:“filename”,“content”:file_name,“stringPart”:“true”});
list_of_text.add({“paramName”:“parent_id”,“content”:workdrive_folder_id,“stringPart”:“true”});
list_of_text.add({“paramName”:“override-name-exist”,“content”:“true”,“stringPart”:“true”});
list_of_text.add({“paramName”:“content”,“content”:file_content,“stringPart”:“false”});
response = invokeurl
[
url :“https://www.zohoapis.eu/workdrive/api/v1/upload
type :POST
headers:header
files:list_of_text
connection:“workdrive”
];
info response;
if(response.contains(“data”))
{
uploaded_file_id = response.get(“data”).get(0).get(“id”);
pdf_files.add(uploaded_file_id);
}
if(item.get(“category”) == “accounts”)
{
break;
}
}
}
}
}
}

Not sure why you’re getting a response BUT an empty array for items and total_count zero (unless you have e.g. added a parameter which has filtered out any results - see later on e.g. category parameter). If a company number is found at all I think there would always be at least one filing.

Is the API key you registered for a live application? (Always use the live system, essentially).

The (example) company numbers you’ve got there are invalid as you seem to be doing string concatenation to build your url. Company numbers are always 8 characters long. For standard England/Wales companies the characters are all digits so you need to left-pad those with zeros to give e.g.:
“00001234”, “00045678”
(Other types of entity can start with other characters e.g. “SC” + 6 characters for Scottish companies etc. - and indeed some end with non-digits also. But always 8 characters.)

Next - if you only want items in the category of accounts, you can specify that in the request using the category=accounts parameter. (I do not know how your larguage builds up URL query strings / does URL escaping but you could try just concatenating ?category=accounts to the end of the first URL).

That will save you wading through filings you don’t need and - since the Filing History API is paged - may save you having to call again for more results to get the ones you want. (Note the API is rate limited so if you call too frequently too often you will get warnings then may get blocked. Companies House may not send all the (matching) filings back at once - that’s what the items_per_page: 25 , start_index: 0 , total_count: 0 relate to. By only requesting the category you want you may avoid having to negotiate this completely for some companies.

If you have started out by using the API I recommend continuing to use it rather than reverting to page-scraping to get the documents. The “find-and-update” site may change at time / there are no guarantees here. The API should be more stable and is designed to allow you to do this!

Downloading documents via the API requires a few more steps but gives you a lot more control. Essentially you can “follow the links” in the filing history item e.g. get document metadata to see what formats (mime types) are available, then set your Accept: header appropriately and follow redirects over to their datastore (on AWS currently). See e.g. this thread for more on the topic (and other links from my post):

The Companies House documentation API info is here but I do recommend reading through the steps in posts here also.

(You can use the magnifying glass icon at top right to search this forum for rate limiting, paging and downloading documents to find lots of info on those topics).

Good luck.

Sorry, I put in mock company numbers as I didn’t want to expose real clients.

If you add in the category accounts it still seems to think there are no filings. I am using live not sandbox. I haven’t hit the rate limits either. Its puzzling as it works for some companies (I assume the last submission was accounts and that is why it works here but not on others?)

Without an example or some noboday else can help by checking this of course. As far as I’m aware all companies should have at least one filing *. Not all will have an “accounts” filing though.

Have you tried running this via e.g. the command line curl tool in verbose mode? That way you could see exactly what is being sent - so if this works perhaps e.g. your environment was adding something / parsing of response was going awry?

curl -v -u YOUR_API_KEY: “https://api.company-information.service.gov.uk/company/12345678/filing-history

Example request:

curl -v -u API_KEY_HERE: "https://api.company-information.service.gov.uk/company/05493106/filing-history?items_per_page=3&start_index=0"
*   Trying 13.41.84.44:443...
* Connected to api.company-information.service.gov.uk (13.41.84.44) port 443 (#0)
...
* TLSv1.2 (OUT), TLS header, Unknown (23):
> GET /company/05493106/filing-history?items_per_page=3&start_index=0 HTTP/2
> Host: api.company-information.service.gov.uk
> authorization: Basic QVBJX0tFWV9IRVJFOg==
> user-agent: curl/7.76.1
> accept: */*
>
...
< HTTP/2 200
< date: Thu, 03 Apr 2025 10:51:16 GMT
< content-type: application/json
< access-control-allow-credentials: true
< access-control-allow-headers: X-RateLimit-Query, origin, content-type, content-length, user-agent, host, accept, authorization
...
<
{"filing_history_status":"filing-history-available","items":[{"transaction_id":"MzI4MjgxOTI4OGFkaXF6a2N4","type":"GAZ2","date":"2020-11-17","category":"gazette","description":"gazette-dissolved-compulsory","pages":1,"paper_filed":true,"links":{"self":"/company/05493106/filing-history/MzI4MjgxOTI4OGFkaXF6a2N4","document_metadata":"https://document-api.company-information.service.gov.uk/document/OnRdepPdB192xOqJl1si4BNuf0FybxFZdR8a_84Yz9g"}},{"transaction_id":"MzI1MTQ1NDI4N2FkaXF6a2N4","type":"DISS16(SOAS)","date":"2019-12-07","category":"dissolution","description":"dissolved-compulsory-strike-off-suspended","pages":1,"paper_filed":true,"links":{"self":"/company/05493106/filing-history/MzI1MTQ1NDI4N2FkaXF6a2N4","document_metadata":"https://document-api.company-information.service.gov.uk/document/vYu1t5YzV3cyXi4xH0LS47oIiEoUdNPGVl54bduIeZY"}},{"transaction_id":"MzI0NzkwMTk4OWFkaXF6a2N4","type":"GAZ1","date":"2019-11-05","category":"gazette","description":"gazette-notice-compulsory","pages":1,"paper_filed":true,"links":{"self":"/company/05493106/filing-history/MzI0NzkwMTk4OWFkaXF6a2N4","document_metadata":"https://document-api.company-information.service.gov.uk/document/wXWquo8gTZjI9Y-JKyoE1wHhrCiaMs54ZKMOpqg1jTQ"}}],"items_per_page":3,"start_index":0,"total_count":37}
  • “Normal” companies - some entities which Companies House lists do not file / Companies House only maintains partial data etc.