Examples
Redirect Call to a new RCML
Live Call Modification POST request example:
curl -X POST https://v1.api19.com/call/2012-04-24/Accounts/ACCOUNT_SID/Calls/CALL_SID.json \
-d 'Url=http://mycompany.com/api19/demos/dialÂalice.xml' \
-u 'API_Token'
Redirect Call to a new RCML and connect both call legs
curl -X POST https://v1.api19.com/call/2012-04-24/Accounts/ACCOUNT_SID/Calls/CALL_SID.json \
-d 'Url=http://mycompany.com/tcml/demos/conference.xml' \
-d 'MoveConnectedCallLeg=true' \
-u 'API_Token'
Terminate In Progress call
curl -X POST https://v1.api19.com/call/2012-04-24/Accounts/ACCOUNT_SID/Calls/CALL_SID.json \
-d 'Status=completed' \
-u 'API_Token'
Terminate Ringing call
curl -X POST https://v1.api19.com/call/2012-04-24/Accounts/ACCOUNT_SID/Calls/CALL_SID.json \
-d 'Status=canceled' \
-u 'API_Token'
Modifying Live Calls - Example
In order to accomplish this, you need to create a client called Alice
Start a SIP phone and register Alice
From the terminal run the following curl command
Make sure Alice is using the port 5061
The "From=" could be any number of your choice
The Url is the default sample example provided with CallAPI.
Modifying a Live Call
curl -X POST https://v1.api19.com/call/2012-04-24/Accounts/ACCOUNT_SID/Calls.json \
-d 'From=+16175551212' \
-d 'To=sip:[email protected]' \
-d 'Url=https://ACCOUNT_SID:[email protected]/callapi/demos/hello-play.xml' \
-u 'API_Token'
You will see an output similar to the one below:
{
"sid": "CAfa51b104354440b09213d04752f50271",
"date_created": "2013-11-01T03:41:14.488-06:00",
"date_updated": "2013-11-01T03:41:14.488-06:00",
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"to": "alice",
"from": "+16175551212",
"status": "queued",
"start_time": "2013-11-01T03:41:14.488-06:00",
"price": "0.0",
"direction": "outbound-api",
"api_version": "2012-04-24",
"uri": "/2012-04-24/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAfa51b104354440b09213d04752f50271.json",
"subresource_uris": {
"notifications": "/call/2012-04-24/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAfa51b104354440b09213d04752f50271/Notifications",
"recordings": "/call/2012-04-24/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAfa51b104354440b09213d04752f50271/Recordings"
}
}
Notice the "sid": "CAfa51b104354440b09213d04752f50271", This Call ID is what you must use to interact with the current call. You can now redirect the current call to another application as shown below Notice that the Call ID is referenced The call will now be redirected to the Url specified(hello-play.xml).
curl -X POST https://v1.api19.com/call/2012-04-24/Accounts/ACCOUNT_SID/Calls/CALL_SID.json \
-d 'From=+16175551212' \
-d 'To=sip:[email protected]' \
-d 'Url=https://ACCOUNT_SID:[email protected]/callapi/demos/hello-play.xml' \
-u 'API_Token'
The output showing the same Call ID:
<CallResponse>
<Call>
<Sid>CAfa51b104354440b09213d04752f50271</Sid>
<DateCreated>2013-11-01T03:41:14.488-06:00</DateCreated>
<DateUpdated>2013-11-01T03:41:14.488-06:00</DateUpdated>
<ParentCallSid/>
<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
<To>alice</To>
<From>+16175551212</From>
<PhoneNumberSid/>
..... TRUNCATED
You can still redirect the current call back to the previous application
curl -X POST https://v1.api19.com/call/2012-04-24/Accounts/ACCOUNT_SID/Calls/CALL_SID.json \
-d 'Url=https://ACCOUNT_SID:[email protected]/callapi/demos/hello-play.xml' \
-u 'API_Token'
const request = require('request');
// Provide your Account Sid and Auth Token from your Console Account page
const ACCOUNT_SID = 'my_ACCOUNT_SID';
const AUTH_TOKEN = 'my_AUTH_TOKEN';
// Provide additional path parameters if applicable
const CALL_SID = 'my_CALL_SID'
request.({
method: 'POST',
url: 'https://v1.api19.com/calls/2012-04-24/Accounts/' + ACCOUNT_SID + '/Calls/' + CALL_SID + '.json',
auth: { 'user': ACCOUNT_SID, 'pass': AUTH_TOKEN },
form: {
'Url': 'https://ACCOUNT_SID:[email protected]/teleapi/demos/hello-play.xml'
}
},
function (error, response, body) {
// Add your business logic below; status can be found at 'response.statusCode' and response body at 'body'
...
});
from http.client import HTTPSConnection
from base64 import b64encode
from urllib.parse import urlencode
# Provide your Account Sid and Auth Token from your Console Account page
ACCOUNT_SID = 'my_ACCOUNT_SID'
AUTH_TOKEN = 'my_AUTH_TOKEN'
// Provide additional path parameters if applicable
CALL_SID = 'my_CALL_SID'
userAndPass = b64encode(bytes(ACCOUNT_SID + ':' + AUTH_TOKEN, 'utf-8')).decode("ascii")
headers = { 'Authorization' : 'Basic %s' % userAndPass,
'Content-type': 'application/x-www-form-urlencoded',
'Accept': 'text/plain' }
# Update POST parameters accordingly
params = urlencode({
'Url': 'https://ACCOUNT_SID:[email protected]/teleapi/demos/hello-play.xml'
})
conn = HTTPSConnection('v1.api19.com')
conn.request("POST", '/calls/2012-04-24/Accounts/' + ACCOUNT_SID + '/Calls/' + CALL_SID + '.json',
params, headers=headers)
res = conn.getresponse()
# Add your business logic below; status can be found at 'res.status', reason at 'res.reason' and response body can be retrieved with res.read()
...
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.util.Base64;
public class JavaSampleClass {
// Provide your Account Sid and Auth Token from your Console Account page
public static final String ACCOUNT_SID = "my_ACCOUNT_SID";
public static final String AUTH_TOKEN = "my_AUTH_TOKEN";
// Provide additional path parameters if applicable
public static final String CALL_SID = "my_CALL_SID"
public static void main(String[] args) throws Exception {
String userAndPass = ACCOUNT_SID + ':' + AUTH_TOKEN;
String encoded = Base64.getEncoder().encodeToString(userAndPass.getBytes());
URL url = new URL(("https://v1.api19.com/calls/2012-04-24/Accounts/" + ACCOUNT_SID + "/Calls/" + CALL_SID + ".json");
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
conn.setRequestProperty("Authorization", "Basic " + encoded);
conn.setRequestMethod("POST");
conn.setDoOutput(true);
DataOutputStream os = new DataOutputStream(conn.getOutputStream());
// Update POST parameters accordingly
os.writeBytes("Url=https://ACCOUNT_SID:[email protected]/api19/demos/hello-play.xml");
os.close();
// Add your business logic below; response code can be obtained from 'conn.getResponseCode()' and input stream from 'conn.getInputStream()'
...
}
}
The output showing the same Call ID
<CallResponse>
<Call>
<Sid>CAfa51b104354440b09213d04752f50271</Sid>
<DateCreated>2013-11-01T03:41:14.488-06:00</DateCreated>
<DateUpdated>2013-11-01T03:41:14.488-06:00</DateUpdated>
<ParentCallSid/>
<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
<To>alice</To>
<From>+16175551212</From>
<PhoneNumberSid/>
..... TRUNCATED
You can still redirect the current call back to the previous application
curl -X POST https://v1.api19.com/call/2012-04-24/Accounts/ACCOUNT_SID/Calls/CALL_SID.json \
-d 'Status=completed' \
-u 'API_Token'
The output showing the same Call ID
<CallResponse>
<Call>
<Sid>CAfa51b104354440b09213d04752f50271</Sid>
<DateCreated>2013-11-01T03:41:14.488-06:00</DateCreated>
<DateUpdated>2013-11-01T03:41:14.488-06:00</DateUpdated>
<ParentCallSid/>
<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
<To>alice</To>
<From>+16175551212</From>
<PhoneNumberSid/>
..... TRUNCATED
You can Mute/unMute an in progress call as shown bellow
curl -X POST https://v1.api19.com/call/2012-04-24/Accounts/ACCOUNT_SID/Conferences/CONFERENCE_SID/Participants/CALL_SID.json \
-d 'Mute=true' \
-u 'API_Token'
Sample Mute Response
<CallResponse>
<Call>
<Sid>CA02b649d3ffe24408a1e141be089f347b</Sid>
<ConferenceSid>CFcc373b0637114f088eae954fa73f0f57</ConferenceSid>
<DateCreated>Wed, 15 Mar 2017 10:10:57 +0000</DateCreated>
<DateUpdated>Wed, 15 Mar 2017 10:15:33 +0000</DateUpdated>
<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
<Muted>true</Muted>
<Hold>false</Hold>
<StartConferenceOnEnter>true</StartConferenceOnEnter>
<EndConferenceOnEnter>false</EndConferenceOnEnter>
<Uri>/2012-04-24/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CA02b649d3ffe24408a1e141be089f347b</Uri>
</Call>
</CallResponse>
curl -X POST https://v1.api19.com/call/2012-04-24/Accounts/ACCOUNT_SID/Conferences/CONFERENCE_SID/Participants/CALL_SID.json \
-d 'Mute=false' \
-u 'API_Token'
Sample unMute Response
<CallResponse>
<Call>
<Sid>CA02b649d3ffe24408a1e141be089f347b</Sid>
<ConferenceSid>CFcc373b0637114f088eae954fa73f0f57</ConferenceSid>
<DateCreated>Wed, 15 Mar 2017 10:10:57 +0000</DateCreated>
<DateUpdated>Wed, 15 Mar 2017 10:16:44 +0000</DateUpdated>
<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
<Muted>false</Muted>
<Hold>false</Hold>
<StartConferenceOnEnter>true</StartConferenceOnEnter>
<EndConferenceOnEnter>false</EndConferenceOnEnter>
<Uri>/2012-04-24/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CA02b649d3ffe24408a1e141be089f347b</Uri>
</Call>
</CallResponse>
Last updated