Vonage / vonage-node-sdk

Vonage API client for Node.js. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
Apache License 2.0
375 stars 178 forks source link

[Bug]: numbers.getOwnedNumbers does not return all numbers #928

Closed tapz closed 2 months ago

tapz commented 2 months ago

Node Version

20.x

Platform

Mac (Apple Silcon)

SDK Version

3.10.0

Code Sample

    const numbers = [];
    let totalCount = 100;

    while (numbers.length < totalCount) {
      const res = await vonage.numbers.getOwnedNumbers({
        country: '',
        applicationId: appId || '',
        index: numbers.length + 1,
        size: Math.min(totalCount - numbers.length, 100)
      });

      console.log(res);

      if (res.count) {
        totalCount = res.count;
      }

      if (res.numbers) {
        numbers.push(...res.numbers);
      } else {
        break;
      }
    }

Expected Behavior

All numbers should be returned, page by page.

Actual Behavior

If the page size is 10, you can call the api 6 times to get totally 60 numbers. All further request with page index > 6 return an empty response . If the page size is 100, you can call the api only once and get the first 100 numbers. All further requests with page index > 1 return a response {}. The count returned in the first response is 589, so why doesn't the api/sdk return the rest of the numbers? The paging system clearly does not work at all.

tapz commented 2 months ago

The index seems to be a PAGE index, not an offset.

manchuck commented 1 month ago

@tapz Thanks for reporting this. I will make sure to get our documentation updated after checking with the Numbers API team to confirm this behavior