Posting xml to faxfinder via PHP and curl

Home Forums FaxFinder Posting xml to faxfinder via PHP and curl

Tagged: , ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2641
    Aaron C
    Participant

    I’m trying to POST the xml to the Faxfinder using php, but I’m not having any success. I am accessing the Faxfinder, I’m getting 400 error codes, and messages of internal error.

    I really have to have this working as soon as possible, below is a test script I’ve been trying to get working, could someone offer me some guidance?

    <?php

    // wonderful variables to internet

    $url = “http://10.10.10.44/ffws/v1/ofax&#8221;;

    $subject = ‘test’;

    $comments = ‘test’;

    $sender_name = ‘person_api’;

    $sender_org = ‘testapi’;

    $sender_phone = ‘1233’;

    $sender_fax = ‘8085551111’;

    $sender_email = ‘herp@derp.com’;

    $rcp_name = ‘george orwell’;

    $rcp_fax = ‘8017725555’;

    $rcp_phone = ‘5555555555’;

    $file = ‘/var/test/test.pdf’;

    $content_type = ‘application/pdf’;

    $tries = ‘3’; // default is 3

    $try_interval = ’30’;

    $priority = ‘3’;

    $receipt = ‘true’;

    $receipt_attachment = ‘none’;

    // Attachment type must be one of:

    // application/pdf

    // application/postscript

    // text/plain

    // image/tiff

    //Get contents of PDF file into a string

    $filename = $file;

    $handle = fopen($filename, “r”);

    $contents = fread($handle, filesize($filename));

    fclose($handle);

    //Base 64 encode the data (converts from binary to only ASCII characters)

    $contents = base64_encode($contents);

    $post_string = ‘<?xml version=”1.0″ encoding=”UTF-8″?>

    <schedule_fax>

    <cover_page>

    <enabled>false</enabled>

    <subject>’.$subject.'</subject>

    <comments>’.$comments.'</comments>

    </cover_page>

    <sender>

    <name>’.$sender_name.'</name>

    <organization>’.$sender_org.'</organization>

    <phone_number>’.$sender_phone.'</phone_number>

    <fax_number>’.$sender_fax.'</fax_number>

    <email_address>’.$sender_email.'</email_address>

    </sender>

    <recipient>

    <name>’.$rcp_name.'</name>

    <fax_number>’.$rcp_fax.'</fax_number>

    <phone_number>’.$rcp_phone.'</phone_number>

    </recipient>

    <attachment>

    <location>inline</location>

    <name>’.$filename.'</name>

    <content_type>’.$content_type.'</content_type>

    <content_transfer_encoding>base64</content_transfer_encoding>

    <content>’.$contents.'</content>

    </attachment>

    <max_tries>’.$tries.'</max_tries>

    <priority>’.$priority.'</priority>

    <try_interval>’.$try_interval.'</try_interval>

    <receipt>’.$receipt.'</receipt>

    <receipt_attachment>’.$receipt_attachment.'</receipt_attachment>

    <schedule_all_at>2011-11-06T20:30:00</schedule_all_at>

    </schedule_fax>’;

    //echo $post_string;

    //* Define POST URL and also payload

    define(‘XML_PAYLOAD’, $post_string);

    define(‘XML_POST_URL’, $url);

    // POST xml using curl

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

    curl_setopt($ch, CURLOPT_USERPWD, “admin:admin”);

    curl_setopt($ch, CURLOPT_URL, XML_POST_URL);

    curl_setopt($ch, CURLOPT_TIMEOUT, 60);

    curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Connection: close’));

    $result = curl_exec($ch);

    if(curl_errno($ch)) {

    $result = ‘ERROR -> ‘.curl_errno($ch).’: ‘.curl_error($ch);

    } else{

    $returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);

    switch($returnCode){

    case 404:

    $result = ‘ERROR -> 404 Not Found’;

    break;

    default:

    break;

    }

    }

    //Close the handle

    curl_close($ch);

    echo $result;

    echo $returnCode;

    exit(0)

    ?>

    #3415
    Bryan Tran
    Moderator

    Hi Aaron,

    Try this sample code and see if it works for you: https://webfiles.multitech.com/engineering/sample-code/fax-finder/php/

    Regards,

    BT

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘FaxFinder’ is closed to new topics and replies.