twilio / twilio-node

Node.js helper library
MIT License
1.37k stars 495 forks source link

Unable to filter calls using startTime and endTime in the list method (please see closing comments) #975

Closed thechori closed 2 months ago

thechori commented 8 months ago

Describe the bug

My code works perfectly when I run:

const calls = await twilioClient.calls.list({
  from: "+12223334444", // fake number
})

but when I try to add the startTime and endTime, I receive an empty array (see below in "To Reproduce")

Note: I think it might have to do with the difference between Date and a string type when being passed in? I've tried to convert my date string (e.g., "2023-11-01") to a Date object, and neither works.

image

In this intellisense screenshot, the suggestion is to pass a date as YYYY-MM-DD but the TypeScript type is marked as Date | undefined

To Reproduce

// Returns an empty array when there is lots of data
const calls = await twilioClient.calls.list({
  from: "+12223334444",
  startTime: "2023-11-01",
  endTime: "2023-12-01",
});

// Returns an empty array when there is lots of data
const calls = await twilioClient.calls.list({
  from: "+12223334444",
  startTime: new Date("2023-11-01"),
  endTime: new Date("2023-12-01"),
});

Expected behavior

I'd expect to pass in the date's string (e.g., "2023-11-01") into the following function and have the filtered call data return properly

const calls = await twilioClient.calls.list({
      from: "+12223334444",
      startTime: "2023-11-01",
      endTime: "2023-12-01",
    });

Code snippets

See above

OS

macOS

Node version

Node v20.5.0

Library version

"twilio": "^4.12.0"

Additional context

Absolutely love the work that you all have done. This is my first hiccup with the API and I'd be more than glad to help more to get this resolved because this would make my application even better.

Thank you so much!! 🔥 🙌

Update (as of finishing this bug report...):

I've found the issue... I was using the wrong parameters the entire time... I did not realize that there were startTimeAfter and endTimeBefore. I'd love to say that doing away with both of those in favor of consolidating into simply startTime and endTime would be the best way to improve DX, but I also don't have the context and experience of a Twilio engineer, so I don't know if that is sound advice or not. All I know is that I was incredibly confused and frustrated and I only stumbled upon these two extra parameters by throwing a hail mary pass at the intellisense to see what other things I could pass into the .list() function call.

I sincerely hope that you appreciate the time that I spent to provide this feedback. Once again, you guys are awesome. Thank you so much for the hard and quality work. Sorry if this comes as a waste of time to y'all, but I hope that it does not!

Cheers :)

tiwarishubham635 commented 2 months ago

Hello @thechori! We have looked into this issue and tried to update the comments with these parameters. Can you please check once here and see if it helps better now?

thechori commented 2 months ago

Hey @tiwarishubham635 , I'm no longer working on the project that used this library. sorry about that. But thank you so much for looking into this! I think this could help a lot of other people. Cheers!

tiwarishubham635 commented 2 months ago

Alright then, would you like to close this issue?

thechori commented 2 months ago

sure!