helpscout / helpscout-api-php

PHP Wrapper for the Help Scout API
MIT License
98 stars 62 forks source link

Pagination only returns page 1 and 2 #290

Closed nickstonervivo closed 2 years ago

nickstonervivo commented 2 years ago

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.

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);
bkuhl commented 2 years ago

đź‘‹ 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.

nickstonervivo commented 2 years ago

Your suggestion fixed my issue. Thank you!