Complete Example
A runnable script that initiates a call, polls until it ends, then fetches the recording URL. Copy it, replace the API key, and run.
Node.js
// Node.js 18+ — uses built-in fetch
const API_KEY = "vp_YOUR_API_KEY";
const BASE = "https://voice-api.edesy.in/v1";
async function call(path, init = {}) {
const res = await fetch(BASE + path, {
...init,
headers: {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
...(init.headers || {}),
},
});
const json = await res.json();
if (!res.ok) throw new Error(json?.error?.message || res.statusText);
return json.data;
}
// 1. Dial
const { call_sid } = await call("/masking/calls", {
method: "POST",
body: JSON.stringify({ party_a: "9876543210", party_b: "9123456789" }),
});
console.log("Call initiated:", call_sid);
// 2. Poll status every 2 seconds until terminal
const terminal = new Set(["completed", "failed", "no-answer"]);
let status;
while (true) {
const log = await call(`/masking/calls/${call_sid}`);
status = log.status;
console.log("Status:", status);
if (terminal.has(status)) break;
await new Promise((r) => setTimeout(r, 2000));
}
// 3. Fetch the recording (if any)
if (status === "completed") {
try {
const rec = await call(`/masking/calls/${call_sid}/recording`);
console.log("Recording URL (valid 1h):", rec.url);
} catch (e) {
console.log("No recording:", e.message);
}
}
Python
# Python 3.7+ — requires "pip install requests"
import time
import requests
API_KEY = "vp_YOUR_API_KEY"
BASE = "https://voice-api.edesy.in/v1"
HEADERS = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}
def call(method, path, **kwargs):
res = requests.request(method, BASE + path, headers=HEADERS, **kwargs)
body = res.json()
if not res.ok:
raise RuntimeError(body.get("error", {}).get("message", res.reason))
return body["data"]
# 1. Dial
result = call("POST", "/masking/calls", json={"party_a": "9876543210", "party_b": "9123456789"})
call_sid = result["call_sid"]
print("Call initiated:", call_sid)
# 2. Poll status until terminal
TERMINAL = {"completed", "failed", "no-answer"}
while True:
log = call("GET", f"/masking/calls/{call_sid}")
status = log["status"]
print("Status:", status)
if status in TERMINAL:
break
time.sleep(2)
# 3. Fetch the recording
if status == "completed":
try:
rec = call("GET", f"/masking/calls/{call_sid}/recording")
print("Recording URL (valid 1h):", rec["url"])
except RuntimeError as e:
print("No recording:", e)
PHP
<?php
// PHP 7.4+ — uses built-in curl extension
$API_KEY = "vp_YOUR_API_KEY";
$BASE = "https://voice-api.edesy.in/v1";
function call($method, $path, $body = null) {
global $API_KEY, $BASE;
$ch = curl_init($BASE . $path);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $API_KEY,
"Content-Type: application/json",
]);
if ($body !== null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
}
$resp = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$json = json_decode($resp, true);
if ($code >= 400) {
throw new Exception($json["error"]["message"] ?? "HTTP $code");
}
return $json["data"];
}
// 1. Dial
$result = call("POST", "/masking/calls", [
"party_a" => "9876543210",
"party_b" => "9123456789",
]);
$call_sid = $result["call_sid"];
echo "Call initiated: $call_sid\n";
// 2. Poll status until terminal
$terminal = ["completed", "failed", "no-answer"];
while (true) {
$log = call("GET", "/masking/calls/$call_sid");
$status = $log["status"];
echo "Status: $status\n";
if (in_array($status, $terminal)) break;
sleep(2);
}
// 3. Fetch the recording
if ($status === "completed") {
try {
$rec = call("GET", "/masking/calls/$call_sid/recording");
echo "Recording URL (valid 1h): " . $rec["url"] . "\n";
} catch (Exception $e) {
echo "No recording: " . $e->getMessage() . "\n";
}
}