App42 Cloud API

Windows Phone Cloud SDK

Push Notification

In order to use the various functions available under a particular API, a developer will have to create an instance of ServiceAPI by passing the apiKey and the secretKey which has been received while creating an app.

	ServiceAPI api = new ServiceAPI("<API_KEY>","<SECRET_KEY>");                            

After initialization, developer needs to call the buildXXXService method on ServiceAPI instance to get the instance of the particular API that you wish to build. For example, To build an instance of PushnotificationService, BuildPushnotificationService() method needs to be called.

	PushnotificationService pushnotificationService = api.BuildPushnotificationService();

Once the API instance has been retrieved, You are ready to use the functions available for that particular API.

The methods available under a particular API will return the domain object (like Push Notification in this case) as a response which will have the accessor / mutator to access the available properties for that object. You can get the response in the form of JSON as well. We have also provided the JSON response with every function detail which can be retrieved by calling the ToString() on the returned object.

public class CallBack : App42Callback
{
public override void OnSuccess(Object obj)
{
	PushNotification pushNotification = (PushNotification) obj;
	//Do whatever you want with the user object
}
public override void OnException(App42Exception e)
{
	//Do whatever you want with the exception
}
}                    

The functions available under Push Notification API can throw some exceptions in abnormal conditions. Example of the same has been given below.

E.g. If App developer is creating a user with username which is already in database, the function will throw the App42Exception (as shown below) with message as "Bad Request" and the appErrorCode as "2001" and the details as "The Request parameters are invalid. Username '{userName}' already Exists".

public override void OnSuccess(Object obj)
{
PushNotification pushNotification = (PushNotification) obj;
Console.WriteLine("UserName" + pushNotification.GetUserName());
Console.WriteLine("message" + pushNotification.GetMessage());
String jsonResponse = social.ToString(); /* Returns the response in JSON format.*/
}
                            

The functions available under Social API can throw some exceptions in abnormal conditions. Example of the same has been given below.

E.g. If App developer is linking the User Twitter account name who has not authorized the app to use his account, the function will throw the App42Exception (as shown below) with message as "Bad Request" and the appErrorCode as "3801" and the details as "User '{userName}' has not authorized App to use his/her account.".

public override void OnException(App42Exception ex)
{
int appErrorCode = ex.GetAppErrorCode();
int httpErrorCode = ex.GetHttpErrorCode();

String jsonText = ex.GetMessage(); /* returns the Exception text in JSON format. (as shown below)*/	
}
                            
Exception Comming Soon                    
{
    "app42Fault": {
        "httpErrorCode": 400,
        "appErrorCode": 1700,
        "message": "Bad Request",
        "details": "User by the name '<userName>' already registered with the device '<deviceToken>'."
    }
}							

Below are the HTTP Error Codes and their description, the function under the Pushnotification API can throw.

/*
1400 - BAD REQUEST - The Request parameters are invalid
1401 - UNAUTHORIZED - Client is not authorized
1500 - INTERNAL SERVER ERROR - Internal Server Error. Please try again	
*/		

Below are the Application Error Codes and their description, the function under the Pushnotification API can throw.

/*
1700 - BAD REQUEST - User by the name '<userName>' already registered with the device '<deviceToken>'.
1701 - BAD REQUEST - Channel by the name '<channelName>' already exist for user '<userName>'.
1702 - BAD REQUEST - Channel by the name '<channelName>' does not exist.
1703 - NOT FOUND - User by the name '<userName>' does not have any device registered.
1704 - NOT FOUND - User by the name '<userName>' already subscribed for the channel '<channelName>'.
1705 - NOT FOUND - User by the name '<userName>' not subscribed for the channel '<channelName>'.
1706 - NOT FOUND - No device is registered with the App.
1707 - NOT FOUND - No device is Subscribed to the channel '<channelName>'.
*/			

Various functions available under Pushnotification API has been explained below.

public void StoreDeviceToken(String username,String deviceToken,App42Callback requestCallback)

Stores The Existing Device Tokens

Parameters:

username - username with which you want your device to be registered
deviceToken - Microsoft HttpNotificationChannel URL
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

PushNotification Object.

Response: PushNotification Object

Exception:

This method throws following exception.
/*
1700 - BAD REQUEST - User by the name '<userName>' already registered with the device '<deviceToken>'
*/
For more details click Exception
String userName = "Nick"
String deviceToken = "http://sn1.notify.live.net/throttledthirdparty/01.00/AAFiutCQOr61R73RoMYT_gZGAgAAAAADAgAAAAQUZm52OkJCMjg1QTg1QkZDMkUxREQ"

