API Issue -- Exceed Skip -- ParameterValueOutOfRange

Hello,

I’m developing an application that would collect some data from one of your APIs.

Currently, I’m using the https://api.nhs.uk/service-search/search?api-version=1 endpoint.

I need to take all services from your API, but currently, after page 101 it is impossible because I’ve to use

top” => 1000 and “skip” => 100000

This is the maximum reachable value, but in the array, I saw that there are around 209k services.

[code] => InvalidRequestParameter
[message] => Value must be between 0 and 100000.

Could you please advise me on how could I loop through all services?

On the other hand, I have a specific list with “ServicesOffered” that I’d like to filter by.
But unfortunately, the “filter” param, doesn’t accept my string and array.

I’m using PHP 7.4 and CURL.

This is the current code:

$json_data = array(
    // "filter" => "....",
    "orderby"   =>"OrganisationName",
    "top"   => $posts_per_page,
    "skip"  => $posts_per_page * ( $page - 1 ),
    "count" => true
);

curl_setopt_array($curl, array(
    CURLOPT_URL => $this->API_URL,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => json_encode($json_data),
    CURLOPT_HTTPHEADER => array(
        "cache-control: no-cache",
        "content-type: application/json",
        "subscription-key: " . $this->API_KEY,
    ),
));

Hi Nikolay,
Thanks for getting in touch.

In order to better direct your query, please could you tell us the full name of the API that you are using, as per the API catalogue API catalogue - NHS Digital?

1 Like

Hi,
Thanks for the fast response.

Currently, I’m guided by this documentation: Service Search API - organisations (version 1) - NHS website developer portal

Also, I’ve maybe found a way to just filter the data with the following string:
“ServicesOffered / any (x: x eq ‘Some service’ or x eq ‘Some other service’) or ServicesProvided / any (x: x eq ‘Some service’ or x eq ‘Some other service’)” passed for the “filter” argument.

This might be helpful to be added to the documentation as well if it is the right way, instead of sending a PHP array or a JSON encoded array/object.

Hi Nikolay,
The $skip parameter is locked at 100,000, this is a Microsoft Limit. The notes from Microsoft on ranges beyond that limit are below:

Optional. The number of search results to skip. When called with POST, this parameter is named skip instead of $skip. This value cannot be greater than 100,000. If you need to scan documents in sequence, but cannot use $skip due to this limitation, consider using $orderby on a field that has unique values for every document in the index (like the document key, for example) and $filter with a range query instead.

More information can be found here:

1 Like