PHP Example

Assuming that you had 1 supporter in your organization.... Output the following:
VALUE -> DATA: Tue Oct 07 2008 10:35:52 GMT-0400 (EDT)
Given the following code:
<?php

$url = "https://sample.nodeurl.tld/api"; # URL to DIA API
$username = ""; # Campaign Manager username goes here
$password = ""; # Campaign Manager password goes here

//method #1 for building post objects to send to Salsa
$authfields["email"] = $username;
$authfields["password"] = $password;

//method #2 for building post objects to send to Salsa
//  note:  unless you have a small number of supporters, this will fail.
//  try remving the 'groupBy' => 'Date_Created' statement.
$fields = array('object' => 'supporter', 'groupBy' => 'Date_Created');

//Initialize CURL connection
$ch = curl_init();


//Set basic connection parameters:
//      See http://us.php.net/curl_setopt for more information on these settings
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);

//Set Parameters to maintain cookies across sessions
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookies_file');
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookies_file');


//Execute connection to authenticate to Salsa
//
//	https://sandbox.salsalabs.com/api/authenticate.sjs?email=1&password=1
//
curl_setopt($ch, CURLOPT_URL, "$url/authenticate.sjs");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($authfields));
$auth = curl_exec($ch);

//Execute query to return data back to the User/Application
//
//	https://sandbox.salsalabs.com/api/getCounts.sjs?object=supporter&groupBy=Date_Created
//
curl_setopt($ch, CURLOPT_URL, "$url/getCounts.sjs");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
$count = curl_exec($ch);

//Close the connection
curl_close($ch);

//Populate results from salsa into SimpleXML object
//	See http://us3.php.net/manual/en/book.simplexml.php for more information
//	on SimpleXML objects in PHP
$response = simplexml_load_string($count);

//Parse SimpleXML object and display Date_Created for each entry to the screen.
foreach($response->supporter->count AS $data){
                echo "VALUE -> DATA: ";
                echo $data->Date_Created . "\n <br/>\n";
}

?>