Sample code for 30+ languages & platforms
React Native

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 React Native Downloads

React Native
import { Http, JsonObject, StringBuilder } from '@chilkat/react-native'

async function chilkatExample() {
  // This example assumes the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  const http = new 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

  http.setRequestHeader('Authorization', 'Token token=abc1234');

  const sbResponseBody = new StringBuilder();
  try {
    await http.quickGetSbAsync('https://api.callrail.com/v3/a/{account_id}/calls/{call_id}/recording.json', sbResponseBody);
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  const jResp = new JsonObject();
  jResp.loadSb(sbResponseBody);
  jResp.emitCompact = false;

  console.log('Response Body:');
  console.log(jResp.emit());

  const respStatusCode = http.lastStatus;
  console.log(`Response Status Code = ${respStatusCode}`);
  if (respStatusCode >= 400) {
    console.log('Response Header:');
    console.log(http.lastHeader);
    console.log('Failed.');
    return;
  }

  // Sample JSON response:

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

  const url = jResp.stringOf('url');

  // Download to a .mp3 file
  try {
    await http.downloadAsync(url, 'call_recordings/CAL11df32690b7d46123456789123456789.mp3');
    console.log('success.');
  } catch {
    console.log(http.lastErrorText);
  }
}