IsraelOrtuno / pipedrive

Complete Pipedrive API client for PHP
MIT License
166 stars 58 forks source link

Add pagination to ListsActivities #90

Closed ampkeegan closed 3 years ago

ampkeegan commented 3 years ago

This by default only returns 100 activities. One can improve to 500 activities by including the ["limit"=> 500] param but it will not paginate through additional resources even if they are available via the API. Can pagination be implemented?

Thanks!

IsraelOrtuno commented 3 years ago

Let me have a look....

IsraelOrtuno commented 3 years ago

Seems like API gets another parameter called start, does it mean current page?

https://developers.pipedrive.com/docs/api/v1/#!/Persons/get_persons_id_activities

ampkeegan commented 3 years ago

Yes, pagination works the same as other requests, like to get all deals. First request would be start=0, limit=500, second request would be start=500, third is start=1000, etc. Check the response for ['additional_data']['pagination']['more_items_in_collection'] = True to continue requesting.

IsraelOrtuno commented 3 years ago

Yeah, not sure if at this point we can implement something like pagination without any breaking changes. Since they do not have a "page" parameter, I'd say the solution would be to watch those response headers and request more manually...

Any idea how to deal with that respecting the current structure?

ampkeegan commented 3 years ago

My php isn't strong enough to understand exactly what's happening in the source, but do the other objects->all() function not paginate? If they do it's the same process.

ampkeegan commented 3 years ago

Looking at the response object from this call:

$acts = (array)$this->pd->persons()->activities($opts, ["limit" => 2])->getContent();

I see this in $acts['additional_data''] :

"pagination":{ "start":0, "limit":2, "more_items_in_collection":true, "next_start":2 }

The second params to listActivities() takes in the start param as well, so I could write a for loop to paginate myself,

$acts = (array)$this->pd->persons()->activities($opts, ["limit" => 2, "start" => 2])->getContent();

IsraelOrtuno commented 3 years ago

As of now, this is the way to go.

Since they do not have a traditional pagination system, this was not taken into account when building this package. Nobody has previously requested this functionality but will consider an implementation of an V3 if becomes an issue in future and simplify the pagination.