Connect Number to Call Flow
Call a phone number and connect them to an applet/IVR flow after they answer. Unlike Connect Two Numbers, this API uses a flow URL instead of a To number.
Request Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
From | Yes | String | The phone number to call first. |
CallerId | Yes | String | Your ExoPhone/virtual number. |
Url | Yes | String | Flow URL: http://my.exotel.com/{your_sid}/exoml/start_voice/{app_id} |
CallType | No | String | trans for transactional calls. |
TimeLimit | No | Integer | Max call duration in seconds. Max: 14400 (4 hours). |
TimeOut | No | Integer | Time in seconds to ring the called party before treating the call as unanswered. The timer runs only during ringing and stops once the call is answered. |
StatusCallback | No | String | Webhook URL for call status updates. |
StatusCallbackEvents | No | Array | terminal, answered, or both. |
CustomField | No | String | Metadata passed to the applet via Passthru. |
MachineDetection | No | String | Enable or Disable (default). Enables answering machine detection on Leg 1 (the From leg). Case-insensitive; omitting the parameter is treated as Disable. Empty string is invalid and returns 400. |
AsyncAmd | No | String | Required when MachineDetection=Enable. Must be true — synchronous AMD is not supported. Any other value returns 400. |
AsyncAmdStatusCallback | No | String | Required when AsyncAmd=true. Absolute http or https URL that receives the AMD result. |
StatusCallbackContentType | No | String | multipart/form-data (default) or application/json. Applies to both StatusCallback and AsyncAmdStatusCallback. |
The Url parameter should point to a call flow (applet) configured in your Exotel dashboard. The app_id is the flow ID found in App Bazaar > My Apps.
Code Examples
- cURL
- Python
- Node.js
- PHP
- Go
curl -u '<api_key>:<api_token>' -X POST 'https://api.exotel.com/v1/Accounts/<your_sid>/Calls/connect' \
-d 'From=+919876543210' \
-d 'CallerId=0XXXXXX4890' \
-d 'Url=http://my.exotel.com/<your_sid>/exoml/start_voice/<app_id>' \
-d 'CallType=trans' \
-d 'StatusCallback=https://yoururl.com/callback'
import requests
data = {
'From': '+919876543210',
'CallerId': '0XXXXXX4890',
'Url': 'http://my.exotel.com/<your_sid>/exoml/start_voice/<app_id>',
'CallType': 'trans',
'StatusCallback': 'https://yoururl.com/callback'
}
response = requests.post(
'https://api.exotel.com/v1/Accounts/<your_sid>/Calls/connect',
auth=('<api_key>', '<api_token>'),
data=data
)
print(response.json())
const apiKey = '<your_api_key>';
const apiToken = '<your_api_token>';
const accountSid = '<your_sid>';
const url = `https://api.exotel.com/v1/Accounts/${accountSid}/Calls/connect`;
const params = new URLSearchParams({
From: '+919876543210',
CallerId: '0XXXXXX4890',
Url: `http://my.exotel.com/${accountSid}/exoml/start_voice/<app_id>`,
CallType: 'trans',
});
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': 'Basic ' + Buffer.from(`${apiKey}:${apiToken}`).toString('base64'),
'Content-Type': 'application/x-www-form-urlencoded',
},
body: params,
});
const data = await response.json();
console.log(data);
<?php
$data = array(
'From' => '+919876543210',
'CallerId' => '0XXXXXX4890',
'Url' => 'http://my.exotel.com/<your_sid>/exoml/start_voice/<app_id>',
'CallType' => 'trans',
'StatusCallback' => 'https://yoururl.com/callback'
);
$ch = curl_init('https://api.exotel.com/v1/Accounts/<your_sid>/Calls/connect');
curl_setopt($ch, CURLOPT_USERPWD, "<api_key>:<api_token>");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strings"
)
func main() {
endpoint := "https://api.exotel.com/v1/Accounts/<your_sid>/Calls/connect"
data := url.Values{}
data.Set("From", "+919876543210")
data.Set("CallerId", "0XXXXXX4890")
data.Set("Url", "http://my.exotel.com/<your_sid>/exoml/start_voice/<app_id>")
data.Set("CallType", "trans")
data.Set("StatusCallback", "https://yoururl.com/callback")
req, _ := http.NewRequest("POST", endpoint, strings.NewReader(data.Encode()))
req.SetBasicAuth("<api_key>", "<api_token>")
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}
Response
{
"Call": {
"Sid": "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6",
"ParentCallSid": null,
"DateCreated": "2017-03-03 12:30:24",
"DateUpdated": "2017-03-03 12:30:27",
"AccountSid": "your_sid",
"To": null,
"From": "09876543210",
"PhoneNumberSid": "0XXXXXX4890",
"Status": "in-progress",
"StartTime": "2017-03-03 12:30:27",
"EndTime": null,
"Duration": null,
"Price": null,
"Direction": "outbound-api",
"AnsweredBy": null,
"Uri": "/v1/Accounts/your_sid/Calls.json/a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6",
"RecordingUrl": null
}
}
When using a flow URL, the To field in the response will be null since the destination is a flow rather than a phone number. The call proceeds to the applet after the From party answers.
Answering Machine Detection (AMD)
When MachineDetection=Enable, AMD runs in parallel with the call after Leg 1 (the From leg) answers. It classifies who picked up — a human or an answering machine / voicemail — without ending the call. The result is delivered to your AsyncAmdStatusCallback mid-call (not on StatusCallback), so you can act on it while the call is still live. AMD does not auto-hangup; your application decides what to do next.
Validation rules
| Condition | Result |
|---|---|
MachineDetection omitted | Treated as Disable; AMD params ignored |
MachineDetection=Disable | AMD params present but ignored; no 400 |
MachineDetection=Enable, valid AsyncAmd=true and AsyncAmdStatusCallback | AMD enabled |
MachineDetection=Enable, missing or invalid AsyncAmd or AsyncAmdStatusCallback | 400 |
MachineDetection= (empty string) | 400 |
AsyncAmdStatusCallback payload
Exotel POSTs to your URL when AMD completes. This can fire even if the call has already ended.
| Field | Type | Description |
|---|---|---|
CallSid | String | Call SID |
AccountSid | String | Account SID |
AnsweredBy | String | HUMAN, MACHINE, or NOTSURE |
AmdCause | String | Cause string from the AMD engine (e.g. HUMAN, INITIALSILENCE-2500-2500). Numbers inside the cause are detector thresholds in milliseconds, not the detection duration. Empty string when not provided. |
MachineDetectionDuration | String | AMD detection time in whole seconds, as a string (e.g. 4). 0 when AMD completes within the same second. Empty string when not provided. |
CallStatus | String | Call state at the time AMD completed (e.g. in-progress, completed). Reflects the state at the time of the result; it does not change the call. |
Content-Type defaults to multipart/form-data. Pass StatusCallbackContentType=application/json on the original request to receive JSON instead.
Acting on the result
AMD reports the outcome; your application decides the next step. When you receive a MACHINE verdict at your AsyncAmdStatusCallback, common patterns are:
- Hang up the call — stop engaging a voicemail or IVR, so you don't spend time (and, in a voicebot flow, tokens) on a machine.
- Drop a voicemail, then hang up — play a pre-recorded message for the machine, then end the call.
Call control — ending the call or playing audio on a live leg — is performed through the Legs & Bridges API (for example, the ExoML Hangup action). AMD itself never hangs up the call.
AnsweredBy is always one of HUMAN, MACHINE, or NOTSURE. AmdCause and MachineDetectionDuration are passed through from the telephony layer and may be empty for a given call.