Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcUrl

lnSuccess = 0

* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

loHttp = CreateObject('Chilkat.Http')

* 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

loHttp.SetRequestHeader("Authorization","Token token=abc1234")

loSbResponseBody = CreateObject('Chilkat.StringBuilder')
lnSuccess = loHttp.QuickGetSb("https://api.callrail.com/v3/a/{account_id}/calls/{call_id}/recording.json",loSbResponseBody)
IF (lnSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loHttp.LastStatus
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
    ? "Response Header:"
    ? loHttp.LastHeader
    ? "Failed."
    RELEASE loHttp
    RELEASE loSbResponseBody
    RELEASE loJResp
    CANCEL
ENDIF

* Sample JSON response:

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

lcUrl = loJResp.StringOf("url")

* Download to a .mp3 file
lnSuccess = loHttp.Download(lcUrl,"call_recordings/CAL11df32690b7d46123456789123456789.mp3")
IF (lnSuccess = 0) THEN
    ? loHttp.LastErrorText
ELSE
    ? "success."
ENDIF

RELEASE loHttp
RELEASE loSbResponseBody
RELEASE loJResp