FG
๐Ÿ’ป Software๐Ÿ”Œ APIs & SDKsTwilio

pageSize opts not working

Fresh3 days ago
Mar 14, 20260 views
Confidence Score50%
50%

Problem

Hello, I'm facing a wrong behaviour using the twilio-node sdk. If I try to retrieve the messages list from a channel setting a pageSize value, let's say equal to 25, the result contains all the messages like if the pageSize option is ignored. I tried using the REST api instead, specifying the `?PageSize=25` param, and all works fine since I get the first 25 messages and the link for the next page and so on. How can I solve this? Thanks. Is there also a way to specify the starting page? Thanks, Simone Version: 3.30.3 Code Snippet [code block]

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix โ€“ Awaiting Verification

Fix pageSize Option in Twilio Node SDK for Message Retrieval

Medium Risk

The Twilio Node SDK may not be correctly applying the pageSize parameter when retrieving messages from a channel, leading to the retrieval of all messages instead of the specified limit. This could be due to a bug in the SDK version 3.30.3 or a misunderstanding of how pagination is implemented in the SDK compared to the REST API.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Update Twilio Node SDK

    Check if there is a newer version of the Twilio Node SDK available that may have fixed this issue. Update to the latest version if possible.

    bash
    npm install twilio@latest
  2. 2

    Use REST API for Pagination

    If updating the SDK does not resolve the issue, consider using the REST API directly for retrieving messages with pagination. This can be done by making an HTTP GET request to the appropriate endpoint with the pageSize parameter.

    javascript
    const axios = require('axios');
    
    axios.get('https://api.twilio.com/v2/Channels/{ChannelSid}/Messages?PageSize=25', {
      auth: {
        username: 'YOUR_ACCOUNT_SID',
        password: 'YOUR_AUTH_TOKEN'
      }
    }).then(response => {
      console.log(response.data);
    }).catch(error => {
      console.error(error);
    });
  3. 3

    Implement Starting Page Logic

    To specify the starting page, you can use the 'Page' parameter in the REST API call. Adjust your request to include this parameter to retrieve messages from a specific page.

    javascript
    axios.get('https://api.twilio.com/v2/Channels/{ChannelSid}/Messages?PageSize=25&Page=2', {
      auth: {
        username: 'YOUR_ACCOUNT_SID',
        password: 'YOUR_AUTH_TOKEN'
      }
    })
  4. 4

    Test the Implementation

    Run the updated code to ensure that the messages retrieved are limited to the specified pageSize and that pagination works as expected. Verify that the output matches the expected number of messages.

Validation

Confirm that the number of messages returned is equal to the pageSize specified (25 in this case) and that pagination links are correctly provided for further pages. Check the console output for any errors.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

twiliosmsapitype:-docs-updatetype:-question