PHP example

Voice API in PHP: Code Example

Call the Edesy Voice API from PHP with cURL. Works in Laravel, Symfony or plain PHP. Place a call with one HTTPS request to POST /v1/calls and control it with VoiceML (JSON).

Plain REST + JSON

No package to install

Rs 0.50/min, 60 s pulse

Place a Call from PHP

Call this from your server and keep the API key in an environment variable.

<?php
$ch = curl_init("https://voice-api.edesy.in/v1/calls");
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("EDESY_API_KEY"),
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => json_encode([
        "to"              => "+919876543210",
        "from"            => "+918045678901", // your Edesy number
        "text"            => "Hello from Edesy. Your order has shipped.",
        "status_callback" => "https://your-app.com/webhooks/call-status",
    ]),
]);
$call = json_decode(curl_exec($ch), true)["data"];
curl_close($ch);
echo $call["call_sid"];

Control the call with VoiceML

Instead of text, pass url: your endpoint returns VoiceML, a JSON list of instructions. It is not TwiML.

{
  "instructions": [
    { "verb": "say", "text": "Your order has shipped.", "language": "en-IN" },
    {
      "verb": "gather",
      "input": "dtmf",
      "num_digits": 1,
      "action": "https://your-app.com/voiceml/order",
      "nested": [{ "verb": "say", "text": "Press 1 to confirm, or 2 to cancel." }]
    }
  ]
}

Twilio-style request

The Twilio-shaped alias accepts Basic auth with your Account SID and Auth Token.

curl -X POST https://voice-api.edesy.in/v1/Accounts/$ACCOUNT_SID/Calls \
  -u "$ACCOUNT_SID:$AUTH_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"to":"+919876543210","from":"+918045678901","text":"Hello from Edesy."}'

Code Examples for Other Languages

FAQ

Ready to Build with PHP?

Sign up, top up the prepaid INR wallet and place your first call. Rs 0.50/min, 60-second pulse, unanswered calls free.