SubmitSurveyData
The SubmitSurveyDataAPI enables posting of survey answers to the Frankly Media system. As a prerequisite, the consumer of this API must have the FM identifiers of the survey, associated questions and answers, which can be obtained by calling the LoadSurvey API.
How to call
The method accepts an XML node with the information about the survey, associated questions and answers. This request is an http post. The contenttype attribute must be set to application/XML. The body of the post must be in the following format:
[xml]<SubmitSurveyData xmlns=”http://www.tritonloyalty.com/ISubscriptions” xmlns:i=”http://www.w3.org/2001/XMLSchema-instance”>
<data xmlns:a=”http://www.tritonloyalty.com/datacontract/MemberSurveyDO” xmlns:i=”http://www.w3.org/2001/XMLSchema-instance”>
<a:SID>52282</a:SID>
<a:MemberID>21324014</a:MemberID>
<a:SiteID>1562</a:SiteID>
<a:Answers xmlns:b=”http://www.tritonloyalty.com/datacontract/MemberAnswersDO”>
<b:MemberAnswersDO>
<b:QuestionID>117160</b:QuestionID>
<b:Answer>556120</b:Answer>
</b:MemberAnswersDO>
<b:MemberAnswersDO>
<b:QuestionID>117161</b:QuestionID>
<b:Answer>Certainly</b:Answer>
</b:MemberAnswersDO>
<b:MemberAnswersDO>
<b:QuestionID>117162</b:QuestionID>
<b:Answer>556123</b:Answer>
</b:MemberAnswersDO>
</a:Answers>
</data>
<partnerName>CCNY</partnerName>
<token>83321D4D470186A6858987C0F932E122</token>
<timestamp>20101029153000</timestamp>
</SubmitSurveyData>;
[/xml]
Description of the nodes
- data node contain the information about the survey. SID is the unique ID of the survey. Each answer node has the QuestionID value which corresponds to the QuestionID node
in the LoadSurvey API - partnerName node is unique identifier of the 3rd party calling the API. This information must be requested from Triton Loyalty in order to use any API methods
- token – An encrypted string constructed using the passed-in parameters and the partner-specific “shared secret” provided by the Frankly Media. Unless requested differently by the partner, the MD5 hashing algorithm is used to produce the token. For the purpose of this call the following formula should be used: md5(memberID + shared secret). For the generic example refer to this article.
- timestampVerification timestamp. UTC time of the client call. Must be in the following format: YYYYMMDDHHmmss
Return Value
The following XML structure is returned in the success scenario:
[xml]
<surveyreceipt xmlns=”http://schemas.datacontract.org/2004/07/ListenerAPI.DataObjects” xmlns:i=”http://www.w3.org/2001/XMLSchema-instance”>
<totalRespondents>82</totalRespondents><totalpoints>5000</totalpoints><credit>400</credit><answerStats><stats><QuestionID>21345</QuestionID><AnswerID>98709</AnswerID><answerTotal>2</answerTotal></stats></answerStats></surveyreceipt>[/xml]
In the case of an error, a SynchError node will be returned by the service. The explanation of the error will be embedded in the messageText node.
Here is an example of the XML structure:
[xml]<SynchError xmlns=”http://schemas.datacontract.org/2004/07/ListenerAPI.DataObjects” xmlns:i=”http://www.w3.org/2001/XMLSchema-instance”>
<messageText>Request declined. Invalid token for partner CLRCHNNY. System.Exception: Validation of the checksum failed</messageText></SynchError>[/xml]
Examples
Here is an example of this API call from PHP:
[xml]
<?php
class cURL
{
var $headers;
var $user_agent;
var $compression;
var $cookie_file;
var $proxy;
function cURL($cookies=TRUE,$cookie=’cookies.txt’,$compression=’gzip’,$proxy=”)
{
$this->headers[] = ‘Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg’;
$this->headers[] = ‘Connection: Keep-Alive’;
$this->headers[] = ‘Content-type: application/xml;charset=UTF-8’;
$this->user_agent = ‘Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)’;
$this->compression=$compression;
$this->proxy=$proxy;
$this->cookies=$cookies;
if ($this->cookies == TRUE)
$this->cookie($cookie);
}
function cookie($cookie_file)
{
if (file_exists($cookie_file))
{
$this->cookie_file=$cookie_file;
}
else
{
fopen($cookie_file,’w’) or $this->error(‘The cookie file could not be opened. Make sure this directory has the correct permissions’);
$this->cookie_file=$cookie_file;
fclose($this->cookie_file);
}
}
function get($url)
{
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
//if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
//if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
curl_setopt($process,CURLOPT_ENCODING , $this->compression);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
if ($this->proxy)
curl_setopt($process, CURLOPT_PROXY, $this->proxy);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
$return = curl_exec($process);
curl_close($process);
return $return;
}
function post($url,$data)
{
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
if ($this->cookies == TRUE)
curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
if ($this->cookies == TRUE)
curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
curl_setopt($process, CURLOPT_ENCODING , $this->compression);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
if ($this->proxy)
curl_setopt($process, CURLOPT_PROXY, $this->proxy);
curl_setopt($process, CURLOPT_POSTFIELDS, $data);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false);
$return = curl_exec($process);
curl_close($process);
return $return;
}
function error($error)
{
echo “<center><div style=’width:500px;border: 3px solid #FFEEFF; padding: 3px; background-color: #FFDDFF;font-family: verdana; font-size: 10px’><b>cURL Error</b><br>$error</div></center>”;
die;
}
}
$cc = new cURL();
$url = ‘https://api.enticent.com/Subscriptions.svc/SubmitSurveyData’;
$param = ‘<SubmitSurveyData xmlns=”http://www.tritonloyalty.com/ISubscriptions” xmlns:i=”http://www.w3.org/2001/XMLSchema-instance”>
<data xmlns:a=”http://www.tritonloyalty.com/datacontract/MemberSurveyDO” xmlns:i=”http://www.w3.org/2001/XMLSchema-instance”>
<a:SID>52282</a:SID>
<a:MemberID>21324014</a:MemberID>
<a:SiteID>1562</a:SiteID>
<a:Answers xmlns:b=”http://www.tritonloyalty.com/datacontract/MemberAnswersDO”>
<b:MemberAnswersDO>
<b:QuestionID>117160</b:QuestionID>
<b:Answer>556120</b:Answer>
</b:MemberAnswersDO>
<b:MemberAnswersDO>
<b:QuestionID>117161</b:QuestionID>
<b:Answer>Certainly</b:Answer>
</b:MemberAnswersDO>
<b:MemberAnswersDO>
<b:QuestionID>117162</b:QuestionID>
<b:Answer>556123</b:Answer>
</b:MemberAnswersDO>
</a:Answers>
</data>
<partnerName>CCNY</partnerName>
<token>83321D4D470186A6858987C0F932E122</token>
<timestamp>20101029153000</timestamp>
</SubmitSurveyData>’;
/*
$param = ‘<SubmitSurveyData xmlns=”http://www.tritonloyalty.com/ISubscriptions” xmlns:i=”http://www.w3.org/2001/XMLSchema-instance”><data xmlns:a=”http://www.tritonloyalty.com/datacontract/MemberSurveyDO” xmlns:i=”http://www.w3.org/2001/XMLSchema-instance”><a:SID>52282</a:SID><a:MemberID>21324014</a:MemberID><a:SiteID>1562</a:SiteID><a:Answers xmlns:b=”http://www.tritonloyalty.com/datacontract/MemberAnswersDO”><b:MemberAnswersDO><b:QuestionID>117160</b:QuestionID><b:Answer>556120</b:Answer></b:MemberAnswersDO><b:MemberAnswersDO><b:QuestionID>117161</b:QuestionID><b:Answer>Certainly</b:Answer></b:MemberAnswersDO><b:MemberAnswersDO><b:QuestionID>117162</b:QuestionID><b:Answer>556123</b:Answer></b:MemberAnswersDO></a:Answers></data><partnerName>CCNY</partnerName><token>83-32-1D-4D-47-01-86-A6-85-89-87-C0-F9-32-E1-22</token><timestmp>20101029</timestmp></SubmitSurveyData>’;
*/
echo $cc->post($url, $param);
?>
[/xml]