How to get newest recording in Twilio?

225 views Asked by At

I'm making recordings in Twilio, using python. Just wondering how do I access the latest/newest recording that I've made? Cheers!

Making the recording:

resp = twilio.twiml.Response()
resp.say("Please record your message after the beep")
resp.record(maxLength="10", action="/handle-recording")

Sample code on accessing recordings, how would I code it for the latest? Thanks!

# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "AC30bd8bdca7572344721eb96c15a5c0c7"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

# A list of recording objects with the properties described above
recordings = client.recordings.list()
1

There are 1 answers

2
Muntaser Ahmed On

recordings[-1] should get you the last item in recordings, which should be the newest recording, as recordings are appended to the list. Make sure recordings is not empty otherwise you will get an IndexError.