helpscout / helpscout-api-php

PHP Wrapper for the Help Scout API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue when calling getPage on conversations.

IronicTrout 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: 8.0.25
  • SDK version: 3.2.0

Current behavior
Gets the same page (first page only?)

Expected behavior
Gets the correct page

$filters = (new \HelpScout\Api\Conversations\ConversationFilters())        
            ->inStatus('all')
            ->sortField('createdAt')
            ->sortOrder('asc')
            ->withQuery($query);
       
        // Get conversations with the filter
        $conversations = $helpscout_client->conversations()->list($filters);
        
        // If a specific page is being fetched, get it
        $total_pages = $conversations->getTotalPageCount();
        if (is_numeric($page) && $page >= 1 && $page <= $total_pages) {

            $conversations->getPage($page);
        }
        
        $conversations = $conversations->toArray();

I'm running the following code and it always seems to be fetching the same page of conversations and I'm not sure why. I know that $page is coming into the function correctly but it always seems to be fetching the same 25 results. Any help would be much appreciated!

Hey @IronicTrout!

I think your problem is you are calling $conversations->getPage($page);, but you're not assigning the result to the variable, so when you call $conversations->toArray(); at the end, $conversations still contains the first page.

You should do this instead:

$conversations = $conversations->getPage($page);

Like this, getPage($page) returns a new instance of PagedCollection containing the page you requested, and you replace the current value of the $conversations variable with that new instance.

Ah what a bone-head mistake. Thank you for your help!