Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // See https://salsasupport.zendesk.com/entries/23514381-Definitions-for-common-terms
- // to find out to retrieve the API URL in $url.
- $url = "https://hq-org.salsalabs.com/api";
- $username = "BAGCounter"; # Campaign Manager username goes here
- $password = "oo@LL@oo"; # 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 removing the 'groupBy' => 'Date_Created' statement.
- $fields = array('object' => 'supporter_action');
- $fields2 = array('object' => 'donation');
- // Initialize cURL connection
- // * See http://us3.php.net/manual/en/book.curl.php for more information
- // on the cURL capability in PHP.
- $ch = curl_init();
- // Set basic connection parameters
- 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
- //* Example:
- // https://sandbox.salsalabs.com/api/authenticate.sjs?email=whatever&password=whatever
- 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
- // * Example:
- // 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);
- curl_setopt($ch, CURLOPT_URL, "$url/getCount.sjs?object=supporter_action");
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
- $countSupporterTotal = curl_exec($ch);
- $responseSupporterTotal = simplexml_load_string($countSupporterTotal);
- curl_setopt($ch, CURLOPT_URL, "$url/getCount.sjs?object=donation");
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields2));
- $countDonationTotal = curl_exec($ch);
- $responseDonationTotal = simplexml_load_string($countDonationTotal);
- //Close the connection
- curl_close($ch);
- $bagTotal = 2023079092;
- $bagTotal = $bagTotal + intval($responseDonationTotal->donation->count) + intval($responseSupporterTotal->supporter_action->count);
- echo number_format($bagTotal);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement