# Is there a bug using start\_index parameter?

**URL:** <http://forum.companieshouse.gov.uk/t/is-there-a-bug-using-start-index-parameter/3079>\
**Category:** Uncategorized\
**Created:** [June 6, 2020, 4:32pm UTC](http://forum.companieshouse.gov.uk/t/is-there-a-bug-using-start-index-parameter/3079 "2020-06-06T16:32:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tim\_savigar](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/t/e8c25b/32.png) [@tim\_savigar](http://forum.companieshouse.gov.uk/u/tim_savigar)\
**Post date:** [June 6, 2020, 4:32pm UTC](http://forum.companieshouse.gov.uk/t/is-there-a-bug-using-start-index-parameter/3079/1 "2020-06-06T16:32:59Z")

</div>

The output Json seems to be the same regardless of what is specified in start\_index?  
Happens in API call and via the web

> **[Search companies](https://developer.company-information.service.gov.uk/api/docs/search/companies/companysearch.html)**

---

<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:** [June 8, 2020, 10:33am UTC](http://forum.companieshouse.gov.uk/t/is-there-a-bug-using-start-index-parameter/3079/2 "2020-06-08T10:33:26Z")

</div>

Have you an example? This seems to be working as usual for me. There are a couple of things to note about `start_index` and search in general to watch for but it’s not clear what your issue is.

I’m guessing the most likely one that you have is something like you have to use a multiple of number of `items_per_page` - e.g. if you alter `start_index` the “paging” mechanism seems to expect you to specify both that and `items_per_page`. I believe “start\_index” starts from zero. It seems that one should be a multiple of the other, as demonstrated at the end of the following thread:

[https://forum.aws.chdev.org/t/search-api-results-starting-at-incorrect-index/339](https://forum.aws.chdev.org/t/search-api-results-starting-at-incorrect-index/339)

Otherwise this works for me - just run the following (via curl, setting items\_per\_page to a very low value to show behaviour. I’ve also cropped out most of the detail and rearranged order of fields for clarity):

```
curl -uMY_API_KEY: "https://api.companieshouse.gov.uk/search/companies?q=buy&items_per_page=3&start_index=0"

{
    "total_results": 3658,
    "page_number": 1,
    "items_per_page": 3,
    "kind": "search#companies",
    "start_index": 0,
    "items": [
        {
            "company_number": "03880920",
            "title": "BUY LIMITED"
        },
        {
            "company_number": "11926789",
            "title": "BEAGLE BUTTON LIMITED"
        },
        {
            "company_number": "11511248",
            "title": "BUY A BANGER LTD"
        }
    ]
}

curl -uMY_API_KEY: "https://api.companieshouse.gov.uk/search/companies?q=buy&items_per_page=3&start_index=3"

{
    "start_index": 3,
    "items_per_page": 3,
    "total_results": 3658,
    "kind": "search#companies",
    "page_number": 2,
    "items": [
        {
            "company_number": "12515686",
            "title": "BUY A BANGER LIMITED"
        },
        {
            "company_number": "08828361",
            "title": "BUY A BARCODE LTD"
        },
        {
            "title": "BUY A BARGAIN (U.K) LIMITED",
            "company_number": "11775856"
        }
    ]
 
}

```

For reference - other issues around search and `start_index` / `items_per_page` (I’ve just checked and they’re still current issues):

Bug when setting items\_per\_page to 1:  
[https://forum.aws.chdev.org/t/search-no-items-returned-when-searching-company-number-for-items-per-page-1/2077](https://forum.aws.chdev.org/t/search-no-items-returned-when-searching-company-number-for-items-per-page-1/2077)

Using search you can’t go higher than a certain value of start\_index (this is limited by design)  
[https://forum.aws.chdev.org/t/416-error-when-start-index-900/2338](https://forum.aws.chdev.org/t/416-error-when-start-index-900/2338)

Other “paging” issues:

Filing history returns `start_index` as a string, not number:  
[https://forum.aws.chdev.org/t/start-index-as-a-string-in-filing-history-response/1507](https://forum.aws.chdev.org/t/start-index-as-a-string-in-filing-history-response/1507)

Not quite a bug but an inconsistency - `items_per_page` and `start_index` not returned in chargeList resource:  
[https://forum.aws.chdev.org/t/get-list-of-charges-items-per-page-and-start-index-not-returned-in-chargelist-resource/885](https://forum.aws.chdev.org/t/get-list-of-charges-items-per-page-and-start-index-not-returned-in-chargelist-resource/885)

---

<div class="post-metadata">

**Author:** ![tim\_savigar](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/t/e8c25b/32.png) [@tim\_savigar](http://forum.companieshouse.gov.uk/u/tim_savigar)\
**Post date:** [June 8, 2020, 5:41pm UTC](http://forum.companieshouse.gov.uk/t/is-there-a-bug-using-start-index-parameter/3079/3 "2020-06-08T17:41:38Z")

</div>

I get the issue when doing a search for “Prism”

You can reproduce it at the bottom of the following page

> **[Search companies](https://developer.company-information.service.gov.uk/api/docs/search/companies/companysearch.html)**

GET /search/companies?q=Prism  
GET /search/companies?q=Prism&start\_index=1  
GET /search/companies?q=Prism&start\_index=2

All appear to retrieve the same results

---

<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:** [June 9, 2020, 8:33pm UTC](http://forum.companieshouse.gov.uk/t/is-there-a-bug-using-start-index-parameter/3079/4 "2020-06-09T20:33:14Z")

</div>

Yes, this is the “feature” I mentioned at the top of my post.

> … you have to use a multiple of number of items\_per\_page - e.g. if you alter start\_index the “paging” mechanism seems to expect you to specify both that and items\_per\_page.

Just include a suitable `items_per_page` and make your `start_index` a multiple of that (inc. zero). This is - briefly - [described in documentation](https://developer.companieshouse.gov.uk/api/docs/search/search.html) and more fully elsewhere on this forum.

I’ve no idea why anyone would want a _single item_ at a _specific_ start index if you were just searching. However due to [the other “feature” noted above](https://forum.aws.chdev.org/t/search-no-items-returned-when-searching-company-number-for-items-per-page-1/2077) you can’t get that by doing e.g.:

```
start_index=3&items_per_page=1

```

There is the “paging” mechanism and you have to play along with that. The following would be logical but doesn’t work - “page” is ignored:

```
curl -uMY_API_KEY: "https://api.companieshouse.gov.uk/search/companies?q=Prism&items_per_page=2&page=3"

```

As you’ve said if you don’t include an `items_per_page` Companies House will likely ignore your `start_index` / round it down to the nearest multiple of the `items_per_page` they’ll default to. (For reference the default is currently 20). They might do something else entirely - anyway just specify `items_per_page`. Do check the value of this / number of results in the `items` arrray in case you requested a larger number than they returned.

Using your example - and the lowest limit for `items_per_page` which works - I can pick what I like:

```
curl -uMY_API_KEY: "https://api.companieshouse.gov.uk/search/companies?q=Prism&start_index=2&items_per_page=2"
{
"start_index":2, "items_per_page":2, "page_number":2, "total_results":1018, ...

```

If I wanted more results I’d just keep incrementing start\_index by 2.

In practice we normally try for 20, 50 or even 100 items per page depending on what we’re doing.
