# Searching Using Curl returns only 20 results a Page

**URL:** <http://forum.companieshouse.gov.uk/t/searching-using-curl-returns-only-20-results-a-page/1454>\
**Category:** Uncategorized\
**Created:** [November 9, 2017, 10:08am UTC](http://forum.companieshouse.gov.uk/t/searching-using-curl-returns-only-20-results-a-page/1454 "2017-11-09T10:08:25Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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 9, 2017, 5:01pm UTC](http://forum.companieshouse.gov.uk/t/searching-using-curl-returns-only-20-results-a-page/1454/2 "2017-11-09T17:01:06Z")

</div>

Documentation is at [https://developer.companieshouse.gov.uk/api/docs/search/search.html](https://developer.companieshouse.gov.uk/api/docs/search/search.html)

You need something like (e.g. for “lloyds”):

```
curl -u{APIkey} "https://api.companieshouse.gov.uk/search?q=lloyds&items_per_page=30&start_index=0"

```

You obviously need your own API key - which should end in a colon - instead of {APIkey} here.  
Check the “items\_per\_page” field in the response to ensure you did get back 30 results (or count 'em!).  
To get the next 30:

```
curl -u{APIkey} "https://api.companieshouse.gov.uk/search?q=lloyds&items_per_page=30&start_index=30"

```

You’ll also probably be interested in the “total\_results” field.  
(By the way - if you are just interested in companies or officers, you can limit the search to these by using `/search/companies` or `/search/officers` instead of `/search`).

The general syntax is as per a standard [RESTful API](https://www.sitepoint.com/developers-rest-api/):

```
curl -u{APIKEY} "{restURI}"

```

(Obviously see [curl docs](https://curl.haxx.se/docs/manpage.html) if you e.g. need to get the http header instead etc.)  
Where (to spell it out):

- {APIKEY} is your API username followed by a colon.  
The format used by cURL is actually username:password but CH just give you a username and no password.
- {restURI} - note you’ll want to enclose this in quotes for windows command line / unix shells.  
This is:
- The URI for the appropriate _end point_. The first part is either:  
For main API - `https://api.companieshouse.gov.uk/`  
For Document API - `http://document-api.companieshouse.gov.uk/`  
So for search (all), you want `https://api.companieshouse.gov.uk/search`
- Search takes the following [query parameters](https://en.wikipedia.org/wiki/Query_string):  
search?q=_{term}_&items\_per\_page=_{ipp}_&start\_index=_{start}_
- {term} is the string you’re searching for (obviously, if that includes URI “special characters” like “?”, “&” etc. these need [percent encoding](https://en.wikipedia.org/wiki/Percent-encoding))
- {ipp} is the number of items you want back (note - this doesn’t guarantee you’ll get as many as this).
- {start} is the item in your search results to start with (zero-based I believe).

Many CH endpoints use start\_index and Items\_per\_page to step through potentially large data sets - a quick search on this forum will show you various ways to do this e.g.:

> [@Search API Results Starting at Incorrect Index](http://forum.aws.chdev.org/t/search-api-results-starting-at-incorrect-index/339/4):
>
> I have found that to make it work, as previously mentioned, you have to use a multiple of number of items per page. I maintain a page\_no (starting at 0) and items\_per\_page variables. I calculate the start\_index as page\_no \* items\_per\_page so the 4th standard page has a start\_index of 60 (3 \* 20) This seems to work for me

You’ll also find out about limits in some cases which are not currently documented in the [main documentation](https://developer.companieshouse.gov.uk/api/docs/).

---

_[View the full topic](http://forum.companieshouse.gov.uk/t/searching-using-curl-returns-only-20-results-a-page/1454)._
