Sample code for 30+ languages & platforms
Tcl

CallRail API - Retrieve a Call Recording

See more CallRail Examples

Returns a CallRail URL pointing to an MP3 recording of the specified call, and then downloads the MP3 to a local file.

Chilkat Tcl Downloads

Tcl

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=abc1234" \
#   https://api.callrail.com/v3/a/{account_id}/calls/{call_id}/recording.json

# Use the following online tool to generate HTTP code from a CURL command
# Convert a cURL Command to HTTP Source Code

CkHttp_SetRequestHeader $http "Authorization" "Token token=abc1234"

set sbResponseBody [new_CkStringBuilder]

set success [CkHttp_QuickGetSb $http "https://api.callrail.com/v3/a/{account_id}/calls/{call_id}/recording.json" $sbResponseBody]
if {$success == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkStringBuilder $sbResponseBody
    exit
}

set jResp [new_CkJsonObject]

CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0

puts "Response Body:"
puts [CkJsonObject_emit $jResp]

set respStatusCode [CkHttp_get_LastStatus $http]
puts "Response Status Code = $respStatusCode"
if {$respStatusCode >= 400} then {
    puts "Response Header:"
    puts [CkHttp_lastHeader $http]
    puts "Failed."
    delete_CkHttp $http
    delete_CkStringBuilder $sbResponseBody
    delete_CkJsonObject $jResp
    exit
}

# Sample JSON response:

# {
#   "url": "http://app.callrail.com/calls/CAL11df32690b7d46123456789123456789/recording/redirect?access_key=241sa242sadqwerty123"
# }

set url [CkJsonObject_stringOf $jResp "url"]

# Download to a .mp3 file
set success [CkHttp_Download $http $url "call_recordings/CAL11df32690b7d46123456789123456789.mp3"]
if {$success == 0} then {
    puts [CkHttp_lastErrorText $http]
} else {
    puts "success."
}


delete_CkHttp $http
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp