Lua
Lua
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 Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
-- 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
http:set_request_header("Authorization", "Token token=abc1234")
local sbResponseBody = chilkat.StringBuilder.new()
local success = http:quick_get_sb("https://api.callrail.com/v3/a/{account_id}/calls/{call_id}/recording.json", sbResponseBody)
if not success then
print(http.last_error_text)
return
end
local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false
print("Response Body:")
print(jResp:emit())
local respStatusCode = http.last_status
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
print("Response Header:")
print(http.last_header)
print("Failed.")
return
end
-- Sample JSON response:
-- {
-- "url": "http://app.callrail.com/calls/CAL11df32690b7d46123456789123456789/recording/redirect?access_key=241sa242sadqwerty123"
-- }
local url = jResp:string_of("url")
-- Download to a .mp3 file
success = http:download(url, "call_recordings/CAL11df32690b7d46123456789123456789.mp3")
if not success then
print(http.last_error_text)
else
print("success.")
end