Retrieves the RedCritter rewards for a given App Domain within an App.
This version of the GetRewards command retrieve the list of rewards for an App based on the Secret Key.
https://redcritterconnecter.com/services/gamificationv1/GetRewards?SecretKey={SecretKey}
SecretKey | string | yes | This SecretKey is an App or App Domain Secret Key. If an App Secret Key is specified, your default App Domain will be assumed. If an App Domain Secret Key is specified, that App Domain will be used. |
Code Samples Javascript, C#
GetRewards with JavaScript
This is a minimal example of calling the GetRewards API via HTML and Javascript. Remember to never use your Secret Keys on the client side.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js"></script>
<style type='text/css'>
body {
font-family: "Arial";
}
.rctable{
padding-top:20px;
padding-bottom:10px;
border-bottom:solid 1px #ccc;
width:600px;
}
.rclabel {
font-size:14px;
font-weight:bold;
}
.rcval{
font-size:14px;
padding-left:10px;
}
</style>
<script type="text/javascript">
var connecterURL = "https://www.redcritterconnecter.com/";
function getRewards(secretKey, cbSuccess, cbFail) {
$.getJSON(connecterURL + "services/gamificationv1/getRewards?jsoncallback=?", { secretKey: secretKey },
function (data) {
if (data.Result) {
cbSuccess(data);
} else {
cbFail(data);
}
});
}
//My Success Callback
function onMyGetRewardsSuccessHandler(data) {
//data is JSON response
renderRewards(data)
}
//My Failure Callback
function onMyGetRewardsFailHandler(data) {
//Something went wrong
alert("Something went wrong");
}
//Sample function to generate the rewardslist output in html
function renderRewards(data) {
var h = "";
if (data.Rewards.length == 0) {
// no rewards
h = "Sorry, this rewards store is currently empty. Check back later.";
} else {
//render each reward
for (var i = 0; i < data.Rewards.length; i++) {
h = h+ generateRewardItemHTML(data.Rewards[i]);
}
}
//display the results
$("#results").html(h);
}
function generateRewardItemHTML(reward) {
var h = "<table class='rctable'>";
h += "<tr><td class='rclabel'>Reward Name : </td><td class='rcval'>" + HTMLEncode(reward.RewardName) + "</td></tr>"
h += "<tr><td class='rclabel'>Description : </td><td class='rcval'>" + HTMLEncode(reward.Description) + "</td></tr>";
h += "<tr><td class='rclabel'>Avail Qty : </td><td class='rcval'>" + reward.AvailQty + "</td></tr>";
h += "<tr><td class='rclabel'>Cost : </td><td class='rcval'>" + reward.Cost + "</td></tr>";
h += "<tr><td class='rclabel'></td><td class='rcval'><img src='" + reward.ImageURL + "'/></td></tr>";
h += "</table>";
return h
}
function HTMLEncode(str) {
var div = document.createElement('div');
var text = document.createTextNode(str);
div.appendChild(text);
return div.innerHTML;
}
</script>
</head>
<body>
<table>
<tr>
<td>Secret Key</td>
<td>
<input type="text" id="tSecretKey" style="width: 500px" />
</td>
</tr>
<tr>
<td></td>
<td>
<input type="button" onclick="getRewards($('#tSecretKey').val(), onMyGetRewardsSuccessHandler, onMyGetRewardsFailHandler)" value="Get Rewards" /></td>
</tr>
</table>
<br />
<div id="results"></div>
</body>
</html>
GetRewards with C#
This is a minmal example of calling the GetRewards API and parsing the JSON result into a populated C# object. This example uses asynchronous techniques to raise a callback when the response is received.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using System.Web; //Add reference to System.Web
using System.Runtime.Serialization.Json; //Add reference to System.Runtime.Serialization
namespace RedCritterConnecter.Samples
{
//Create a class to contain the response
public class GetRewardsResponse
{
public Int64 UserID { get; set; }
public String TeamID { get; set; }
public String ProfileEntity { get; set; }
public Int64 AppID { get; set; }
public Int64 AppDomainID { get; set; }
public Boolean Result { get; set; }
private Int32 ErrorCode { get; set; }
public Int32 RewardPoints { get; set; }
public String APIVersion { get; set; }
public String ErrorMessage { get; set; }
public Int32 AuthErrorCode { get; set; }
public List<RewardItem> Rewards { get; set; }
}
public class RewardItem
{
public String RewardID { get; set; }
public Int64 AppDomainID { get; set; }
public String RewardName { get; set; }
public String Description { get; set; }
public Int32 AvailQty { get; set; }
public Int32 Cost { get; set; }
public Int32 LowLevel { get; set; }
public String StartDate { get; set; }
public String EndDate { get; set; }
public string ImageURL { get; set; }
}
public class GetRewards
{
public delegate void OnGetRewardsResponse(GetRewardsResponse GetRewardsResponse);
public event OnGetRewardsResponse onGetRewardsResponse;
public delegate void OnGetRewardsResponseError(GetRewardsResponse GetRewardsResponse);
public event OnGetRewardsResponseError onGetRewardsResponseError;
const string CONST_ConnecterBaseURL = "https://www.redcritterconnecter.com/";
public void Execute(String SecretKey)
{
try
{
//Create url encoded parameters in query string
String queryString = "secretkey=" + System.Web.HttpUtility.UrlEncode(SecretKey);
//Create a new instance of a WebClient
WebClient wc = new System.Net.WebClient();
//Prevent this request from caching in order to ensure that it is sent to server
wc.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
//Attach an event handler to receive the response
wc.DownloadStringCompleted += onGetRewardsResponseReceived;
//Make the call
wc.DownloadStringAsync(new Uri(CONST_ConnecterBaseURL + "services/gamificationv1/GetRewards?" + queryString, UriKind.Absolute));
}
catch
{
//Something went wrong communicating with the server
if (onGetRewardsResponseError != null)
{
onGetRewardsResponseError(null);
}
}
}
private void onGetRewardsResponseReceived(object sender, DownloadStringCompletedEventArgs e)
{
try
{
//Create a JSON serializer
System.Runtime.Serialization.Json.DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(GetRewardsResponse));
//Copy the string into a memory stream
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(e.Result));
//Read the stream into an object matching the response's type
GetRewardsResponse GetRewardsResponse = (GetRewardsResponse)s.ReadObject(ms);
//Work with the populated response object
if (GetRewardsResponse.Result == true)
{
//Request was accepted, raise the success event
onGetRewardsResponse(GetRewardsResponse);
}
else
{
//Something went wrong
if (onGetRewardsResponseError != null)
{
//Request failed, raise the error event
onGetRewardsResponseError(GetRewardsResponse);
}
}
}
catch
{
//Something went wrong
onGetRewardsResponseError(null);
}
}
}
}
Responses JSON, XML
JSON Response
{
"Rewards": [
{
"AppDomainID": 59,
"RewardID": "2013-08-20 16:51:47.8032326",
"RewardName": "Take a long Lunch !",
"Description": "Take an extra hour for lunch !",
"AvailQty": 25,
"Cost": 25,
"LowLevel": 0,
"StartDate": "2000-01-01T00:00:00",
"EndDate": "2000-01-01T00:00:00",
"ImageURL": "http://connecterstoredev.blob.core.windows.net/rewards/rewardicon_8/20/2013 4:51:47 PM.png"
},
{
"AppDomainID": 59,
"RewardID": "2013-08-14 21:32:38.8490405",
"RewardName": "Tasty Treat",
"Description": "Yum !",
"AvailQty": 198,
"Cost": 250,
"LowLevel": 0,
"StartDate": "2000-01-01T00:00:00",
"EndDate": "2000-01-01T00:00:00",
"ImageURL": "http://connecterstoredev.blob.core.windows.net/rewards/rewardicon_8/14/2013 9:32:38 PM.png"
}
],
"UserID": 0,
"TeamID": "",
"ProfileEntity": null,
"RewardPoints": 0,
"AppID": 40,
"AppDomainID": 59,
"Result": true,
"ErrorMessage": "",
"ErrorCode": 0,
"APIVersion": "1.0.0",
"AuthErrorCode": 0
}
XML Response
<Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="Connecter">
<APIVersion>1.0.0</APIVersion>
<AuthErrorCode>0</AuthErrorCode>
<ErrorMessage />
<AppDomainID>59</AppDomainID>
<AppID>40</AppID>
<ErrorCode>0</ErrorCode>
<ProfileEntity i:nil="true" />
<Result>true</Result>
<RewardPoints>0</RewardPoints>
<Rewards>
<Reward>
<AppDomainID>59</AppDomainID>
<AvailQty>25</AvailQty>
<Cost>25</Cost>
<Description>Take an extra hour for lunch !</Description>
<EndDate>2000-01-01T00:00:00</EndDate>
<ImageURL>
http://connecterstoredev.blob.core.windows.net/rewards/rewardicon_8/20/2013 4:51:47 PM.png
</ImageURL>
<LowLevel>0</LowLevel>
<RewardID>2013-08-20 16:51:47.8032326</RewardID>
<RewardName>Take a long Lunch !</RewardName>
<StartDate>2000-01-01T00:00:00</StartDate>
</Reward>
<Reward>
<AppDomainID>59</AppDomainID>
<AvailQty>198</AvailQty>
<Cost>250</Cost>
<Description>Yum !</Description>
<EndDate>2000-01-01T00:00:00</EndDate>
<ImageURL>
http://connecterstoredev.blob.core.windows.net/rewards/rewardicon_8/14/2013 9:32:38 PM.png
</ImageURL>
<LowLevel>0</LowLevel>
<RewardID>2013-08-14 21:32:38.8490405</RewardID>
<RewardName>Tasty Treat</RewardName>
<StartDate>2000-01-01T00:00:00</StartDate>
</Reward>
</Rewards>
<TeamID />
<UserID>0</UserID>
</Response>
This version of the GetRewards command retrieve the list of rewards of an App based on the App Domain. The Secret Key must be the App Secret Key.
https://redcritterconnecter.com/services/gamificationv1/getRewards?SecretKey={SecretKey}&ExternalAccountID={ExternalAccountID}
SecretKey | string | yes | This SecretKey is an App Secret Key.The App Domain is determined by the External Account ID you provide. |
ExternalAccountID | string | yes | A unique ID for an App Domain that you create and manage. For example an App could have 2 App Domains managed separately by specifying an ExternalAccountID of 'Sales Dept' or 'IT Dept'. When passed as a parameter if the External Account ID does not exist. RedCritter Connecter will create a new App Domain on the fly with the ID that you specify. |
Code Samples Javascript, C#
GetRewards with JavaScript
This is a minimal example of calling the GetRewards API via HTML and Javascript. Remember to never use your Secret Keys on the client side.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js"></script>
<style type='text/css'>
body {
font-family: "Arial";
}
.rctable{
padding-top:20px;
padding-bottom:10px;
border-bottom:solid 1px #ccc;
width:600px;
}
.rclabel {
font-size:14px;
font-weight:bold;
}
.rcval{
font-size:14px;
padding-left:10px;
}
</style>
var connecterURL = "https://www.redcritterconnecter.com/";
function getRewards(secretKey, externalAccountID, cbSuccess, cbFail) {
$.getJSON(connecterURL + "services/gamificationv1/getRewards?jsoncallback=?", { secretKey: secretKey, externalAccountID: externalAccountID },
function (data) {
if (data.Result) {
cbSuccess(data);
} else {
cbFail(data);
}
});
}
<script type="text/javascript">
//My Success Callback
function onMyGetRewardsSuccessHandler(data) {
//data is JSON response
renderRewards(data)
}
//My Failure Callback
function onMyGetRewardsFailHandler(data) {
//Something went wrong
alert("Something went wrong");
}
//Sample function to generate the rewardslist output in html
function renderRewards(data) {
var h = "";
if (data.Rewards.length == 0) {
// no rewards
h = "Sorry, this rewards store is currently empty. Check back later.";
} else {
//render each reward
for (var i = 0; i < data.Rewards.length; i++) {
h = h+ generateRewardItemHTML(data.Rewards[i]);
}
}
//display the results
$("#results").html(h);
}
function generateRewardItemHTML(reward) {
var h = "<table class='rctable'>";
h += "<tr><td class='rclabel'>Reward Name : </td><td class='rcval'>" + HTMLEncode(reward.RewardName) + "</td></tr>"
h += "<tr><td class='rclabel'>Description : </td><td class='rcval'>" + HTMLEncode(reward.Description) + "</td></tr>";
h += "<tr><td class='rclabel'>Avail Qty : </td><td class='rcval'>" + reward.AvailQty + "</td></tr>";
h += "<tr><td class='rclabel'>Cost : </td><td class='rcval'>" + reward.Cost + "</td></tr>";
h += "<tr><td class='rclabel'></td><td class='rcval'><img src='" + reward.ImageURL + "'/></td></tr>";
h += "</table>";
return h
}
function HTMLEncode(str) {
var div = document.createElement('div');
var text = document.createTextNode(str);
div.appendChild(text);
return div.innerHTML;
}
</script>
</head>
<body>
<table>
<tr>
<td>Secret Key</td>
<td>
<input type="text" id="tSecretKey" style="width: 500px" />
</td>
</tr>
<tr>
<td>External Account ID</td>
<td>
<input type="text" id="tExternalAccountID" style="width: 500px" />
</td>
</tr>
<tr>
<td></td>
<td>
<input type="button" onclick="getRewards($('#tSecretKey').val(),$('#tExternalAccountID').val(), onMyGetRewardsSuccessHandler, onMyGetRewardsFailHandler)" value="Get Rewards" /></td>
</tr>
</table>
<br />
<div id="results"></div>
</body>
</html>
GetRewards with C#
This is a minmal example of calling the GetRewards API and parsing the JSON result into a populated C# object. This example uses asynchronous techniques to raise a callback when the response is received.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using System.Web; //Add reference to System.Web
using System.Runtime.Serialization.Json; //Add reference to System.Runtime.Serialization
namespace RedCritterConnecter.Samples
{
//Create a class to contain the response
public class GetRewardsResponse
{
public Int64 UserID { get; set; }
public String TeamID { get; set; }
public String ProfileEntity { get; set; }
public Int64 AppID { get; set; }
public Int64 AppDomainID { get; set; }
public Boolean Result { get; set; }
private Int32 ErrorCode { get; set; }
public Int32 RewardPoints { get; set; }
public String APIVersion { get; set; }
public String ErrorMessage { get; set; }
public Int32 AuthErrorCode { get; set; }
public List<RewardItem> Rewards { get; set; }
}
public class RewardItem
{
public String RewardID { get; set; }
public Int64 AppDomainID { get; set; }
public String RewardName { get; set; }
public String Description { get; set; }
public Int32 AvailQty { get; set; }
public Int32 Cost { get; set; }
public Int32 LowLevel { get; set; }
public String StartDate { get; set; }
public String EndDate { get; set; }
public string ImageURL { get; set; }
}
public class GetRewards
{
public delegate void OnGetRewardsResponse(GetRewardsResponse GetRewardsResponse);
public event OnGetRewardsResponse onGetRewardsResponse;
public delegate void OnGetRewardsResponseError(GetRewardsResponse GetRewardsResponse);
public event OnGetRewardsResponseError onGetRewardsResponseError;
const string CONST_ConnecterBaseURL = "https://www.redcritterconnecter.com/";
public void Execute(String SecretKey, String ExternalAccountID)
{
try
{
//Create url encoded parameters in query string
String queryString = "secretkey=" + System.Web.HttpUtility.UrlEncode(SecretKey) + "&externalaccountid=" + System.Web.HttpUtility.UrlEncode(ExternalAccountID);
//Create a new instance of a WebClient
WebClient wc = new System.Net.WebClient();
//Prevent this request from caching in order to ensure that it is sent to server
wc.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
//Attach an event handler to receive the response
wc.DownloadStringCompleted += onGetRewardsResponseReceived;
//Make the call
wc.DownloadStringAsync(new Uri(CONST_ConnecterBaseURL + "services/gamificationv1/GetRewards?" + queryString, UriKind.Absolute));
}
catch
{
//Something went wrong communicating with the server
if (onGetRewardsResponseError != null)
{
onGetRewardsResponseError(null);
}
}
}
private void onGetRewardsResponseReceived(object sender, DownloadStringCompletedEventArgs e)
{
try
{
//Create a JSON serializer
System.Runtime.Serialization.Json.DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(GetRewardsResponse));
//Copy the string into a memory stream
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(e.Result));
//Read the stream into an object matching the response's type
GetRewardsResponse GetRewardsResponse = (GetRewardsResponse)s.ReadObject(ms);
//Work with the populated response object
if (GetRewardsResponse.Result == true)
{
//Request was accepted, raise the success event
onGetRewardsResponse(GetRewardsResponse);
}
else
{
//Something went wrong
if (onGetRewardsResponseError != null)
{
//Request failed, raise the error event
onGetRewardsResponseError(GetRewardsResponse);
}
}
}
catch
{
//Something went wrong
onGetRewardsResponseError(null);
}
}
}
}
Responses JSON, XML
JSON Response
{
"Rewards": [
{
"AppDomainID": 63,
"RewardID": "2013-08-20 18:10:53.3105291",
"RewardName": "TestGroup Reward",
"Description": "Fun Fun Fun !!!!",
"AvailQty": 22,
"Cost": 5,
"LowLevel": 0,
"StartDate": "2000-01-01T00:00:00",
"EndDate": "2000-01-01T00:00:00",
"ImageURL": "http://connecterstoredev.blob.core.windows.net/rewards/rewardicon_8/20/2013 6:10:53 PM.png"
}
],
"UserID": 0,
"TeamID": "",
"ProfileEntity": null,
"RewardPoints": 0,
"AppID": 40,
"AppDomainID": 63,
"Result": true,
"ErrorMessage": "",
"ErrorCode": 0,
"APIVersion": "1.0.0",
"AuthErrorCode": 0
}
XML Response
<Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="Connecter">
<APIVersion>1.0.0</APIVersion>
<AuthErrorCode>0</AuthErrorCode>
<ErrorMessage />
<AppDomainID>63</AppDomainID>
<AppID>40</AppID>
<ErrorCode>0</ErrorCode>
<ProfileEntity i:nil="true" />
<Result>true</Result>
<RewardPoints>0</RewardPoints>
<Rewards>
<Reward>
<AppDomainID>63</AppDomainID>
<AvailQty>22</AvailQty>
<Cost>5</Cost>
<Description>Fun Fun Fun !!!!</Description>
<EndDate>2000-01-01T00:00:00</EndDate>
<ImageURL>
http://connecterstoredev.blob.core.windows.net/rewards/rewardicon_8/20/2013 6:10:53 PM.png
</ImageURL>
<LowLevel>0</LowLevel>
<RewardID>2013-08-20 18:10:53.3105291</RewardID>
<RewardName>TestGroup Reward</RewardName>
<StartDate>2000-01-01T00:00:00</StartDate>
</Reward>
</Rewards>
<TeamID />
<UserID>0</UserID>
</Response>
|
Use |
Runtime |
Method |
HTTP GET |
Invites User |
No |
Billable |
No |
Response |
JSON,XML |
API Version |
1 |
|