Initialize

In order to use various the functions available in a specific API, a developer has to initialize with App42API by passing the apiKey and secretKey which will be created after the app creation from AppHQ dashboard.

Required Parameters

apiKey - The Application key given when the application was created.
secretKey - The secret key corresponding to the application key given when the application was created.

Build Service

After initialization, developer needs to call the buildXXXService method on App42API 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.

Upload P12 File For iOS

Upload apiKey/certificate to server that will be used while sending notifications to the devices.

Required Parameters

apiKey - the apiKey which you have received while registering for GCM.
password - Password which has been given while export .p12 file.
filePath - Path of certificates.p12 file.
environment - It can be development or production.

local channel = "News Channel";
local message = "Message which you have to send";
local App42CallBack = {}
App42API:initialize("API_KEY","SECRET_KEY")
local pushNotificationService = App42API:buildPushNotificationService()
pushNotificationService:sendPushMessageToChannel(channel,message,App42CallBack);
function App42CallBack:onSuccess(object)
print("Message is :"..object:getMessage());
print("channel is :"..object:getChannelList():getName())
end
function App42CallBack:onException(object)
print("Message is "..object:getAppErrorCode());
print("Message is "..object:getHttpErrorCode());
print("Message is "..object:getMessage());
print("Message is "..object:getDetails());
end

local message = "Message which you have to send";
local App42CallBack = {}
App42API:initialize("API_KEY","SECRET_KEY")
local pushNotificationService = App42API:buildPushNotificationService()
pushNotificationService:sendPushMessageToAll(message,App42CallBack);
function App42CallBack:onSuccess(object)
print("Message is :"..object:getMessage());
print("Expiry is : "..object:getExpiry());
end
function App42CallBack:onException(object)
print("Message is "..object:getAppErrorCode());
print("Message is "..object:getHttpErrorCode());
print("Message is "..object:getMessage());
print("Message is "..object:getDetails());
end

local message = "Message which you have to send";
local deviceType= DeviceType.ANDROID;
local App42CallBack = {}
App42API:initialize("API_KEY","SECRET_KEY")
local pushNotificationService = App42API:buildPushNotificationService()
pushNotificationService:sendPushMessageToAllByType(message,deviceType,App42CallBack);
function App42CallBack:onSuccess(object)
print("Message is :"..object:getMessage());
print("Expiry is :"..object:getExpiry());
print("Type is :"..object:getType());
end
function App42CallBack:onException(object)
print("Message is "..object:getAppErrorCode());
print("Message is "..object:getHttpErrorCode());
print("Message is "..object:getMessage());
print("Message is "..object:getDetails());
end

local userName = "Nick";
local message = "Message which you have to send";
local App42CallBack = {}
App42API:initialize("API_KEY","SECRET_KEY")
local pushNotificationService = App42API:buildPushNotificationService()
pushNotificationService:sendPushMessageToUser(userName,message,App42CallBack);
function App42CallBack:onSuccess(object)
print("Message is "..object:getMessage());
print("Message is "..object:getExpiry());
print("UserName is "..object:getUserName());
end
function App42CallBack:onException(object)
print("Message is "..object:getAppErrorCode());
print("Message is "..object:getHttpErrorCode());
print("Message is "..object:getMessage());
print("Message is "..object:getDetails());
end

Subscribe To Channel With device token

Subscribe your device to a particular channel with device token and type.

Required Parameters

userName - Username which want to subscribe.
channelName - Name of channel for which user want to subscribe.
deviceToken - Device token which you want to subscribe.
deviceType - Device Type which you want to subscribe.

local message="Message which you have to send"
local userList={}
userList[1]="Nick";
userList[2]="John";
local App42CallBack = {}
App42API:initialize("API_KEY","SECRET_KEY")
local pushNotificationService = App42API:buildPushNotificationService()
pushNotificationService:sendPushMessageToGroup(message,userList,App42CallBack);
function App42CallBack:onSuccess(object)
print("Message is "..object:getMessage());
print("Expiry is "..object:getExpiry());
end
function App42CallBack:onException(object)
print("Message is "..object:getAppErrorCode());
print("Message is "..object:getHttpErrorCode());
print("Message is "..object:getMessage());
print("Message is "..object:getDetails());
end

Send Push To Target Users

message - Message which you have to send.
dbName - Unique handler for storage name.
collectionName - Name of collection under which message has to be send.
query - Query object containing custom query for sending push message to that target users.

Exception Handling

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 sending a message to channel which is not in database, the function will throw the App42Exception (as shown below) with message as “Not Found” and the appErrorCode as “1702” and the details as “Channel by the name ‘News Channel’ does not exist”.

Error Codes

Functions in PushNotification API might throw exceptions with following HTTP and Application Error Codes (along with their descriptions):

1400 - BAD REQUEST - The Request parameters are invalid.
1401 - UNAUTHORIZED - Client is not authorized.
1500 - INTERNAL SERVER ERROR - Internal Server Error. Please try again.
1700 - BAD REQUEST - User by the name '@userName' already registered with the device '@deviceToken'.
1701 - BAD REQUEST - Channel by the name '@channelName' already exist
1702 - NOT FOUND - Channel by the name '@channelName' does not exist.
1703 - NOT FOUND - User by the name '@userName' does not have any device registered
1704 - BAD REQUEST - User by the name '@userName' already subscribed for the channel '@channelName'
1705 - NOT FOUND - User by the name '@userName' not subscribed for any channel
1706 - NOT FOUND - No device is registered with the App
1707 - NOT FOUND - No device is Subscribed to the channel '@channelName'.
1708 - NOT FOUND - Channel by the name '@channelName' device '@deviceToken' does not subscribe.
1709 - NOT FOUND - User by the name '@userName' device token '@deviceToken' does not registered.
1710 - NOT FOUND - No device registered for user list '@userList'
1711 - NOT FOUND - No target user found for given query
1712 - NOT FOUND - In Active Users with date rnage '@startDate'and '@endDate' does not exist.
1713 - BAD REQUEST - User by the name '@userName' already unsubscribe with the device '@deviceToken'
1714 - BAD REQUEST - User by the name '@userName' already subscribe with the device '@deviceToken'
1715 - BAD REQUEST - Your previous request already in process.Please Try after sometime.