API Rate Limit increase

Hi,

There’s a page in the documentation about the rate limit and how users should get in touch if they want to increase it. It would probably be worth adding a contact email address to that page so we don’t have to clog up the forum with requests.

Also, would it be possible for someone to get in touch to discuss the rate limit please?

Thanks,

Dave

Hi,

I was about to ask the same question when I saw this.

Could someone please confirm how users should contact companies house to apply for a rate limit increase?

Cheers

Si

Ditto. I haven’t used my app for a little while (a bit of a stall in the development process) and as I try it now, I find it works fine for the first 85 or so lookups, then fails on a bunch, and then starts working again after presumably the CH server has paused for breath, whereas it used to work fine.

The app is just checking for live updates on CS01 and AA filing deadlines on a hundred or so companies, which is well below the documented rate limit.

As the list of companies grows, I will move towards the rate limit, but in the first instance, need a resolution on the missing responses, please.

What error are you getting?.

…so I get the data back for the first 85 results or so, and then no results for the next (guessing) 30, and then results start coming through again.

There is no error reported per se (at least not that I can see), but there is simply no company object being returned for those 30 results. Maybe there is a way to get additional error reporting, but I have (PHP) errors, warnings and notices all enabled on the test server.

What is strange is that it worked previously, and I have carefully reviewed the code. There’s no way the requests can change between the first and last sets - they’re all within the same loop, which made me wonder whether CH had changed the rate limit.

No rate limit remains as it was 600 requests per 5 minute period. Perhaps we can pick this up in the morning.

So my lookup is: $profile = CompanyProfileSearch($companyNumber, $key);
Results 0-19 were fine (results are all LTD companies)
Results 21-31 were null (results are all LTD companies again)
Result 32 was fine (a LLP)

I added a LTD company to the lookup list and it increased the null results up to 32.
I added a LLP to the lookup list and it added a final successful query (so results 32 and 33 were then fine).

Where I mentioned the 85 lookups in my earlier post, I was referring to the items of data extracted (I’m pulling 4 items out of each profile. Hope that clarifies the disparity in numbers between this post and my previous.

The Notices (for the null lookups) reported are:
Notice: Undefined property: stdClass::$company_name in companiesHouseAPI.php on line 84
Notice: Undefined property: stdClass::$confirmation_statement in companiesHouseAPI.php on line 85
Notice: Trying to get property of non-object in companiesHouseAPI.php on line 85
Notice: Undefined property: stdClass::$confirmation_statement in companiesHouseAPI.php on line 86
Notice: Trying to get property of non-object in companiesHouseAPI.php on line 86
Notice: Undefined property: stdClass::$accounts in companiesHouseAPI.php on line 87
Notice: Trying to get property of non-object in companiesHouseAPI.php on line 87
Notice: Trying to get property of non-object in companiesHouseAPI.php on line 87
Notice: Undefined property: stdClass::$accounts in companiesHouseAPI.php on line 88
Notice: Trying to get property of non-object in companiesHouseAPI.php on line 88
Notice: Trying to get property of non-object in companiesHouseAPI.php on line 88

Just asking as we also use PHP to interact with the API. I’ve seen null properties returned by the API (when they shouldn’t be) and occasionally blank objects but nothing like you’ve described (as yet…). You’ve obviously got some processing going on in your (own?) API-handling code so I’m wondering

  1. What is the REST request you’re making (e.g. what is the url + query string which actually gets sent to CH)?
  2. Are you calling several times e.g. paging through a list using items_per_page and start_index or are all results returned from one request?
  3. What raw JSON data is being returned?
  4. If you were using a library that is generally available, what is it?
  1. I extract the profile as follows:
    $accessURI = “https://api.companieshouse.gov.uk/company/$companyNumber”;
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_USERPWD,$key);
    curl_setopt($curl, CURLOPT_URL, $accessURI);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, ‘GET’);
    $profile = curl_exec($curl);
    curl_close($curl);
    return json_decode($profile);

    $companyName = $profile->company_name;
    $csDueDate = $profile->confirmation_statement->next_due;
    $csMakeUpDate = $profile->confirmation_statement->next_made_up_to;
    $accountsDueDate = $profile->accounts->next_accounts->due_on;
    $accountsMakeUpDate = $profile->accounts->next_accounts->period_end_on;

  2. There is a loop which repeatedly calls to extract $profile, extracts the data and drops it into a temporary table.

  3. Not had chance to test to review the raw JSON

  4. It’s my own library. Not much use at the moment though!

The test would be to dump the following after the curl_exec:

[ 'uri' => $accessURI,
'httpcode' => curl_getinfo ( $curl, CURLINFO_HTTP_CODE ),
'profile' => $profile ]

The httpcode to check if the request was valid - could be that:

  • Company number was invalid - note that company numbers have to be 8 characters, left-padded with ‘0’ if less, and letters in uppercase.
  • Company number didn’t exist in the CH API dataset. Not all companies do (see posts about missing ones / when CH remove ceased companies etc.)

Another possible is that since the function json_decode returns null if it can’t parse the input it could be the decoding. It could be the json returned is incorrect JSON - or at any rate JSON that your PHP’s version of json_decode can’t handle (I’m saying the last because I’ve encountered too many odd behaviours in PHP…BTW which version are you running?).

The errors seem to indicate (if they’re always the same) that json_decode is indeed returning null here (try running ‘null’ and then ‘{ }’ through your code e.g. putting it into json_decode to compare).

See the PHP manual page on the json_last_error() function and particularly the json_last_error_msg() function in case you need to check if these are giving errors (in the comments there’s a script to provide a version if you’re at PHP < 5.5). You could do:

// cast to string just in case, use @ since message can be raised
$profileObj = @json_decode( (string) $profile );
if ( JSON_ERROR_NONE !== json_last_error() ) {
    // throw an error or return 'JSON error: ' . json_last_error_msg();
    ...

A way to simplify a lot of this is using an http library e.g. Guzzle. (Caveat - we don’t on this project but may move to it).

Of course in an ideal world, CH would publish their Swagger spec / OpenAPI spec for the API and you’d be able to run Swagger Codegen to create all the code stubs to handle the basic communication. (In my experience of these it is never that simple of course…)