Free PamFax API
The PamFax API is completely free for developers. Deploy fax services easily and at no cost.
Samples
To get you started we’ve written PHP, Python, Ruby and Bash samples. If you want to use the PamFax API with another language, please contact us and we’ll try to help you get going.
PHP Samples
Our PHP reference implementation is required to run the following samples. Login to the PamFax API Frontend and download the code. Unpack into your server root. Then include the pamfax_api.php file and if you want to use the wrapper classes: call pamfax_use_static() or pamfax_use_instance()
// include the PamFax API client and set your credentials require_once('pamfax_api.php'); $GLOBALS['PAMFAX_API_URL'] = "https://api.pamfax.biz/"; $GLOBALS['PAMFAX_API_APPLICATION'] = "your API key here"; $GLOBALS['PAMFAX_API_SECRET_WORD'] = "your API secret word here"; // tell the API client to create objects from returned XML automatically $GLOBALS['PAMFAX_API_MODE'] = ApiClient::API_MODE_OBJECT; // tell the API client to use static wrapper classes pamfax_use_static(); // verify the PamFax user (this is the same as used on https://portal.pamfax.biz etc to login): $result = SessionApi::VerifyUser('test_user','test_users_password'); if( !isset($result['UserToken']) || !isset($result['User']) ) die("Unable to login"); // set the global usertoken $GLOBALS['PAMFAX_API_USERTOKEN'] = $result['UserToken']->token; // optionally remember the user for later use $currentUser = $result['User']; |
// do everything from sample 1 require_once('sample_001.php'); // create a new fax and give the users IP, UserAgent and an origin FaxJobApi::Create($_SERVER['REMOTE_ADDR'],$_SERVER['HTTP_USER_AGENT'],'API Samples'); // add a recipient to the fax FaxJobApi::AddRecipient('+15752087007','Optional name of recipient'); // set the cover to template 1 and the text to some value FaxJobApi::SetCover(1,'This is my test fax using the PamFax API'); // wait for the API to prepare the fax do { sleep(5); $test = FaxJobApi::GetFaxState(); if( !isset($test['FaxContainer']) ) die("Error preparing the fax"); }while( $test['FaxContainer']->state != "ready_to_send" ); // finally send it FaxJobApi::Send(); |
require_once('sample_001.php'); // create a new fax and give the users IP, UserAgent and an origin FaxJobApi::Create($_SERVER['REMOTE_ADDR'],$_SERVER['HTTP_USER_AGENT'],'API Samples'); // add 3 recipients to the fax FaxJobApi::AddRecipient('+15752087007','Recipient 1'); FaxJobApi::AddRecipient('+495822947714','Recipient 2'); // use the prefix '@' with the $full_path_to_local_file to tell api-client it shall upload a file $postdata = array( 'file' => "@".$full_path_to_local_file, 'filename' => $name_of_file ); FaxJobApi::AddFile($postdata); // wait for the API to prepare the fax do { sleep(5); $test = FaxJobApi::GetFaxState(); if( !isset($test['FaxContainer']) ) die("Error preparing the fax"); }while( $test['FaxContainer']->state != "ready_to_send" ); // finally send it FaxJobApi::Send(); |
Python Sample
You can use the dynaptio-pamfax package to access the PamFax API from Python. The pip command can be used to install the package.
On Ubuntu, pip can be installed via sudo apt-get install python-pip. To install dynaptico-pamfax use: sudo pip install dynaptico-pamfax
Further information on the Python package is available from http://github.com/dynaptico/pamfaxp.
Example: send a fax with a cover text
#!/usr/bin/env python import time from pamfax import PamFax HOST = 'api.pamfax.biz' USERNAME = 'standard pamfax account username' PASSWORD = 'standard pamfax account password' APIKEY = 'your API key here' APISECRET = 'our API secret word' pamfax = PamFax(USERNAME, PASSWORD, host=HOST, apikey=APIKEY, apisecret=APISECRET) pamfax.create() response = pamfax.list_available_covers() pamfax.set_cover(response['Covers']['content'][1]['id'], 'My test fax with PamFax using Python') pamfax.add_recipient('+15752087007') while True: fax_state = pamfax.get_state() if fax_state['FaxContainer']['state'] == 'ready_to_send': break time.sleep(2) pamfax.send() |
Ruby Sample
This sample is taken from the PamFax ruby library, developed by our partner Tropo.
Sample: Send a fax with a cover sheet and a PDF file to multiple recipients
require 'rubygems' require 'lib/pamfaxr' require 'awesome_print' PAMFAX_URI = 'https://api.pamfax.biz/' PAMFAX_USERNAME = 'username' PAMFAX_PASSWORD = 'password' # You may also specificy a custom :api_key and :api_secret, or it uses the default pamfaxr = PamFaxr.new :base_uri => PAMFAX_URI, :username => PAMFAX_USERNAME, :password => PAMFAX_PASSWORD # Create a faxjob faxjob = pamfaxr.create_fax_job ap 'Creating a fax job' ap '*'*10 ap faxjob # Add a cover covers = pamfaxr.list_available_covers ap 'Listing available covers' ap '*'*10 ap covers ap 'Adding a cover' ap '*'*10 ap pamfaxr.set_cover(covers['Covers']['content'][1]['id'], 'Foobar is here!') ap 'Adding a remote file' ap '*'*10 ap pamfaxr.add_remote_file('https://s3.amazonaws.com/pamfax-test/Tropo.pdf') ap 'Adding a local file' ap '*'*10 file = pamfaxr.add_file('examples/Tropo.pdf') ap file ap 'Removing a file' ap '*'*10 ap pamfaxr.remove_file(file['FaxContainerFile']['file_uuid']) ap 'Adding a recipient' ap '*'*10 ap pamfaxr.add_recipient('+15752087007') ap 'Adding a second recipient' ap '*'*10 recipient = pamfaxr.add_recipient('+495822947714') ap recipient ap 'Removing a recipient' ap '*'*10 ap pamfaxr.remove_recipient(recipient['FaxRecipient']['number']) ap 'Listing a recipient' ap '*'*10 ap pamfaxr.list_recipients ap 'Listing associated fax files' ap '*'*10 ap pamfaxr.list_fax_files ap 'Checking state' ap '*'*10 time = 0 loop do fax_state = pamfaxr.get_state ap fax_state converting = true break if fax_state['FaxContainer']['state'] == 'ready_to_send' sleep 2 time += 2 ap "#{time.to_s} seconds elapsed..." end ap 'Preview the fax' ap '*'*10 ap pamfaxr.get_preview(faxjob['FaxContainer']['uuid']) ap 'Sent the fax' ap '*'*10 ap pamfaxr.send_fax ap 'Sent the fax later' ap '*'*10 ap pamfaxr.send_fax_later ap 'Cloning the fax' ap '*'*10 ap pamfaxr.clone_fax(faxjob['FaxContainer']['uuid']) |
BASH Sample
Save the code to a file named sendpamfax.sh and then call this script via command line like: ./sendpamfax.sh apikey apisecret username password faxnumber faxcontent
Sample: Send a fax with a bash script using a CURL library
#!/bin/bash # Send a fax using bash, curl, sed and the PamFax API # check the number of arguments if [ $# -ne 7 ] then echo "USAGE: $0 apikey apisecret username password faxnumber faxcontent filename" exit 1 fi # protocol and server export url_start="https://api.pamfax.biz/" # common parameters used in all API calls, taken from commandline export url_params="/?apikey=$1&apisecret=$2" # create a session export xml_result=`curl -k --silent "$url_start/Session/VerifyUser$url_params&username=$3&password=$4"` # todo: error handling / check for success # extract the user token from the XML response export usertoken=`echo $xml_result | sed '/UserToken/!d;s/.*token="\([^"]*\)".*/\1/'` if [ "$usertoken" == "" ] then echo "Session/VerifyUser failed" exit 1 fi # add usertoken to common url parameters for this session export session_params="$url_params&usertoken=$usertoken" # create a new fax job export user_ip=`hostname -i` export xml_result=`curl -k --silent "$url_start/FaxJob/Create$session_params&user_ip=$user_ip&user_agent=pamfax_send.sh&origin=shell"` # todo: error handling / check for success # Add the recipient export xml_result=`curl -k --silent "$url_start/FaxJob/AddRecipient$session_params&number=$5"` # todo: error handling / check for success # Use Basic template for the cover page # Available templates can be listed using FaxJob/ListAvailableCovers export template_id=1 # Add the cover page using the text provided on the commandline export xml_result=`curl -k --silent "$url_start/FaxJob/SetCover$session_params&template_id=$template_id&text=$6"` # todo: error handling / check for success # Upload the given file export xml_result=`curl -k --silent --form file=@$7 --form filename=$7 "$url_start/FaxJob/AddFile$session_params"` # loop until the fax is ready export ready=1 while [ $ready -ne 0 ] do # wait for 5 seconds sleep 5 # Query the fax state export xml_result=`curl -k --silent "$url_start/FaxJob/GetFaxState$session_params"` # Note that the response will also contain pricing information # look for state="ready_to_send" echo $xml_result | grep 'state="ready_to_send"' export ready="$?" done #Send the fax export xml_result=`curl -k --silent "$url_start/FaxJob/Send$session_params"` echo $xml_result |