Created
November 10, 2011 00:58
-
-
Save michaelespinosa/1353743 to your computer and use it in GitHub Desktop.
Using the v3 of the Wufoo API to retrieve all entries and store in a single array ($all_results). This is necessary because of the limit 100 entries limit that Wufoo has.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Setup | |
$account = "YOUR_ACCOUNT_NAME"; | |
$form = "FORM_ID"; | |
$api_key = "API_KEY"; | |
$offset = 0; | |
$limit = 100; | |
$all_results = array(); | |
// How many entries are there? | |
$api_uri = "https://$account.wufoo.com/api/v3/forms/$form/entries/count.json"; | |
$count = wufoo_api($api_key, $account, $form, $offset, $limit, $api_uri); | |
$counted = $count['EntryCount']; | |
// Call the api and push results to $all_results array | |
for ($offset = 0; $offset <= $counted - 1; $offset = $offset + $limit) { | |
$results = wufoo_api($api_key, $account, $form, $offset, $limit); | |
$limit = (($offset + $limit) > $counted) ? $limit - (($offset + $limit) - $counted) : $limit; | |
for ($result = 0; $result <= $limit - 1; $result++) { | |
array_push($all_results, $results['Entries'][$result]); | |
} | |
} | |
// Get the entries | |
function wufoo_api($api_key, $account, $form, $offset, $limit, $api_uri = NULL) { | |
$api_url = ($api_uri) ? $api_uri : 'https://' . $account . '.wufoo.com/api/v3/forms/' . $form . '/entries.json?pageStart=' . $offset . '&pageSize=' . $limit; | |
$curl = curl_init($api_url); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($curl, CURLOPT_USERPWD, $api_key . ':footastic'); | |
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); | |
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_USERAGENT, 'Wufoo Sample Code'); | |
$response = curl_exec($curl); | |
$resultStatus = curl_getinfo($curl); | |
if ($resultStatus['http_code'] == 200) { | |
$results = json_decode($response, true); | |
return $results; | |
} else { | |
$results = 'Call Failed '.print_r($resultStatus, true); | |
return $results; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment