Querying Your Data V1

API Beta Testing

This portion of the Wufoo API is still in development. We have placed it live to gather feedback on the structure and flexibility of the API. We encourage you to play around and leave your feedback. Be aware that the structure may change up until the public release of the API.

The Query API

Programmatically search, sort, filter, and organize data collected through your forms.

URL

Use the URL below, and substitute the subdomain mashup with your Wufoo username.

http://mashup.wufoo.com/api/query/

An Introductory Example

We’re going to walk through a very simple example to become familiarized with the Query API. To start, let’s imagine you have created a form with a URL of ‘what-is-your-name’. The form has 2 fields: ‘First Name’ and ‘Last Name’. You then collected 10 submissions to that form, shown below:

#First NameLast Name
1BobWilson
2SteveRickson
3RickJohnson
4SusySmith
5JoeGold
6KatieCampbell
7MitchHale
8AnderSabat
9ElaineWoodcrafter
10KimSong

Building the Request

Now that we have data, we will build a request to retrieve that data. Regardless of the programming language used, the POST must be formatted properly. While all of our examples are in PHP, very similar concepts will apply to all languages. Below is an example construction of a POST string to send.

// Set the Wufoo Query POST parameters
$wufoo_query_vals = array(
    'w_api_key' => '1234-5678-9012-3456',
    'w_form' => 'what-is-your-name',
    'w_sort' => '1'
);

// Generate the POST string
foreach($wufoo_query_vals as $key => $value) {
    $request .= $key.'='.urlencode($value).'&';
}

// Chop of the trailing ampersand
$request = rtrim($request, '&');

Notice that the w_sort parameter was set to 1. This tells the results to be sorted alphabetically by the field with an ID of 1. You can find your fields and their corresponding ID’s on your Wufoo API page. To learn more about what information you can send in the POST request, see the Query API parameters.

Sending the Request

Our preferred method of sending the request in PHP is by using CURL. To send the above request, the code below could be used.

$ch = curl_init("http://mashup.wufoo.com/api/query/"); 
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
curl_close ($ch);

Once executed, the $response variable will contain the XML or JSON returned by the Wufoo servers. Continuing with the example, the response would contain the data in this order:

#First NameLast Name
1AnderSabat
2BobWilson
3ElaineWoodcrafter
4JoeGold
5KatieCampbell
6KimSong
7MitchHale
8RickJohnson
9SteveRickson
10SusySmith

The reason for this is because the w_sort parameter was set to ‘First Name’, which told the request to sort results by ‘First Name’ alphabetically. For more information, view the actual format of the response.

Updated : July 16th, 2009