Home > Software design >  How to display all data from Invision Power board Rest API
How to display all data from Invision Power board Rest API

Time:12-28

I am looking to display all data but my result is only the first 25 for page 1: I want to extract all the download file name for example

what would be the best way to get all the data

<?php
$communityUrl = 'https://www.example.com/ips4/';
$apiKey = 'c7a349a1629f02cd2855a58d77646f6d';
$endpoint = '/downloads/files';
$endpoint = '/core/members';

$curl = curl_init( $communityUrl . 'api' . $endpoint );
curl_setopt_array( $curl, array(
    CURLOPT_RETURNTRANSFER  => TRUE,
    CURLOPT_HTTPAUTH    => CURLAUTH_BASIC,
    CURLOPT_USERPWD     => "{$apiKey}:"
) );
$response = curl_exec( $curl );
?>

My php code

<?php
$result_files = json_decode($response , true);

if (is_array($result_files)) {
  foreach ($result_files as $value) {
    if (is_array($value)) {
       foreach ($value as $info) {
          echo $info['title'];
      }
   }
}
?>

The code above display only 25 files. I have 150. How to do that ?

Thank you

CodePudding user response:

Have you looked the rest download document, there are page that defaults to 25 files, you have to send call to fetch 150 files per page. Use the perPages atripute to declare amount per page.

page    int     Page number
perPage     int     Number of results per page - defaults to 25

After looking rest commands here id put perPage = 150 to collect 150 files in 1 call. Try this:

$endpoint = '/downloads/files/{perPage=150}';

or

$endpoint = '/downloads/files?perPage=150'

One or another way will work to get 150 results.

Here is dynamic version if you will later first get dynamically how many files there is and then fetch that result files amount:

$endpoint = '/downloads/files?perPage='.$amount
  • Related