Querying Your Data V2

Note

The Wufoo API has changed! This page contains the documentation for API Version 2.0. If you’re looking for API Version 1.0, please follow this link. Also, we ask that you convert any dependent apps to the new API style. Some time in the near future we’ll remove access to the 1.0 version, so please begin making your changes now.


The URL Pattern

The URL you use tells Wufoo what data to return to you. To query Wufoo, use the URL below, and substitute the subdomain mashup with your Wufoo username.

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

Example - Intro

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

Example - Build 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_version' => '2.0',
    '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.

Example - Send 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.

Where is the documentation for API V1.0?

We’ve revamped the query API. Below are the links to the old documentation:

Why did you change the API?

We use the same API that you do to access data. In the process of adding Likert fields and other advanced features, we found our old API style quite limiting. Because we dislike limitations and think you do, we added created a whole new infrastructure which we like very much. In order to keep you up-to-date, we published the API.

Will the old API still work?

Version 1.0 of the query API will continue to work for the time being. Likert fields will be returned as standard text fields. Be aware, however, that the 1.0 version of the API will go away, so make efforts to switch your apps to the new standard.

Updated : July 17th, 2009