helpscout / helpscout-api-php

PHP Wrapper for the Help Scout API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pagination only returns page 1 and 2

nickstonervivo opened this issue · comments

Thank you for taking the time to submit an issue with all the details shown below. Our engineering team monitors issues submitted and strives to respond with 1-2 business days.

  • PHP version: 7.4
  • SDK version: 3.6.3

Current behavior

prints 2 pages of conversation results then stops
Expected behavior

print all pages of conversation results
Steps to reproduce

$filter = (new ConversationFilters())->inStatus('all');

$conversations = $client->conversations()->list($filter);
do{
        foreach ($conversations as $conversation) {
                $conversationId = $conversation->getId();
                $conversationType = $conversation->getType();
                echo $conversationId. " ".$conversationType ."</br></br>";
                
        }
        $totalPages = $conversations->getTotalPageCount();
        $currentPage = $conversations->getPageNumber();
        echo "Current Page: ".$currentPage." Total Pages: ".$totalPages;
$conversations = $client->conversations()->list($filter)->getNextPage();
}while($currentPage<=$totalPages);

👋 Hey! I think the code you provided will show the same page 1 results over and over. This will perform a raw search again from page 1, but jump to page 2:

// Performs a fresh search, providing page 1 of results
$conversations = $client->conversations()->list($filter)
    // Jumps to page 2 of the results
    ->getNextPage();

Whereas replacing that with this will actually iterate to the next page:

$conversations = $conversations->getNextPage();

Try changing that and see how it helps. If there are still issues you need help with, providing more information here such as the output of the code you provided would be helpful.

Your suggestion fixed my issue. Thank you!