pushnotificationService.StoreDeviceToken(userName, deviceToken, requestCallback); /* returns the PushNotification object. */
OnSucess(Object obj)
{
PushNotification push = (PushNotification) obj;
Console.WriteLine("userName is " + push.GetUserName());
String jsonResponse = push.ToString(); /* returns the response in JSON format. (as shown below)*/
} 
		   
{
    "app42": {
        "response": {
            "success": true,
            "push": {
                "userName": "Nick",
                "type": "WP7",
                "deviceToken": "http://sn1.notify.live.net/throttledthirdparty/01.00/AAFiutCQOr61R73RoMYT_gZGAgAAAAADAgAAAAQUZm52OkJCMjg1QTg1QkZDMkUxREQ"
            }
        }
    }
} 
public void CreateChannelForApp(String channel, String description, App42Callback requestCallback)

Creates The Channel for the Application.

Parameters:

channel - channel name which you want to create
description - description for that channel
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

The PushNotification Object

Response: PushNotification Object

Exception:

This method throws following exception.
/*		   
1701 - BAD REQUEST - Channel by the name '<channelName>' already exist for user '<userName>'.
*/
For more details click Exception
String channelName = "Channel";	
String description = "description";					
						
pushnotificationService.CreateChannelForApp(channelName, description, requestCallback); /* returns the PushNotification object. */
OnSucess(Object obj)
{
PushNotification push = (PushNotification) obj;
String jsonResponse = push.ToString(); /* returns the response in JSON format. (as shown below)*/
}
{
    "app42": {
        "response": {
            "success": true,
            "push": {
                "userName": "",
                "channels": {
                    "channel": {
                        "channelName": "newsChannel",
                        "description": "channel all about the news"
                    }
                }
            }
        }
    }
}   
public void SubscribeToChannel(String channel, String userName, App42Callback requestCallback)

Selected User Will Be Subscribe To The Existing Channel

Parameters:

channel - the channel name which you want to subscribe
userName - username which want to subscribe
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

The PushNotification Object

Response: PushNotification Object

Exception:

This method throws following exception.
/*		   
1702 - BAD REQUEST - Channel by the name '<channelName>' does not exist.
1703 - NOT FOUND - User by the name '<userName>' does not have any device registered.
1704 - NOT FOUND - User by the name '<userName>' already subscribed for the channel '<channelName>'.
*/
For more details click Exception
String channelName = "newsChannel";
String userName = "Nick";						
						
pushnotificationService.SubscribeToChannel(channelName,userName, requestCallback); /* returns the PushNotification object. */
OnSucess(Object obj)
{
PushNotification push = (PushNotification) obj;
Console.WriteLine("userName is " + push.GetUserName());
String jsonResponse = push.ToString(); /* returns the response in JSON format. (as shown below)*/
}
		
{
    "app42": {
        "response": {
            "success": true,
            "push": {
                "userName": "Nick",
                "channels": {
                    "channel": {
                        "channelName": "newsChannel"
                    }
                }
            }
        }
    }
} 
public void UnsubscribeFromChannel(String channel, String userName, App42Callback requestCallback)

Selected User Will Be Unsubscribe From The Existing Channel

Parameters:

channel - channel name which you want to unsubscribe
userName - username which want to unsubscribe
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

The PushNotification Object

Response: PushNotification Object

Exception:

This method throws following exception.
/*		   
1702 - BAD REQUEST - Channel by the name '<channelName>' does not exist.
1703 - NOT FOUND - User by the name '<userName>' does not have any device registered.
1705 - NOT FOUND - User by the name '<userName>' not subscribed for the channel '<channelName>'.
*/
For more details click Exception
String channelName = "newsChannel";
String userName = "Nick";						
						
pushnotificationService.UnsubscribeFromChannel(channelName,userName, requestCallback); /* returns the PushNotification object. */
OnSucess(Object obj)
{
PushNotification push = (PushNotification) obj;
Console.WriteLine("userName is " + push.GetUserName());
String jsonResponse = push.ToString(); /* returns the response in JSON format. (as shown below)*/
} 
{
    "app42": {
        "response": {
            "success": true,
            "push": {
                "userName": "Nick",
                "channels": {
                    "channel": {
                        "channelName": "newsChannel"
                    }
                }
            }
        }
    }
}
public void SendPushMessageToChannel(String channel, String message, App42Callback requestCallback)

