Possible bug in PHP Predicates::at('document.type'

I have just started getting this error: regardless of which "page" number I set, the results are always from the first page! I have a client with 900 elements, but only 100 is shown (9 times).

for($page = 0; $page < $totalPages; $page++){
$results = $api->query(
    Predicates::at('document.type', 'track'),['pageSize' => $pageSize, 'page' => ($page+1), 'orderings' => '[document.last_publication_date desc]' ]
);
$totalTracks = count($results->results);

...

Hope you can look at this ASAP, I have a client breathing down my neck.

1 Like

Hi,

Welcome to the Prismic community.
I will try to help you on this, but to investigate further the issue, I would need the repository name that you are calling (in a private message if necessary).

Looking forward to your reply,
Fares

Hello,

Sorry for the delay, I don't know PHP but at a first glance it looks to me that there is an issue in your loop

because result are being overwritten on every iteration

For me, the code should look like this

$results = array();
for($page = 0; $page < $totalPages; $page++){
	$results += $api->query(
	    Predicates::at('document.type', 'track'),['pageSize' => $pageSize, 'page' => ($page+1), 'orderings' => '[document.last_publication_date desc]' ]
	);
}
$totalTracks = count($results->results);

But to debug this further I would need to have access to your code.

Hi, no the code is fine - I just sent you a snippet of it. It used to work, but suddenly it doesn't anymore, so you must have changed something. Regardless it is a fact that the "page" parameter doesn't work anymore, because I always get the results for the first page returned.

I am experiencing the same misbehaviour using the PHP SDK v. 4.0.0. We have several Prismic repos for out clients and I found out, that those different client repos end up in different Prismic API versions.
When the SDK makes the initial call to the Prismic Server, the response's "form.*.action" URL ist broken.

Client A (stripped response):

{
    "experiments": {
        "draft": [],
        "running": []
    },
    "forms": {
        "everything": {
            "action": "https://CLIENT-A.cdn.prismic.io/api/v2/documents/search?",
            "enctype": "application/x-www-form-urlencoded",
            "fields": {},
            "method": "GET"
        }
    },
    "refs": [
        {
            "id": "master",
            "isMasterRef": true,
            "label": "Master",
            "ref": "YGwiHBAAACMA6Jky"
        }
    ],
    "version": "4bbe838"
}

Note the trailing "?" in the URL! The PHP SDK adds a second "?" to the URL:

This results in URLs like https://CLIENT-A.cdn.prismic.io/api/v2/documents/search??page=2&pageSize=20 . If you strip the second "?" from the duplicate "??", the request works just fine.

Another client's response:

{
    "experiments": {
        "draft": [],
        "running": []
    },
    "forms": {
        "everything": {
            "action": "https://CLIENT-B.cdn.prismic.io/api/v2/documents/search",
            "enctype": "application/x-www-form-urlencoded",
            "fields": {},
            "method": "GET"
        }
    },
    "refs": [
        {
            "id": "master",
            "isMasterRef": true,
            "label": "Master",
            "ref": "YGVmHxAAACAA-NYN"
        }
    ],
    "version": "96e5efe"
}

The API Version "96e5efe" works fine (no trailing "?"). "4bbe838" is broken and needs an immediate fix!

For everyone experiencing the same issue on PHP SDK version v.4.0.0: You may use a specific commit from the repo:

This will turn https://CLIENT-A.cdn.prismic.io/api/v2/documents/search??page=2&pageSize=20 into https://CLIENT-A.cdn.prismic.io/api/v2/documents/search?&page=2&pageSize=20 . Not beautiful, but it works. Using Composer you can require the commit as "v.4.0.0" with this line:

"prismic/php-sdk": "dev-release-4.0.0#6588de96e29ce722b35c876b15ead637efb5b337 as v4.0.0",

Hi there,

Thanks for your contribution.

I have been able to reproduce the issue on my end and I have created an issue for it.
We will let you know in case of any updates.

Best,
Fares

As a workaround we can change your API version, until this issue gets fixed.
If you are interested please send me a private message with your repository name.

Hi Thomas,

We have changed the API version for you, can you please check if the problem still exist?