Zig
Zig
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 Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
var success: bool = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
// 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 sb_response_body = try chilkat.StringBuilder.init();
defer sb_response_body.deinit();
success = if (http.quickGetSb("https://api.callrail.com/v3/a/{account_id}/calls/{call_id}/recording.json", sb_response_body)) true else |_| false;
if (!success) {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
}
const j_resp = try chilkat.JsonObject.init();
defer j_resp.deinit();
j_resp.loadSb(sb_response_body) catch {};
j_resp.setEmitCompact(false);
std.debug.print("Response Body:\n", .{});
std.debug.print("{s}\n", .{try j_resp.emit(alloc)});
const resp_status_code = http.getLastStatus();
std.debug.print("Response Status Code = {d}\n", .{resp_status_code});
if (resp_status_code >= 400) {
std.debug.print("Response Header:\n", .{});
std.debug.print("{s}\n", .{try http.getLastHeader(alloc)});
std.debug.print("Failed.\n", .{});
return;
}
// Sample JSON response:
// {
// "url": "http://app.callrail.com/calls/CAL11df32690b7d46123456789123456789/recording/redirect?access_key=241sa242sadqwerty123"
// }
const url = try j_resp.stringOf(alloc, "url");
// Download to a .mp3 file
success = if (http.download(url, "call_recordings/CAL11df32690b7d46123456789123456789.mp3")) true else |_| false;
if (!success) {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
} else {
std.debug.print("success.\n", .{});
}
}