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. |
info
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
}
}
note
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.