0

I am trying to get more than 20 images with the searches endpoint:

$data = '{
                    "query": {
                      "ands": [
                        {
                          "output": {
                            "input": {
                              "data": {
                                "image": {
                                  "url": "' . $url . '"
                                }
                              }
                            }
                          }
                        }
                      ]
                    }
                  }';


$ch = curl_init('https://api.clarifai.com/v2/searches? 
page=1&per_page=30');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        "Authorization: Key " . self::$clarify_user_apikey,
        "Content-Type: application/json")
);
$output = curl_exec($ch);
curl_close($ch);

The images are initialized above in the $data variable.

Does the image search not have pagination and per_page attributes, or what am I doing wrong?

However I change the two attributes, I always get a max of 20 images back. The App / Project in question has more than 70k images, and the explorer app shows more images as well.

Thanks!

ljungi
  • 21
  • 1
  • 7
  • https://clarifai.com/developer/guide/#pagination ? Have you tried setting `per_page` as POST instead of GET? – brombeer Sep 07 '18 at 07:30
  • Hey, thanks for getting back. Where exactly would I add it, as the data code is in json format. Adding it in the first { part makes the query invalid. – ljungi Sep 10 '18 at 03:25
  • I recommend using the [official Clarifai PHP client](https://github.com/Clarifai/clarifai-php) instead of JSON/REST. – Rok Povsic Dec 12 '18 at 07:33

1 Answers1

0

I found the answer. For easier understanding I formatted the JSON part into an array.

$data = array(
        "query" => array(
            "ands" => array(
                array(
                    "output" => array(
                        "input" => array(
                            "data" => array(
                                "image" => array(
                                    "url" => $url
                                )
                            )
                        )
                    )
                )
            )
        ),
        "pagination" => array(
            "page" => 1,
            "per_page" => 100
        ),
    );

This code gives 100 images back. I haven't seen an upper limit yet, but it seems to work fine with 500 images as well. The request call gets slow then, though.

ljungi
  • 21
  • 1
  • 7