Send a notification to one or more users. Notifications can appear in a user's feed and on their mobile devices (if they have the RedCritter App installed). Additionally notifications will appear in real-time feeds for the Account, App and AppDomain. Notifications are not sent out to social networks.
This version of the SendNotification command is used to send notifications and feed updates to the users specified with the ProfileEntity value.
https://redcritterconnecter.com/services/gamificationv1/SendNotification?SecretKey={SecretKey}&ProfileEntity={ProfileEntity}&Title={Title}&Message={Message}
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. |
ProfileEntity | string | yes | The ProfileEntity represents to whom the API call will apply. This can be an email address. Multiple email addresses can be specified by separating them with a semicolon. Teams are not supported with Notifications |
Title | string | yes | The title of the notification. Max length of title is 24 characters |
Message | string | yes | The Notification Message. Max length of message is 140 characters |
Code Samples Javascript, C#
SendNotification with JavaScript
This is a minimal example of calling the SendNotification 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>
<script type="text/javascript">
var connecterURL = "https://www.redcritterconnecter.com/";
function sendNotification(secretKey, profileEntity, title, message, cbSuccess, cbFail) {
$.getJSON(connecterURL + "services/gamificationv1/sendnotification?jsoncallback=?", { secretKey: secretKey, profileEntity: profileEntity, title:title, message:message },
function (data) {
if (data.Submitted) {
cbSuccess(data);
} else {
cbFail(data);
}
});
}
//My Success Callback
function onMysendNotificationSuccessHandler(data) {
//data is JSON response
alert("Request was successful");
}
//My Failure Callback
function onMysendNotificationFailHandler(data) {
//Something went wrong
alert("Something went wrong");
}
</script>
</head>
<body>
<table>
<tr>
<td>Secret Key</td>
<td>
<input type="text" id="tSecretKey" style="width: 500px" />
</td>
</tr>
<tr>
<td>Profile Entity</td>
<td>
<input type="text" id="tProfileEntity" />
</td>
</tr>
<tr>
<td>Title</td>
<td>
<input type="text" id="tTitle" />
</td>
</tr>
<tr>
<td>Message</td>
<td>
<input type="text" id="tMessage" />
</td>
</tr>
<td></td>
<td>
<input type="button" onclick="sendNotification($('#tSecretKey').val(), $('#tProfileEntity').val(), $('#tTitle').val(), $('#tMessage').val(),onMysendNotificationSuccessHandler, onMysendNotificationFailHandler)" value="Send Notification" /></td>
</tr>
</table>
</body>
</html>
SendNotification with C#
This is a minmal example of calling the SendNotification 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 SendNotificationResponse
{
public String ErrorMessage { get; set; }
public Boolean Submitted { get; set; }
public String RequestID { get; set; }
public String APIVersion { get; set; }
public String ReturnParam1 { get; set; }
public String ReturnParam2 { get; set; }
public String ReturnParam3 { get; set; }
private Int32 ErrorCode { get; set; }
}
public class SendNotification
{
public delegate void OnSendNotificationResponse(SendNotificationResponse SendNotificationResponse);
public event OnSendNotificationResponse onSendNotificationResponse;
public delegate void OnSendNotificationResponseError(SendNotificationResponse SendNotificationResponse);
public event OnSendNotificationResponseError onSendNotificationResponseError;
const string CONST_ConnecterBaseURL = "https://www.redcritterconnecter.com/";
public void Execute(String SecretKey, String ProfileEntity, String Title, String Message)
{
try
{
//Create url encoded parameters in query string
String queryString = "secretkey=" + System.Web.HttpUtility.UrlEncode(SecretKey) + "&profileentity=" + System.Web.HttpUtility.UrlEncode(ProfileEntity) + "&title=" + System.Web.HttpUtility.UrlEncode(Title) + "&message=" + System.Web.HttpUtility.UrlEncode(Message);
//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 += onSendNotificationResponseReceived;
//Make the call
wc.DownloadStringAsync(new Uri(CONST_ConnecterBaseURL + "services/gamificationv1/SendNotification?" + queryString, UriKind.Absolute));
}
catch
{
//Something went wrong communicating with the server
if (onSendNotificationResponseError != null)
{
onSendNotificationResponseError(null);
}
}
}
private void onSendNotificationResponseReceived(object sender, DownloadStringCompletedEventArgs e)
{
try
{
//Create a JSON serializer
System.Runtime.Serialization.Json.DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(SendNotificationResponse));
//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
SendNotificationResponse SendNotificationResponse = (SendNotificationResponse)s.ReadObject(ms);
//Work with the populated response object
if (SendNotificationResponse.Submitted == true)
{
//Request was accepted, raise the success event
onSendNotificationResponse(SendNotificationResponse);
}
else
{
//Something went wrong
if (onSendNotificationResponseError != null)
{
//Request failed, raise the error event
onSendNotificationResponseError(SendNotificationResponse);
}
}
}
catch
{
//Something went wrong
onSendNotificationResponseError(null);
}
}
}
}
Responses JSON, XML
JSON Result
{
"ErrorMessage": "",
"Submitted": true,
"RequestID": "7666-02-10 08:09:12.1423360",
"APIVersion": "1.0.0",
"ReturnParam1": "",
"ReturnParam2": "",
"ReturnParam3": "",
"OddsOneIn": 1,
"OddsTriggered": true,
"ErrorCode": 0
}
XML Response
<Response xmlns="Connecter" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<APIVersion>1.0.0</APIVersion>
<ErrorCode>0</ErrorCode>
<ErrorMessage/>
<OddsOneIn>1</OddsOneIn>
<OddsTriggered>true</OddsTriggered>
<RequestID>3208-04-02 22:22:58.2830848</RequestID>
<ReturnParam1/>
<ReturnParam2/>
<ReturnParam3/>
<Submitted>true</Submitted>
</Response>
This version of the SendNotification command is used to send notifications and feed updates to the users specified with the ProfileEntity value. The Secret Key must be the App Secret Key.
https://redcritterconnecter.com/services/gamificationv1/gamificationv1/SendNotification?SecretKey={SecretKey}&ExternalAccountID={ExternalAccountID}&ProfileEntity={ProfileEntity}&Title={Title}&Message={Message}
SecretKey | string | yes | This SecretKey must be the App Secret Key. |
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. |
ProfileEntity | string | yes | The ProfileEntity represents to whom the API call will apply. This can be an email address. Multiple email addresses can be specified by separating them with a semicolon. Teams are not supported with Notifications |
Title | string | yes | The title of the notification. Max length of title is 24 characters |
Message | string | yes | The Notification Message. Max length of message is 140 characters |
Code Samples Javascript, C#
SendNotification with JavaScript
This is a minimal example of calling the SendNotification 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>
<script type="text/javascript">
var connecterURL = "https://www.redcritterconnecter.com/";
function sendNotification(secretKey, externalAccountID, profileEntity, title, message, cbSuccess, cbFail) {
$.getJSON(connecterURL + "services/gamificationv1/sendnotification?jsoncallback=?", { secretKey: secretKey, externalAccountID: externalAccountID, profileEntity: profileEntity, title: title, message:message },
function (data) {
if (data.Submitted) {
cbSuccess(data);
} else {
cbFail(data);
}
});
}
//My Success Callback
function onMysendNotificationSuccessHandler(data) {
//data is JSON response
alert("Request was successful");
}
//My Failure Callback
function onMysendNotificationFailHandler(data) {
//Something went wrong
alert("Something went wrong");
}
</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" />
</td>
</tr>
<tr>
<tr>
<td>Profile Entity</td>
<td>
<input type="text" id="tProfileEntity" />
</td>
</tr>
<tr>
<td>Title</td>
<td>
<input type="text" id="tTitle" />
</td>
</tr>
<tr>
<td>Message</td>
<td>
<input type="text" id="tMessage" />
</td>
</tr>
<td></td>
<td>
<input type="button" onclick="sendNotification($('#tSecretKey').val(), $('#tExternalAccountID').val(), $('#tProfileEntity').val(), $('#tTitle').val(),$('#tTitle').val(), onMysendNotificationSuccessHandler, onMysendNotificationFailHandler)" value="Send Notification" /></td>
</tr>
</table>
</body>
SendNotification with C#
This is a minmal example of calling the SendNotification 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. The Secret Key must be the App Secret Key.
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 SendNotificationResponse
{
public String ErrorMessage { get; set; }
public Boolean Submitted { get; set; }
public String RequestID { get; set; }
public String APIVersion { get; set; }
public String ReturnParam1 { get; set; }
public String ReturnParam2 { get; set; }
public String ReturnParam3 { get; set; }
private Int32 ErrorCode { get; set; }
}
public class SendNotification
{
public delegate void OnSendNotificationResponse(SendNotificationResponse SendNotificationResponse);
public event OnSendNotificationResponse onSendNotificationResponse;
public delegate void OnSendNotificationResponseError(SendNotificationResponse SendNotificationResponse);
public event OnSendNotificationResponseError onSendNotificationResponseError;
const string CONST_ConnecterBaseURL = "https://www.redcritterconnecter.com/";
public void Execute(String SecretKey, String ExternalAccountID, String ProfileEntity, String Title, String Message)
{
try
{
//Create url encoded parameters in query string
String queryString = "secretkey=" + System.Web.HttpUtility.UrlEncode(SecretKey) + "&externalaccountid=" + System.Web.HttpUtility.UrlEncode(ExternalAccountID) + "&profileentity=" + System.Web.HttpUtility.UrlEncode(ProfileEntity) + "&title=" + System.Web.HttpUtility.UrlEncode(Title) + "&message=" + System.Web.HttpUtility.UrlEncode(Message);
//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 += onSendNotificationResponseReceived;
//Make the call
wc.DownloadStringAsync(new Uri(CONST_ConnecterBaseURL + "services/gamificationv1/SendNotification?" + queryString, UriKind.Absolute));
}
catch
{
//Something went wrong communicating with the server
if (onSendNotificationResponseError != null)
{
onSendNotificationResponseError(null);
}
}
}
private void onSendNotificationResponseReceived(object sender, DownloadStringCompletedEventArgs e)
{
try
{
//Create a JSON serializer
System.Runtime.Serialization.Json.DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(SendNotificationResponse));
//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
SendNotificationResponse SendNotificationResponse = (SendNotificationResponse)s.ReadObject(ms);
//Work with the populated response object
if (SendNotificationResponse.Submitted == true)
{
//Request was accepted, raise the success event
onSendNotificationResponse(SendNotificationResponse);
}
else
{
//Something went wrong
if (onSendNotificationResponseError != null)
{
//Request failed, raise the error event
onSendNotificationResponseError(SendNotificationResponse);
}
}
}
catch
{
//Something went wrong
onSendNotificationResponseError(null);
}
}
}
}
Responses JSON, XML
JSON Result
{
"ErrorMessage": "",
"Submitted": true,
"RequestID": "0587-06-03 13:21:04.8151552",
"APIVersion": "1.0.0",
"ReturnParam1": "",
"ReturnParam2": "",
"ReturnParam3": "",
"OddsOneIn": 1,
"OddsTriggered": true,
"ErrorCode": 0
}
XML Result
<Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="Connecter">
<APIVersion>1.0.0</APIVersion>
<ErrorCode>0</ErrorCode>
<ErrorMessage/>
<OddsOneIn>1</OddsOneIn>
<OddsTriggered>true</OddsTriggered>
<RequestID>2135-04-15 07:25:22.2938624</RequestID>
<ReturnParam1/>
<ReturnParam2/>
<ReturnParam3/>
<Submitted>true</Submitted>
</Response>
|
Use |
Runtime |
Method |
HTTP GET |
Invites User |
Yes |
Billable |
Yes |
Response |
JSON,XML |
API Version |
1 |
|