helpscout / helpscout-api-php

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

Expected a value greater than 0. Got: 0 #258

Closed arbind-ladybird closed 3 years ago

arbind-ladybird commented 3 years ago

when trying to get next page via $records = $records->getNextPage(); getting error like Expected a value greater than 0. Got: 0
Can anyone suggest me why I'm getting this error.

shaunmcilroy commented 3 years ago

Thanks for reaching out @arbind-ladybird -- we'll pass along this note to our engineers to investigate and get you a response when our team return from the Thanksgiving break from 11/30 onwards.

bkuhl commented 3 years ago

Hey @arbind-ladybird,

getNextPage() actually loads the next page of results using data provided by the last request. It seems like for this error to happen, there must be a scenario where the public API is providing a 0 for the next page value. Can you share the values of the output of $records->getTotalPageCount(); and $records->getPageNumber(); when this error is encountered?

arbind-ladybird commented 3 years ago

This is happening because for createdBy you are directly passing

if(isset($data['createdBy'])){ $this->hydrateCreatedBy($data['createdBy']); }

But for some users/customer we are getting id having value 0. But there is a condition in assert that value can't be 0 it should be greater than 0. As you have putted condition for closed by user like

if (isset($data['closedBy']) && $data['closedBy'] > 0) { $user = new User(); $user->setId((int) $data['closedBy']); $this->setClosedBy($user); }

So to handle this I have modified two file conversation.php and Thread.php like this

if (isset($data['createdBy']) && $data['createdBy']['id'] > 0) { $this->hydrateCreatedBy($data['createdBy']); }

bkuhl commented 3 years ago

A fix is now available for this scenario in in v3.3.1

arbind-ladybird commented 3 years ago

okay

On Wed, Jan 27, 2021 at 1:44 AM Ben Kuhl notifications@github.com wrote:

A fix is now available for this scenario in https://github.com/helpscout/helpscout-api-php/releases/tag/3.3.1

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/helpscout/helpscout-api-php/issues/258#issuecomment-767800095, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARD3GQIWLPXDB4P2HKAOM6LS34PDLANCNFSM4UCBJV5Q .