Telephony API
Call recording API
Manage your centralized call recordings via an API.
The Sonetel Call recording API allows you to browse, download and delete call recordings made centrally.
How to activate call recording centrally
Activate call recording in your account in the web app.
Please note that you need to verify your account before Call recording can be activated.
How the API works
The Call recording API can be used to perform the following tasks;
- Browse
You can get a list of all your recordings, and optionally filter them. - Get details
You can get details about the recording, including the phone number of the calling party and the called party, the name of any user involved in the call etc. - Download
You can download the audio file. - Delete
You can delete the recording permanently.
Sample scripts for managing Call Recordings
Python
The following sample script with Python can be used to retrieve, delete, and download recordings:
import requests
base_url = "https://public-api.sonetel.com/"
# Function will change the format of date
def date_format_change(date):
date.replace(":", "%3A")
# Enter Date
created_date_max = "ENTER THE MAX DATE"
date_format_change(created_date_max)
created_date_min = "ENTER THE MIN DATE"
date_format_change(created_date_min)
# API Access token
access_token = "ENTER_ACCESS_TOKEN"
# Sonetel account ID
acc_id = "ENTER_ACCOUNT_ID"
#account information
headers = {"Authorization": "Bearer {}".format(access_token),
'Content-Type': 'application/json'
}
#########################Choices for user######################
# type 1 to View recording
# type 2 to Download recording
# type 3 to Delete recording
choice = 1; # Download Recording
########################retrive all call recordings##################
def retrive_call_recordings():
global response_all_recording
response_all_recording= requests.request("GET", "{}call-recording?account_id={}&created_date_min={}&created_date_max={}&type=voice_call&fields=voice_call_details".format(base_url,acc_id,created_date_min,created_date_max), headers=headers).json()
return response_all_recording
if(choice==1):
if(retrive_call_recordings()):
print(response_all_recording["response"])
########################download call recordings####################
def download_call_recordings():
global response_download_recording
response_download_recording = requests.request("GET", "{}call-recording/{}?fields=file_access_details".format(base_url, call_recording_id), headers=headers).json()
return response_download_recording
if(choice==2):
#user have to enter call_recording_id
call_recording_id = "ENTER CALL_RECORDING_ID"
if(download_call_recordings()):
print(response_download_recording["response"]["file"]["file_access_details"]["url"])
############################delete recording#############################
def delete_recording():
global response_delete_recording
response_delete_recording = requests.request("DELETE", "{}call-recording/{}".format(base_url, del_rec_id), headers=headers).json()
if response_delete_recording['status'] == "success":
return True
else:
return False
if(choice==3):
# calling so user can see their call rec
retrive_call_recordings()
del_rec_id = "ENTER CALL_RECORDING_ID"
if(delete_recording()):
print("Recording is successfully DELETED")
NodeJS
The following sample script with NodeJS can be used to retrieve recordings:
import http from "https";
const get_recordings = ({accessToken, fields, startDate, endDate}) => {
const host = process.env.SonetelAPIName ?? "public-api.sonetel.com";
let url = `/call-recording/`;
let query = [];
if (!accessToken || !accessToken instanceof String) {
throw Error("accessToken is required and must be passed as a String");
}
const parsedToken = JSON.parse(
Buffer.from(accessToken.split(".")[1], "base64").toString()
);
const accountId = parsedToken.acc_id;
query.push(`account_id=${accountId}`);
if (startDate && endDate) {
// If the recording ID is specified, then fetch that particular recording.
query.push(`created_date_min=${startDate}`);
query.push(`created_date_max=${endDate}`);
}
if (fields && fields instanceof Array){
query.push(`fields=${fields.join()}`);
}
// Final URL
url += `?${query.join('&')}`;
const options = {
hostname: host,
path: url,
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${accessToken}`,
Accept: "application/json",
},
};
const req = http.request(options, (res) => {
const { statusCode } = res;
if (statusCode !== 200) {
throw new Error(`Request failed. Status code ${statusCode}`);
}
res.setEncoding("utf-8");
let rawData = "";
res.on("data", (chunk) => (rawData += chunk));
res.on("end", () => {
try {
const parsedData = JSON.parse(rawData);
console.log(parsedData);
} catch (e) {
console.error(e.message);
}
});
});
req.on("error", (e) => {
throw new Error(`Request failed. ${e.message}`);
});
req.end();
};
export { get_recordings };
Sample codes for deleting and downloading recordings can be found here.
