Can't get past 24h calls from API
Andreluizfc opened this issue · 4 comments
Andreluizfc commented
Issue Summary
I can't find a way to get the last calls from past X hours from API.
Can I query the calls database based on hours?
The code snippet bellow is something that should be implemented.
Code Snippet
import os
from twilio.rest import Client
from datetime import datetime, timedelta
# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
# Calculate start and end date for the last 24 hours
end_time = datetime.utcnow()
start_time = end_time - timedelta(hours=24)
# Format dates for Twilio API query
start_time_formatted = start_time.strftime('%Y-%m-%dT%H:%M:%SZ')
end_time_formatted = end_time.strftime('%Y-%m-%dT%H:%M:%SZ')
calls = client.calls.list(start_time=start_time_formatted, end_time=end_time_formatted)
Exception/Log
# paste exception/log here
Technical details:
- twilio-python version: 9.0.4
- python version: 3.9
tiwarishubham635 commented
I think you can use start_time_after parameter. Pass start_time_formatted as its value and that should do the work. See here.
tiwarishubham635 commented
No, you can't query the database on hours. We currently support start_time, end_time and their inequality fields.
Andreluizfc commented
Great. Thanks for the help. I end up going to this list()
method.
Andreluizfc commented
@tiwarishubham635 Clarified the right usage.