Reputation: 2177
We are using Twilio to send messages and want to get a count of messages that have been sent by a number and recieved by the same number.
Right now we are trying to do something along the lines like:
messagesTo = twilioClient.messages.list({
"DateSent>" : startDate,
"DateSent<" : endDate,
"to" : number
})
messagesFrom = twilioClient.messages.list({
"DateSent>" : startDate,
"DateSent<" : endDate,
"from_" : number
})
count = len(messagesTo) + len(messagesFrom)
However we are running into 2 problems.
First, the
twilioClient.messages.list({
"DateSent>" : startDate,
"DateSent<" : endDate,
"to" : number
})
is always returning empty with the to field used
Second, we always get only a maximum of 50 results.
Is there a way to just use the parameters to get the count rather then the messages?
Upvotes: 1
Views: 923
Reputation: 73027
Twilio developer evangelist here.
I'm afraid API results do not include the total number of results. This was a compromise taken mainly for performance reasons. There was a blog post that explained the decisions made around pagination here.
If you really do need to count the messages, you can page through the list yourself. Firstly, you can get up to 1000 messages per page, by setting the PageSize
attribute to 1000.
With the Python helper library, you can also iterate through all results using the iter
method, as explained here.
Let me know if that helps at all.
Upvotes: 2