Passing parameters: via POST is harder but has the advantage that the Parameters: do not appear in the URL.
Calling from a server
If the API is to be called from a server script (probably in PHP), the recommended way to pass Parameters: via POST is to use the CURL functions.
For example:
<?php // Function call_api evokes the ARPreach API using POST data // // $url: URL of your ARPreach site // $api: The api function // $api_key: Your api key // $use_xml: Set TRUE to return XML, FALSE for JSON // $Parameters: to the function Function call_api($url, $api, $use_xml, $api_key, $Parameters) { $ch = curl_init(); if ($use_xml) { $xmlstr = "/xml"; } else { $xmlstr = "/json"; } curl_setopt($ch, CURLOPT_URL, $url . $api . $xmlstr); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $api_key . $Parameters); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch); curl_close($ch); return $result; } ?>
This function could be used thus:
// URL of your arpreach installation $url = "http://example.com/a.php/api/"; // Set this to 0 to receive response by JSON, or 1 to receive response by XML $use_xml = 0; // Your API key $api_key = "XYZ"; // API function to call $api = "add_contact"; // Set paramaters of api call $Paramaters = array( 'email_address' => 'joe@bloggs.com', 'lists' => array( array( 'list' => 'Sales', 'format_preference' => 1, 'next_message' => 2 ) ) ); $Paramaters = json_encode($Paramaters); $return = call_api($url, $api, $use_xml, $api_key, $Parameters);