Skip to content

fix(api): add missing pagination fields and fix broken auto-pagination - #81

Closed
sudiptpa wants to merge 1 commit into
sentdm:mainfrom
sudiptpa:fix-pagination-missing-fields
Closed

sudiptpa wants to merge 1 commit into
sentdm:mainfrom
sudiptpa:fix-pagination-missing-fields

Conversation

@sudiptpa

@sudiptpa sudiptpa commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What's wrong

Three bugs in the same ten lines of code, found while fixing the first one.

1. Pagination fields missing (issue #47). All 7 *Page/Data/Pagination.php classes
(Contacts, Templates, Webhooks, WebhookEvents, Conversations, Calls, VoiceAgents) declare
only has_more. Reading ->page, ->pageSize, ->totalCount, ->totalPages throws, even
though the API has always returned all of them. Confirmed against a fresh pull of
api.sent.dm/swagger/v3/swagger.json: all 7 resolve to the same SharedPaginationMeta
schema that CallsList and 5 other sibling response types already use correctly.

2. has_more itself never hydrates, so hasNextPage() always returns false.
*Page::__construct() calls __unserialize() directly on raw wire JSON, skipping the
normal name-translation path every other model goes through. List items (contacts,
calls, etc.) escape this because they're typed mixed and get manually re-coerced right
after, a workaround already in every one of these files. Nobody added that same fix for
pagination, so has_more silently fails to translate, and nextRequest()'s ??
swallows the resulting error:

if (!($this->data->pagination->hasMore ?? null) || !count($this->getItems())) {
    return null;
}

3. The next request never advances the page.

$nextRequest = array_merge_recursive($this->requestInfo, ['query' => $curr + 1]);

merges a scalar against an array under the same key. array_merge_recursive appends
instead of overwriting, so page stays 1 forever:

php -r '
$requestInfo = ["query" => ["page" => 1, "pageSize" => 1]];
var_export(array_merge_recursive($requestInfo, ["query" => 2]));
'
→ query => ['page' => 1, 'pageSize' => 1, 0 => 2]

Fixing that directly surfaces a fourth detail: requestInfo['path'] is the fully resolved
URI, query string included. Util::joinUri() re-parses that embedded query and merges it
with the new one, so the stale page=1 survives next to the new page=2 unless the query
string is stripped off path first.

Checked the other SDKs

  • Same bug: Python, TypeScript, Go, Ruby all have the identical has_more-only shape.
  • Already correct: Java, C#, and Rust all type this field as the shared PaginationMeta.

Checked the commit history too: PHP, Java, and C# each got a commit with the identical
message, feat(api): configure page_number pagination for the v3 list endpoints, from the
same generator pipeline, same day. Java and C# generated the full PaginationMeta from
that commit. PHP generated the has_more-only stub. Same spec, same rollout, different
output per language. This PR is PHP catching up to where its siblings already landed.

Bugs 2 and 3 are PHP-specific plumbing, not checked against the other SDKs.

What changed

For each of the 7 resources:

  • *Page/Data.php now types pagination as SentDm\Webhooks\PaginationMeta. The 7 stale
    Pagination.php files are deleted.
  • *Page.php's constructor gets the same second-pass re-coercion for pagination that
    list items already get.
  • nextRequest() sets $nextRequest['query']['page'] directly instead of the broken
    merge, and strips the stale query string off path first.

Before:

$page->hasNextPage();              // always false, even with more pages
$page->data->pagination->page;     // throws

After:

$page->hasNextPage();              // true, when the API says so
$page->getNextPage();              // requests page 2, not page 1 again
$page->data->pagination->page;     // 1

Compatibility

Removes the 7 public Pagination classes outright rather than keeping deprecated aliases.
Each one exposed exactly one field that never hydrated anyway, so there was nothing working
to depend on. Matches the Java fix for the same bug: that SDK's old class was renamed and
replaced outright in the same commit, no alias kept.

How I verified it

Added tests/PaginationFieldsTest.php: one hydration test per resource, plus a real
two-page test for contacts that mocks page 1 and page 2, calls getNextPage(), and asserts
the second HTTP request actually carries page=2.

./scripts/lint and ./scripts/test both pass locally, full existing suite included.

The 7 *Page/Data/Pagination.php classes (Contacts, Templates, Webhooks,
WebhookEvents, Conversations, Calls, VoiceAgents) only declared hasMore,
so reading ->page, ->pageSize, ->totalCount, or ->totalPages threw, even
though the API has always returned all of them (issue sentdm#47).

Fixing that surfaced two deeper bugs in the same auto-pagination path.
hasMore itself never hydrated either, because *Page::__construct() calls
__unserialize() directly on raw wire JSON, bypassing the normal name
translation every other model goes through. nextRequest() also never
advanced the page number: array_merge_recursive() on a scalar against an
array appends rather than overwrites, and once that's fixed, the stale
query string baked into the reused request path collides with the new one
unless stripped first.

Repoints each *Page/Data.php at the existing SentDm\Webhooks\PaginationMeta
type (already used correctly by CallsList and five other sibling response
types), extends the second-pass re-coercion workaround list items already
get to cover pagination too, and fixes nextRequest()'s page increment and
stale query string.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T18:30:35.065022Z 0a60e5d Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@sudiptpa

sudiptpa commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 0a60e5dfb7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@arbianst

arbianst commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Thanks, this is a thorough one, and all three findings check out. Here's how we're taking them, because the fixes belong upstream of this repository:

  • The missing fields. The SDK generator's config declared only has_more on the pagination object for every page type, which is why PHP, Python, TypeScript, Go and Ruby all lack page, pageSize, totalCount and totalPages. That's corrected in the config; the next generated release of each of those SDKs carries the four fields.
  • hasNextPage() always false, and the next request never advancing. Both are bugs in the generator's PHP page template: hydration without name translation, and the bare integer merged under query. We've filed them against the generator with your reproduction, so one regeneration fixes all seven page classes at once instead of carrying hand edits that the next regeneration would fight.

I'll leave this PR open as the reference until those land, then close it in favour of the generated fix. Your two-page test is exactly the regression test the template needs, and the generator issue points at it.

@arbianst

arbianst commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Follow-up: the two page bugs are going in now as #83, a narrower version of your change that touches only the seven page classes (the constructor's second pass for pagination, and nextRequest() setting query.page on a path without its query string). You're credited as co-author there, and its test is built on yours. The four fields stay out of it on purpose, they arrive on the generated Pagination classes from the generator's side, so no public class is removed. Once #83 and that release are out, I'll close this one.

@arbianst

arbianst commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Closing now that both halves have shipped from the right places: 0.44.1 fixed hasNextPage() and the next-page request (#83, co-authored with you), and 0.45.0 adds page, pageSize, totalCount and totalPages on every Pagination model, generated from the API's shared pagination schema. Python, TypeScript, Go and Ruby got the same fields in their releases today. Thank you for the diagnosis and the two-page test, which is now the regression test in this repository.

@arbianst arbianst closed this Nov 4, 2026
@sudiptpa
sudiptpa deleted the fix-pagination-missing-fields branch November 4, 2026 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants