API Updates 5/4

- Fixed an issue where adding a contact via the API returned invalid results when there were more than 50 contacts in the system. (v2 & v3)
- Fixed an issue with the contact object not functioning with v3 of the api (v3)
- Fixed an issue with sbusinessphone and saddress2 in the contact object (v2 & v3)
- Poll embed code is now properly escaped (v2 & v3)

Posted in API Release Notes | Leave a comment

API Updates 3/19

All updates for API v3 unless otherwise noted. Note that some of these updates were released prior to locking v1 and v2, the documentation of the fixes was just a little late.

- API now properly returns all translations for fields with multiple languages entered.
- Survey object properly displays embed codes if one or more are available. (v1, v2 and v3)
- “Publish” link (found under the survey object inside “Links” array) is no longer truncated when requeting xml format. (v1, v2 and v3)
- API now returns “Alias/Short Name” information for questions. Found under SurveyQuestion object, field name: “shortname” (v1, v2 and v3)

Updates to the Contact object (survey/{surveyID}/surveycampaign/{campaignID}/contact)
- Can now see fields estatus and esubscriberstatus
- esubscriberstatus is updated when emails are sent. Possible values are unsent, sent, unsubscribed and bounced
- Can now set/change estatus through the app (not the API) to Active, Deleted, Unsubscribed

- Can now submit “other/please specify” data. (v1, v2 and v3)
Example:
&data[2][10001]=otherreportingvalue
&data[2][10001-other]=othertextboxvalue

Posted in API Release Notes | Leave a comment

v1 and v2 locked

Development of new features is no longer being done for v1 and v2 of the REST API. All development of new features is currently being done on v3 of the REST API.

Posted in API Release Notes | Leave a comment

API v3 released

XML returned by v3 of the API includes underscores normally found in other formats.

Children of the “data” node are named _#, where # is the index.

eg.

<data>
  <_0>…</_0>
  <_1>…</_1>
</data>

Posted in API Release Notes | Leave a comment

Head will point to V2 (version 2) beginning Monday 2/27

API calls pointing to restapi.surveygizmo.com/head/ will point to restapi.surveygizmo.com/v2/ beginning Monday, February 27th. Currently, head points to v1.

In order to access new updates, you will want to update your calls to v2 or head. However, if you prefer to remain on V1, you may continue to use restapi.surveygizmo.com/v1/

Posted in API Release Notes | Leave a comment

User & Permission Impact to the API

As some of you have noticed, the past week has been a bit bumpy with a few releases impacting the API — our apologies! The good news is that these issues should be resolved, and also that we have added our version 2 or v2 of the restful API, which will make it easier to expand functionality and access using the API with less impact on your existing development.

Continue reading

Posted in API Release Notes | Leave a comment

XML result format now includes cdata tags

For many of our API users, XML results without cdata tags could be problematic. One errant < or > and things break. For some time the data has not included these tags and this has been updated. The default setting is to have calls for SurveyResponse now include the cdata tags.

Continue reading

Posted in Uncategorized | Leave a comment

PHP code to build an array of response data

Some users have requested example scripts to parse the basic survey response array into something more malleable for working with the data. The following example is very similar to code we use to organize survey data into an array that is easier to work with, at least within PHP.

/**

*  splitFieldName – Splits a returned field name (the merge codes) and splits it up into an array via regex
*  @param string $fieldname Field to split
*  @return mixxed array with result or error
* */
public static function splitFieldNames($fieldname)
{
//Added error protection (if it’s an array we’ll assume its in field_return format)
if(is_array($fieldname))
return $fieldname;
if(!is_string($fieldname))
return false;
$fieldname = stripslashes($fieldname);
// Use regex to pull out the field names – Identical to Query, can be replaced if Query’s gets changed
$pattern = ’/\\[(question|url|variable|calc|comment)\\(("(?:\\\\"|[^"])+”|\d+)\\)’;
$pattern .= ’(?:\\s?,\\s?option\\((“(?:\\\\”|[^"]){0,}”|\d{0,})\\))?’;
$pattern .= ’(?:\\s?,\\s?question_pipe\\(‘ . ’(“‘ . ’(?:\\\\”|[^"])’ . ’{0,}”|\d{0,})’ . ’\\))?’;
$pattern .= ’(?:\\s?,\\s?page_pipe\\((“(?:\\\\”|[^"]){0,}”|\d{0,})\\))?’;
$pattern .= ’(?:\\s?,\\s?(select))?’;
$pattern .= ’(?:\\s?,\\s?(concat))?’;
$pattern .= ’(?:\\s?,\\s?(any))?’;
$pattern .= ’(?:\\s?,\\s?(all))?’;
$pattern .= ’(?:\\s?,\\s?(delimit))?’;
$pattern .= ’(?:\\s?,\\s?(lines))?’;
$pattern .= ’\\]/’;
$match_count = preg_match_all($pattern, $fieldname, $matches);
if ($match_count == 0)
return false;
$type = addslashes(stripslashes($matches[1][0]));
$variable = is_numeric($matches[2][0]) ? intval($matches[2][0]) : stripslashes(substr($matches[2][0], 1, -1));
$option = is_numeric($matches[3][0]) ? intval($matches[3][0]) : stripslashes(substr($matches[3][0], 1, -1));
$question_pipe = is_numeric($matches[4][0]) ? intval($matches[4][0]) : stripslashes(substr($matches[4][0], 1, -1));
$page_pipe = is_numeric($matches[5][0]) ? intval($matches[5][0]) : stripslashes(substr($matches[5][0], 1, -1));
$select = $matches[6][0] == ”select” ? true : false;
$concat = $matches[7][0] == ”concat” ? true : false;
$any = $matches[8][0] == ”any” ? true : false;
$all = $matches[9][0] == ”all” ? true : false;
$delimit = $matches[10][0] == ”delimit” ? true : false;
$lines = $matches[11][0] == ”lines” ? true : false;
// build the array for return
$field_return = array(
“type” => $type,
“id” => $variable,
“optionid” => $option,
“question_pipe” => $question_pipe,
“page_pipe” => $page_pipe,
“select” => $select,
“concat” => $concat,
“any” => $any,
“all” => $all,
“delimit” => $delimit,
“lines” => $lines
);
return $field_return;
}
Posted in REST API Sample Code | Leave a comment

New custom scripting documentation

One of the things we’ve been working on is a new way to present our documentation. As I’m sure you’ve noticed we have a ton of custom scripting functions, and the organization and presentation could be improved. So, to see what you all think, we’ve decided to post an early version of what we’re working on!

Before you head over to the new documentation, there are a few things that you should know:

  • This is a very early version, and is not complete. There are examples for only a handful of functions, and you may encounter some glitches.
  • You may experience slowness loading this site. This is because it is not yet hosted on SurveyGizmo’s live servers (because we’re still making frequent changes). If you get an error message while trying to load the page, try refreshing the page. Don’t worry though, it’ll be much faster by the time we officially launch it.
  • Some of the functions may not work, or they may be improperly documented. There have been quite a few changes since this documentation was updated, so we’re also checking to see if each function still works properly. If you encounter any of these problems, feel free to contact us.

You can email any feedback you have to dan@sgizmo.com. This is the reason we’re putting it up, so please let us know what you think!

Now, without further ado: http://forplayplay.com/SurveyGizmo/beta/CSDoc/CSDoc.html

If you’d like a couple of tips on how to use the documentation…

  1. Click on a function to open a description and example.
  2. Functions that currently have examples are highlighted yellow. This will be removed once every function has an example.
  3. Click on any of the categories at the top to filter functions by that category.
  4. Use the search box to search for functions by name.
  5. Next to most functions, you’ll see a “2″, “3″, or “B”. This refers to the version of SurveyGizmo that function will work in: 2 only, 3 only, or both.
Posted in Uncategorized | Leave a comment

PHP Curl call to pull survey response data

Here’s a PHP example that uses Curl to pull response data for a single survey. Please use this forum thread for any questions or discussions of this example: http://developer.surveygizmo.com/forum/topic/php-curl-example

<?php
/**
* This script is a example of how to do a basic curl call to the SurveyGizmo Restful API to retrieve
* responses for a given survey and display results.
* More documentation on the Restful API can be found at http://developer.surveygizmo.com/
* @author Seth McClaine, SurveyGizmo Web Developer
* 9/20/2011
**/

//Required Fields
$user = 'seth@sgizmo.com'; //Email address used to log in
$pass = 'password'; //Passord used to log in
$survey = '123456';//Survey to pull from

//Options Filter examples, uncomment to see theese in use
#$status = "&filter[field][1]=status&filter[operator][1]==&filter[value][1]=Complete";//Only show complete responses
#$datesubmmitted = "&filter[field][0]=datesubmitted&filter[operator][0]=>=&filter[value][0]=2011-02-23+13:23:28";//Submit date greater than 2/23/2011 at 1:23:28 PM

//Restful API Call URL
$url ="https://restapi.surveygizmo.com/v1/survey/{$survey}/surveyresponse?user:pass={$user}:{$pass}{$status}{$datesubmmitted}";
echo $url;

//Curl call
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);

//The standard return from the API is JSON, decode to php. (It is also possible to request a PSON, PHP object, back. See documentation for more details)
$output= json_decode($output);

//If there are no responses, display an error (Either if the filter is to strong or the given survey does not have responses)
if($output->total_count<1)
{
        die('<h3>No responses found</h3>');
}

//Run through responses
foreach($output->data as $response)
{
        $count++;
        unset($row);
        foreach($response as $key => $value)
        {
                if($count == 1)
                {
                        $header .= "<th>{$key}</th>";
                }
                $row .= "<td>{$value}</td>";
        }
        $trows[] = "<tr>{$row}</tr>";
}

//Display results in a table
echo "<table border='1'>";
echo "<tr>{$header}</tr>";
echo join($trows);
echo "</table>";
?>

Posted in REST API Sample Code | Leave a comment