Get call recordings
In this step you will make a GET request to the Call Recording API to get a JSON response with your call recordings.
-
Before you call the company_call_recordings API, you must pass in a date string that is one month in the past.
import datetime import urllib.parse today = datetime.datetime.now() last_week = datetime.timedelta(days = 30) date_diff = today - last_week encoded_date = urllib.parse.quote_plus(date_diff.strftime('%Y-%m-%dT00:00:00+0000'))
- In this example, you get the current date using
datetime.datetime.now()
. - Use the
datetime.timedelta()
function to create a date that isdays
in the past. In this example,30
is the value set. - Subtract the current date from the date 30 days in the past, to get our date.
- Use
strftime()
to convert the date object into a string. In this example, the time is set to00:00:00+0000
, which means you will get the date at midnight UTC. - Before you can pass the date into the Call Recordings API, you must urlencode the date using
urllib.parse.quote_plus()
.
- In this example, you get the current date using
-
Request the
company_call_recordings/v1/api/
and use theaccess_token
that was returned from theget_token()
function. This will return a JSON response of the call recordings. Next, pass in theencoded_date
into this function:import requests comany_recordings = [] def company_call_recordings(token, start_date, account_id="self",order="asc", page_size=10, page=1): url = "https://api.vonage.com/t/vbc.prod/call_recording/v1/api/accounts/{}/company_call_recordings?order={}&page_size={}&page={}&start:gte={}".format(account_id, order, page_size, page, start_date) headers = { 'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(token), } response = requests.request("GET", url, headers=headers).json() if "_embedded" in response: comany_recordings.extend(response["_embedded"]["recordings"]) if "total_pages" in response: if page < response["total_pages"]: page = page + 1 company_call_recordings(token, start_date, account_id, order, page_size, page) return comany_recordings
In this example, you are calling the
company_call_recordings/v1/api/
and passing the following parameters:Key Description account_id
The Vonage Business Communications account ID. You can use self
to refer to the authenticated user's account.page
The number of pages to request. page_size
The requested page size. order
The order of the returned call recordings. start:gte
Filter records by start date (greater than or equal to). You may also pass in
start:lte
which would return records less than the given date. -
Once you get a list of call recordings, you will loop though each recording and get the duration of the call so you can determine which recordings should be deleted.
Before doing this, make sure you have a backup of the recordings. Refer to the Saving call recordings to Amazon S3 tutorial to save recordings to an Amazon S3 bucket.
For the purposes of this tutorial, you will create a function to delete the call recordings with durations less than or equal to 30 seconds in the next step.
Delete company call recordings by duration
Delete call recordings and on-demand call recordings by their durations.Steps