Search - no items returned when searching company number for items_per_page=1

If you search for a company number (using /search or /search/companies) but set items_per_page to 1 the items field is blank.

Using curl:

curl -uAPIKEY: “https://api.companieshouse.gov.uk/search/companies?q=SC294759&items_per_page=1

{ “items_per_page”:1, “page_number”:2, “items”:[], “kind”:“search#companies”, “start_index”:1, “total_results”:1 }

page_number also incorrectly shows 2.

However if items_per_page is changed to 2 - it shows data (and page_number is correctly 1):

curl -uAPIKEY: “https://api.companieshouse.gov.uk/search?q=SC229764&items_per_page=2

{“items”: [ {“company_number”:“SC229764”, “address”:{“locality”:“Perthshire”, “postal_code”:“PH2 8HR”, “address_line_1”:“King Street”, “premises”:“7 “, “address_line_2”:“Perth”}, “links”:{“self”:”/company/SC229764”},“kind”:“searchresults#company”, “date_of_creation”:“2002-03-28”, “description_identifier”:[“incorporated-on”],“description”:“SC229764 - Incorporated on 28 March 2002”,“address_snippet”:“7 King Street, Perth, Perthshire, PH2 8HR”,“title”:“KIRKLANDS BUSINESS SOLUTIONS LIMITED”,“company_type”:“ltd”,“company_status”:“active”}],“total_results”:1,“start_index”:0,“page_number”:1,“items_per_page”:2,“kind”:“search#all”}

Setting start_index to 0 won’t help:

curl -uAPIKEY: “https://api.companieshouse.gov.uk/search?q=SC229764&items_per_page=1&start_index=0

{“items_per_page”:1, “total_results”:1, “items”:[], “start_index”:1,“page_number”:2, “kind”:“search#all”}

If you don’t specify items_per_page all works correctly as the defaults are applied e.g. items_per_page=20

curl -uAPIKEY: “https://api.companieshouse.gov.uk/search?q=SC229764
{“items_per_page”:20,“total_results”:1,“kind”:“search#all”,“start_index”:0,“page_number”:1,“items”:[

{“title”:“KIRKLANDS BUSINESS SOLUTIONS LIMITED”,“description_identifier”:[“incorporated-on”],“description”:“SC229764 - Incorporated on 28 March 2002”,“links”:{“self”:"/company/SC229764"},“address_snippet”:“7 King Street, Perth, Perthshire, PH2 8HR”,“kind”:“searchresults#company”,“company_type”:“ltd”,“company_status”:“active”,“address”:{“postal_code”:“PH2 8HR”,“premises”:"7 ",“locality”:“Perthshire”,“address_line_2”:“Perth”,“address_line_1”:“King Street”},“company_number”:“SC229764”,“date_of_creation”:“2002-03-28”}
]}

If you search on a name however, items_per_page can be 1:

curl -uAPIKEY: “https://api.companieshouse.gov.uk/search/companies?q=kirklands&items_per_page=1

{“kind”:“search#companies”,“items”:[{“date_of_creation”:“2002-03-28”,“company_number”:“SC229764”,“address”:{“premises”:“7 “,“locality”:“Perthshire”,“postal_code”:“PH2 8HR”,“address_line_1”:“King Street”,“address_line_2”:“Perth”},“title”:“KIRKLANDS BUSINESS SOLUTIONS LIMITED”,“snippet”:””,“company_type”:“ltd”,“links”:{“self”:"/company/SC229764"},“description”:“SC229764 - Incorporated on 28 March 2002”,“company_status”:“active”,“matches”:{“snippet”:[],“title”:[1,9]},“address_snippet”:“7 King Street, Perth, Perthshire, PH2 8HR”,“kind”:“searchresults#company”,“description_identifier”:[“incorporated-on”]}],“start_index”:1,“page_number”:2,“total_results”:30,“items_per_page”:1}

…although page_number is still 2.

Order of URL parameters or including start_index doesn’t seem to have any effect.

curl -uAPIKEY: “https://api.companieshouse.gov.uk/search?q=SC229764&items_per_page=1&start_index=1

{“page_number”:2,“items_per_page”:1,“total_results”:1,“kind”:“search#all”,“start_index”:1,“items”:[]}

The code here must have changed as the behaviour’s changed but it’s still not quite right!

If you call the search end-point and specify items_per_page as 1 and don’t specify a start_index, the second result in the list is returned. This seems to happen because start_index is incorrectly being set to 1 when you specify items_per_page as 1. For other values of items_per_page (or if you don’t specify it at all) start_index is set to zero (which is where it should start).

Example (the “normal” order can be seen by performing the search in CH Beta e.g. https://beta.companieshouse.gov.uk/search/companies?q=Wiselan%20Ltd):

First:
items_per_page = 1
Note: the entry returned is WISELAND LIMITED (09990271). In the returned object start_index is given as 1, and page_number as 2.

curl -u%APIKEY%: “https://api.companieshouse.gov.uk/search/companies?q=WISELAN%20LTD&items_per_page=1

{
“kind”: “search#companies”,
“total_results”: 4,
"page_number": 2,
"start_index": 1,
“items_per_page”: 1,
“items”: [ {
“date_of_creation”: “2016-02-05”,
“address”: { … },
“title”: “WISELAND LIMITED”,
“company_number”: “09990271”,
“matches”: { … },
“address_snippet”: …,
“links”: { … },
“company_type”: “ltd”,
“kind”: “searchresults#company”,
“description”: “09990271 - Incorporated on 5 February 2016”,
“company_status”: “active”,
“description_identifier”: [ “incorporated-on” ],
“snippet”: “”
} ]
}

How it should work:
items_per_page = 3. Note the top entry = WISELAN LIMITED (03765830) - the correct “top” entry. In the return start_index = 0 and page_number = 1 as expected.

curl -u%APIKEY%: “https://api.companieshouse.gov.uk/search/companies?q=WISELAN%20LTD&items_per_page=3

{
“kind”: “search#companies”,
“items_per_page”: 3,
“total_results”: 4,
“items”:
[
{
"company_number": “03765830”,
"title": “WISELAN LIMITED”,

},
{
“company_number”: “09990271”,
“title”: “WISELAND LIMITED”,

},
{
“title”: “WISELAND CONSTRUCTION LIMITED”,
“company_number”: “03259344”,

}
],
"start_index": 0,
"page_number": 1
}

Going down one- items_per_page = 2 - gives the same order as above (e.g. without “WISELAND CONSTRUCTION LIMITED”) and the start_index is 0 still.

Trying to force the issue by deliberately setting both items_per_page = 1 and start_index = 0 doesn’t help:

curl -u%APIKEY%: “https://api.companieshouse.gov.uk/search/companies?q=WISELAN%20LTD&items_per_page=1&start_index=0

{
“page_number”: 2,
“kind”: “search#companies”,
“items_per_page”: 1,
“total_results”: 4,
“items”: [
{
“title”: “WISELAND LIMITED”,
“company_number”: “09990271”,
“company_type”: “ltd”,

}],
“start_index”: 1
}