# Search - no items returned when searching company number for items\_per\_page=1

**URL:** <http://forum.companieshouse.gov.uk/t/search-no-items-returned-when-searching-company-number-for-items-per-page-1/2077>\
**Category:** API Issues\
**Created:** [November 16, 2018, 1:55pm UTC](http://forum.companieshouse.gov.uk/t/search-no-items-returned-when-searching-company-number-for-items-per-page-1/2077 "2018-11-16T13:55:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![voracityemail](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/v/b77776/32.png) [@voracityemail](http://forum.companieshouse.gov.uk/u/voracityemail)\
**Post date:** [November 16, 2018, 1:55pm UTC](http://forum.companieshouse.gov.uk/t/search-no-items-returned-when-searching-company-number-for-items-per-page-1/2077/1 "2018-11-16T13:55:02Z")

</div>

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](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](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](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](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](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](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”:}

---

<div class="post-metadata">

**Author:** ![voracityemail](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/v/b77776/32.png) [@voracityemail](http://forum.companieshouse.gov.uk/u/voracityemail)\
**Post date:** [January 7, 2019, 6:52pm UTC](http://forum.companieshouse.gov.uk/t/search-no-items-returned-when-searching-company-number-for-items-per-page-1/2077/2 "2019-01-07T18:52:30Z")

</div>

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](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](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](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](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  
}
