You would use something like LWP::UserAgent.
#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use PHP::Include; include_php_vars('file.php');
PHP::Include makes it really easy. You just need a little file.php
#file.php <?php /* * Add customer example code * Uses PHP 5 but not JSON * */ $GLOBALS['api_url'] = "https://demo.rpmsoftware.com/rpm/Api.svc/"; $GLOBALS['api_key'] = "xxxxx"; /* * An array with the customer data to add * */ $customer = array( 'name' => '111A Test Customer1', 'website' => '', 'address' => '', 'city' => '', 'stateprovince' => '', 'zippostalcode' => '', 'salutation' => '', 'first name' => '', 'last name' => '', 'title' => '', 'email' => '', 'phone' => '', // To use custom fields make 'fields' an array like this: // 'fields' => array( // 'fieldname' => 'fieldvalue' // ); // // Example: // 'fields' => array( // 'Custom text' => 'a demo value', // 'Some date' => '12/20/2009', // ); 'fields' => '' ); /* * A generic POST function * * This isn't specific to RPM, it's just a simple POST wrapper to * fopen. Any post function will do and something using CURL is * probably better: http://curl.haxx.se/libcurl/php/ * */ function req_post($url, $data, $optional_headers = null) { $params = array('http' => array( 'method' => 'POST', 'content' => $data )); if ($optional_headers !== null) { $params['http']['header'] = $optional_headers; } $ctx = stream_context_create($params); $fp = fopen($url, 'rb', false, $ctx); if (!$fp) { throw new Exception("Problem with $url"); } $response = @stream_get_contents($fp); if ($response === false) { throw new Exception("Problem reading data from $url"); } return $response; } /* * API call without JSON functions * */ function rpm_req($call, $data_string = "") { if ("" != $data_string) $data_string = ", ".$data_string; // Build the request $data = '{"Key":"'.$GLOBALS['api_key'].'" '.$data_string.' }'; // Make the request $result = req_post($GLOBALS['api_url'].$call, $data, 'Content-Type +: application/json; charset=utf-8'); // Analyse the results $response_pattern = '/\{\"[A-Za-z]+\":\"(.+)\"\}/'; $error_pattern = '/\{\\\"Error\\\":\\\"([A-za-z0-9 ]+)\\\"\}/'; if (preg_match($response_pattern, $result, $matches)) { $return = $matches[1]; if (preg_match($error_pattern, $return, $matches)) { throw new Exception("API returned error: $matches[1]"); } return $return; } else { throw new Exception("Problem with return from $url"); } } ?> <html> <head> <title>Add customer API example</title> <style> body { background: #eee; font-family: Arial, sans-serif; font-size +: small; } </style> </head> <body> <?php if (is_array($customer['fields'])) { $customer_fields = ', "Fields": ['; foreach ($customer['fields'] as $field_name => $field_value) { $customer_fields .= '{"Field":"'.$field_name.'","Value":"'.$fi +eld_value.'"},'; } $customer_fields = substr($customer_fields, 0, strlen($customer_fi +elds) - 1); // chop off the last , $customer_fields .= ']'; } else $customer_fields = ""; try { $result = rpm_req('CustomerAdd',' "Customer": { "Name": "'.$customer['name'].'", "Website": "'.$customer['website'].'", "Address": "'.$customer['address'].'", "City": "'.$customer['city'].'", "StateProvince": "'.$customer['stateprovince'].'", "Country": "United States", "ZipPostalCode": "'.$customer['zippostalcode'].'", "PrimaryContact": { "Salutation": "'.$customer['salutation'].'", "FirstName": "'.$customer['first name'].'", "LastName": "'.$customer['last name'].'", "Title": "'.$customer['title'].'", "Email": "'.$customer['email'].'", "PhoneBusiness": { "Number":"'.$customer['phone'].'"} } '.$customer_fields.' } '); echo 'Customer added'; } catch (Exception $e) { echo $e->getMessage(); } ?> </body> </html>

In reply to Re: PHP -> Perl question by Khen1950fx
in thread PHP -> Perl question by ultranerds

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.