Push Message To Channel Only

Parameters:

channel - channel name which you want to send your message
message - push message in string format
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

The PushNotification Object

Response:PushNotification Object

Exception:

This method throws following exception.
/*		   
1702 - BAD REQUEST - Channel by the name '<channelName>' does not exist.
1707 - NOT FOUND - No device is Subscribed to the channel '<channelName>'.
*/
For more details click Exception
String channelName = "newsChannel";
String message = "Mary Kom won the bronze medal in Olympics";

pushnotificationService.SendPushMessageToChannel(channelName, message, requestCallback); /* returns the PushNotification object. */
OnSucess(Object obj)
{
PushNotification push = (PushNotification) obj;
Console.WriteLine("userName is " + push.GetUserName());
Console.WriteLine("message is " + push.GetMessage());
String jsonResponse = push.ToString(); /* returns the response in JSON format. (as shown below)*/
}
  		
{
    "app42": {
        "response": {
            "success": true,
            "push": {
                "message": "Mary Kom won the bronze medal in Olympics",
                "channels": {
                    "channel": {
                        "channelName": "newsChannel"
                    }
                }
            }
        }
    }
} 
public void SendPushToastMessageToUser(String userName, String title, String subTitle, String param, App42Callback requestCallback)

Push Message To The Selected User.

Parameters:

channel - user name which you want to send your json message
title - title of message
subTitle - subTitle of message
param - param to post with message
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

The PushNotification Object

Response: PushNotification Object

Exception:

This method throws following exception.
/*		   
1703 - NOT FOUND - User by the name '<userName>' does not have any device registered.
*/
For more details click Exception
String userName = "Nick";
String title = "Hello";
String subTitle = "Nick";
String param = "/Page.xml";

pushnotificationService.SendPushToastMessageToUser(user, title, subTitle, param, requestCallback); /* returns the PushNotification object. */
OnSucess(Object obj)
{
PushNotification push = (PushNotification) obj;
Console.WriteLine("userName is " + push.GetUserName());
Console.WriteLine("message is " + push.GetMessage());
String jsonResponse = push.ToString(); /* returns the response in JSON format. (as shown below)*/
}
{
    "app42": {
        "response": {
            "success": true,
            "push": {
                "userName": "Nick",
                "message": {
                    "toast": {
                        "title": "Hello",
                        "subTitle": "Nick",
                        "param": "/Page.xml"
                    }
                }
            }
        }
    }
}   
public void SendPushMessageToAll(String message, App42Callback requestCallback)

Push The Message To All.

Parameters:

message - push Message
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

The PushNotification Object

Response: PushNotification Object

Exception:

This method throws following exception.
/*		   
1706 - NOT FOUND - No device is registered with the App.
*/
For more details click Exception
String message = "vijay kumar shoots the silver medal";

pushnotificationService.SendPushMessageToAll(message, requestCallback); /* returns the PushNotification object. */
OnSucess(Object obj)
{
PushNotification push = (PushNotification) obj;
Console.WriteLine("message is " + push.GetMessage());
String jsonResponse = push.ToString(); /* returns the response in JSON format. (as shown below)*/
}
 
{
    "app42": {
        "response": {
            "success": true,
            "push": {
                "message": "vijay kumar shoots the silver medal"
            }
        }
    }
}                        
}   
public void SendPushMessageToAllByType(String message,String deviceType,App42Callback requestCallback)

Send push message to all your users

Parameters:

message - push Message
deviceType - type of the device like Android, iOS , WP7
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

The PushNotification Object

Response: PushNotification Object

Exception:

This method throws following exception.
/*		   
1706 - NOT FOUND - No device is registered with the App.
*/	
For more details click Exception
String message = "vijay kumar shoots the silver medal";

pushnotificationService.SendPushMessageToAllByType(message,DeviceType.ANDROID,requestCallback); /* returns the PushNotification object. */
OnSucess(Object obj)
{
PushNotification push = (PushNotification) obj;
Console.WriteLine("message is " + push.GetMessage());
Console.WriteLine("message is " + push.GetType());
String jsonResponse = push.ToString(); /* returns the response in JSON format. (as shown below)*/
}
 
{
    "app42": {
        "response": {
            "success": true,
            "push": {
                "message": "vijay kumar shoots the silver medal",
                "expiry": "2012-10-15T11:03:45.425Z",
                "type": "ANDROID"
            }
        }
    }
}