Tcl
Tcl
CallRail API - Create an Outbound Phone Call
See more CallRail Examples
Initiates an outbound call from the target account.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set http [new_CkHttp]
# Implements the following CURL command:
# curl -H "Authorization: Token token={api_token}" \
# -X POST \
# -H "Content-Type: application/json" \
# -d '{
# "caller_id": "+17703334455",
# "business_phone_number": "+14045556666",
# "customer_phone_number": "+14044442233",
# "recording_enabled": true,
# "outbound_greeting_recording_url": "http://www.test.com/greeting.mp3",
# "outbound_greeting_text": "These are not the droids you are looking for."
# }' \
# "https://api.callrail.com/v3/a/{account_id}/calls.json"
# Use the following online tool to generate HTTP code from a CURL command
# Convert a cURL Command to HTTP Source Code
# Use this online tool to generate code from sample JSON:
# Generate Code to Create JSON
# The following JSON is sent in the request body.
# {
# "caller_id": "+17703334455",
# "business_phone_number": "+14045556666",
# "customer_phone_number": "+14044442233",
# "recording_enabled": true,
# "outbound_greeting_recording_url": "http://www.test.com/greeting.mp3",
# "outbound_greeting_text": "These are not the droids you are looking for."
# }
set json [new_CkJsonObject]
CkJsonObject_UpdateString $json "caller_id" "+17703334455"
CkJsonObject_UpdateString $json "business_phone_number" "+14045556666"
CkJsonObject_UpdateString $json "customer_phone_number" "+14044442233"
CkJsonObject_UpdateBool $json "recording_enabled" 1
CkJsonObject_UpdateString $json "outbound_greeting_recording_url" "http://www.test.com/greeting.mp3"
CkJsonObject_UpdateString $json "outbound_greeting_text" "These are not the droids you are looking for."
CkHttp_SetRequestHeader $http "Authorization" "Token token={api_token}"
CkHttp_SetRequestHeader $http "Content-Type" "application/json"
set resp [new_CkHttpResponse]
set success [CkHttp_HttpJson $http "POST" "https://api.callrail.com/v3/a/{account_id}/calls.json" $json "application/json" $resp]
if {$success == 0} then {
puts [CkHttp_lastErrorText $http]
delete_CkHttp $http
delete_CkJsonObject $json
delete_CkHttpResponse $resp
exit
}
set sbResponseBody [new_CkStringBuilder]
CkHttpResponse_GetBodySb $resp $sbResponseBody
set jResp [new_CkJsonObject]
CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0
puts "Response Body:"
puts [CkJsonObject_emit $jResp]
set respStatusCode [CkHttpResponse_get_StatusCode $resp]
puts "Response Status Code = $respStatusCode"
if {$respStatusCode >= 400} then {
puts "Response Header:"
puts [CkHttpResponse_header $resp]
puts "Failed."
delete_CkHttp $http
delete_CkJsonObject $json
delete_CkHttpResponse $resp
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp
exit
}
# Sample JSON response:
# (Sample code for parsing the JSON response is shown below)
# {
# "answered": null,
# "business_phone_number": "+19044567899",
# "customer_city": "Atlanta",
# "customer_country": "US",
# "customer_name": null,
# "customer_phone_number": "+14703444700",
# "customer_state": "GA",
# "direction": "outbound",
# "duration": null,
# "id": "CAL8154748ae6bd4e278a7cddd38a662f4f",
# "recording": null,
# "recording_duration": null,
# "start_time": "2017-02-22T15:02:24.916-05:00",
# "tracking_phone_number": "+19044567899",
# "voicemail": false
# }
# Sample code for parsing the JSON response...
# Use the following online tool to generate parsing code from sample JSON:
# Generate Parsing Code from JSON
set answered [CkJsonObject_stringOf $jResp "answered"]
set business_phone_number [CkJsonObject_stringOf $jResp "business_phone_number"]
set customer_city [CkJsonObject_stringOf $jResp "customer_city"]
set customer_country [CkJsonObject_stringOf $jResp "customer_country"]
set customer_name [CkJsonObject_stringOf $jResp "customer_name"]
set customer_phone_number [CkJsonObject_stringOf $jResp "customer_phone_number"]
set customer_state [CkJsonObject_stringOf $jResp "customer_state"]
set direction [CkJsonObject_stringOf $jResp "direction"]
set duration [CkJsonObject_stringOf $jResp "duration"]
set id [CkJsonObject_stringOf $jResp "id"]
set recording [CkJsonObject_stringOf $jResp "recording"]
set recording_duration [CkJsonObject_stringOf $jResp "recording_duration"]
set start_time [CkJsonObject_stringOf $jResp "start_time"]
set tracking_phone_number [CkJsonObject_stringOf $jResp "tracking_phone_number"]
set voicemail [CkJsonObject_BoolOf $jResp "voicemail"]
delete_CkHttp $http
delete_CkJsonObject $json
delete_CkHttpResponse $resp
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp