Zig
Zig
Interfax -- Fax a Single Document
See more REST Examples
Demonstrates how to use the REST API to fax a single document using interfax.net. See Send fax for more information.This example will send a POST with these potential query params:
POST /outbound/faxes?faxNumber={faxnumber}[&contact={string}&postponeTime={datetime}
&retriesToPerform={number}&csid={string}&pageHeader={string}&reference={string}
&replyAddress={email}&pageSize={a4|letter|legal|b4}&fitToPage={scale|noscale}
&pageOrientation={portrait|landscape}&resolution={fine|standard}&rendering={greyscale|bw}]
The HTTP POST request to be sent will look like this:
POST /outbound/faxes?faxNumber={faxnumber}&... HTTP/1.1
Host: rest.interfax.net
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Content-Type: application/msword
{binary content goes here}
Note: The Content-Type header field should match type type of document. For example, use "application/pdf" to fax a PDF. To find out what content-type header field values should be used, Google "MIME content type for XYZ" where XYZ describes the type of document. For example, one might Google "MIME content type for Excel xls", and the answer would be "application/vnd.ms-excel".
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const rest = try chilkat.Rest.init();
defer rest.deinit();
// Use Basic Authentication.
// Use your InterFAX login and password.
try rest.setAuthBasic("INTERFAX_LOGIN", "INTERFAX_PASSWORD");
// Connect to the Interfax REST server.
// Make sure TLS is used. One should NEVER send a username+password using Basic authentication
// over a non-secure connection.
const b_tls = true;
const port = 443;
const b_auto_reconnect = true;
try rest.connect("rest.interfax.net", port, b_tls, b_auto_reconnect);
// Indicate the Content-Type of our upload.
// We're faxing a PDF, so set the content-type to application/pdf.
try rest.addHeader("Content-Type", "application/pdf");
// We can add an "Expect: 100-continue" header so that if the request is rejected
// by the server immediately after receiving the request header, it can respond
// and the client (Chilkat) can avoid sending the file data.
// (this is optional)
try rest.addHeader("Expect", "100-continue");
const file_stream = try chilkat.Stream.init();
defer file_stream.deinit();
// The stream's source will be a file.
file_stream.setSourceFile("qa_data/pdf/fishing.pdf");
// Add query params.
// The fax number format is "+1-212-3456789"
rest.addQueryParam("faxNumber", "MY-FAX-NUMBER") catch {};
rest.addQueryParam("pageSize", "letter") catch {};
// Add any other desired query params ...
// The response is a 0-length "201 Created" response.
// Therefore the responseStr will be empty.
_ = rest.fullRequestStream(alloc, "POST", "/outbound/faxes", file_stream) catch {
std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
return;
};
if (rest.getResponseStatusCode() != 201) {
// The response was not successful.
// We can examine the response code, header and status text:
std.debug.print("Response status code: {d}\n", .{rest.getResponseStatusCode()});
std.debug.print("Response status text: {s}\n", .{try rest.getResponseStatusText(alloc)});
std.debug.print("Response header: {s}\n", .{try rest.getResponseHeader(alloc)});
std.debug.print("FAX failed.\n", .{});
} else {
std.debug.print("FAX sent.\n", .{});
}
}