Search API Results Starting at Incorrect Index

I’ve noticed that some of my searches are returning results starting at an index offset that is different than the offset that I’ve specified with the start_index parameter, for example:

https://api.companieshouse.gov.uk/search/companies?q=jericho&items_per_page=30&start_index=58

That search currently finds 75 total items, so I would have expected the response to start at the 58th item, and return only 17 items. It actually returns results starting at index offset 30 and includes 30 results, which is completely different from what I expected.

I’ve noticed this kind of behavior with other searches too.
Is this a bug, or does it work differently than I expected?

Hi Rob,

This looks like it’s an bug with the API - the start_index works as long as it’s a multiple of the items_per_page. So for example if you used a start_index of 60 it works. Thanks for spotting this - we’ll look to fix this as soon as possible.

Thanks,
Andrew

1 Like

I’m not sure if this is a different manifestation of the same bug or something else but I don’t seem to be able to find any relationship between the start_index and items_per_page parameters and the results returned. In fact I’d say they are both ignored.

Example 1:

https://api.companieshouse.gov.uk/search/companies?q=Auto&start_index=30

JSON results end with:

"start_index":0,"kind":"search#companies","page_number":1,"items_per_page":20}

Example 2 (here using start_index as a multiple of items_per_page):

https://api.companieshouse.gov.uk/search/companies?q=Auto&items_per_page=10&start_index=20

ends with:

"page_number":1,"items_per_page":20,"start_index":0,"total_results":19236,

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

2 Likes