Skip to content

Fix Brevo list_modules pagination to return all lists#192

Merged
davidperezgar merged 5 commits into
trunkfrom
select-model-crm
May 13, 2026
Merged

Fix Brevo list_modules pagination to return all lists#192
davidperezgar merged 5 commits into
trunkfrom
select-model-crm

Conversation

@matiasqueroceballos
Copy link
Copy Markdown
Contributor

Problem
The fc_crm_module dropdown in Contact Form 7 (and other form plugins) only displayed 10 lists from Brevo, even though the account had 87 lists. The API response showed count: 87, confirming all lists existed but weren't being fetched.

Root Cause
The api() method in CRMLIB_Brevo had three chained bugs in its GET pagination logic:

Missing URL parameters: Query string params ?limit=N&offset=N were commented out, so every API request hit the same endpoint without pagination parameters. Brevo defaults to 10 items when no limit is specified.

Loop never repeats: The repeat_query condition compared count($result['data']) (which was 10) against a hardcoded $limit of 100, causing the loop to exit after one iteration.

Broken data accumulation: The method tried to merge entire response envelopes ({lists: [...], count: 87}) instead of just the nested items array, then list_modules() looked for ['data']['lists'] in a structure that no longer had that nesting.

Solution
Modified /includes/crm-library/class-crmlib-brevo.php:

In api() GET block:

Append ?limit=50&offset=N to the URL for each request
Extract nested items ($result['data']['lists']) from the response, or fall back to $result['data'] if not nested
Accumulate only items (not envelopes) in $result_data
Use $offset < $total to control pagination loop continuation
In list_modules():

Read $result_lists['data'] directly as a flat array (changed from $result_lists['data']['lists'])
Impact
✅ Dropdown now displays all 87 lists instead of 10
✅ Backwards compatible: Other Brevo endpoints like contacts/attributes continue working because the extraction logic safely detects nested vs flat responses
✅ Pagination now works for any endpoint with paginated results
Testing
Open Contact Form 7 with Brevo connected
Navigate to CRM settings
Verify CRM Module dropdown shows all 87 lists (scroll through dropdown)
Verify field mapping still works (check that custom fields load correctly)

@matiasqueroceballos matiasqueroceballos changed the title add pagination Brevo lists Fix Brevo list_modules pagination to return all lists May 12, 2026
@davidperezgar davidperezgar merged commit 03e280c into trunk May 13, 2026
9 of 10 checks passed
@davidperezgar davidperezgar deleted the select-model-crm branch May 13, 2026 07:16
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