API Documentation

Last updated: Aug 25th, 2017

Getting Started

The Morengage REST APIs are very easy to use, and you will only need two things to get started: Your Morengage API Keys, which are located on the Morengage dashboard under Profile->API Keys. You will need the API Key. You can call Morengage REST services from other languages and environments. We provide some examples alongside the curl examples for each feature.

Sign Up / Login

Features

The REST API can be used to:

  • Send notifications to all subscribers belonging to a particular web site.
  • Create campaign to a particular web site.
  • Check reports of notification / campaign details..
  • View subscribers count as per browser or web site.
  • Check reports of previous notification requests
  • All requests to the API will be authenticated by an authentication token in a request header, as explained in the next section.

How does Morengage Works?

Morengage currently supports Chrome / Safari browsers that provide push notification functionality. These include: Chrome on desktop and Android, Safari on desktop. (We plan to add support for other browsers as soon as.) How Morengage works: You install Morengage JavaScript on your website By default, we trigger an opt-in box for users on pages where Morengage JavaScript file is present. (Browsers require opt-in from users before you can send them push notifications) If users opt-in to push notifications, you can get subscriber ID and store it in your database to associate it with specific users) For sending notifications to users, you can either use Morengage database and send to all or specific site of users if you have OR you can use our REST API to send notifications to specific users.

Authentication

Each API request is authenticated by an authentication token in the request header. To get your authentication token go to Morengage dashboard under Profile->API Keys. The token needs to be sent in the 'Authorization' HTTP header. The value of the header should be the authentication token.

These are the instructions for connecting to authenticated methods in the Morengage API.

All APIs use HTTPS basic-auth with the X-Auth-Token as the username and the API Key as the password.

Web Push Notification APIs

Web Push Notification - SEND

The Send API can be used to: Send notifications to all subscribers belonging to a particular web site with additional parameters

API ENDPOINT
https://api.morengage.com/send/
HEADER TOKEN
AUTH-Token: TokenID
REQUEST BODY

										
{
	"title": "Title For We Push Notification",
	"body": "Body Content For We Push Notification",
	"link": "Destination Url For We Push Notification",
	"img": "Your Icon Image Path",
	"wid": Id of Website,
	"aid": UserID,
	"badge": "Badge (image) path for Mobile Devices ",
	"bannerimg": "Baner Image Url For We Push Notification",
	"enableAction": "Y",
	"actionName1": "Action1",
	"actionName2": "Action2",
	"actionTitle1": "Action 1 title",
	"actionTitle2": "Action 2 title",
	"actionUrl1": "Action1 Destination Url",
	"actionUrl2": "Action2 Destination Url",
	"actionIcon1": "Icon Url for Action1",
	"actionIcon2": "Icon Url for Action2",
	"vibrate": "vibration type",
	"uniqueIdentifier": "A Unique Identifier",
	"recipientid": ["SubscriberID1", "SubscriberID2", "SubscriberID3", "SubscriberID4"....]
}
										
										
PARAMETER DEFINITION
Parameter Name Description
AUTH-Token Authentication Token
Title Title of the message . This should not exceed more than 40 character
Body Message body part. Max char limit is 120
URL Landing URL
img Path of the image. Recommended sizes are 192 X 192 or 256 X 256
badge Path of the badge image.Recommended size 128 X 128
bannerimg Path of the banner image.Works only in Chrome
enableAction Default value has to be "Y" if you want to use action buttons.Pass action parameters as below along with this type:-

"enableAction":"Y"

"actionName1":"action1"

"actionName2":"action2"

"actionTitle1":"Your desired title for action1"

"actionTitle2":"Your desired title for action2"

"actionUrl1":"The fully qualifed landing url for action1"

"actionUrl2":"The fully qualifed landing url for action2"

"actionIcon1":"A small icon url if needed for action1"

"actionIcon2":"A small icon url if needed for action2"

vibrate Mobile notification vibration patterns.
Types
No
Single
Repetitive
wid The ID of website where the subscription is done
aid The specific account id
recipientid Are the sub ids of each receipients
API RESPONSE STATUS
Status Code Description
200 Success
401 Un Authorized
204 No Data Found
Token or Required Parameter Missing Message Title,Body,image ,url or authentication tokens are missing

APP Push Notification APIs

These endpoints can be used to Send,Fetch Reports,Logs etc for App Push Notifications The request method of this call needs to be "POST".

Parameter

PARAMETER DEFINITION
Parameter Name Description
Device Registration Id Andriod app registration uniue id for app in a phone
Device Token IOS app registration uniue id for app in a phone
URi Windows apps unique registration id for a phone
Uniqueidentifier A unique number( like messagid) can pass to api, can download report based on unique identifier

API RESPONSE STATUS
Status Code Description
200 Success
401 Un Authorized
204 No Data Found
Token or Required Parameter Missing Message Title,Body,image ,url or authentication tokens are missing

APP Push Notifications - Send Api

Using this Endpoint you can push messages to Android , IOS ,Windows Phone

Android - GCM

Push Messages through Google Cloud Messaging for Android (GCM) to Android applications on Android devices

API ENDPOINT
https://api2.morengage.com/pushandriod
REQUEST BODY

{
	"AccountId": "111",
	"ApiKey": "yourapikey",
	"DeviceRegistrationIds": ["DeviceReg1", "DeviceReg2"],
	"JsonMessage": "json string",
	"UniqueIdentifier": "11"
}

IOS - APNS

Push Messages through APNS to IOS applications on Iphone devices

API ENDPOINT
https://api2.morengage.com/pushios
REQUEST BODY

{
	"AccountId": "111",
	"ApiKey": "yourapikey",
	"DeviceTokens": ["Token1", "Token2"],
	"JsonMessage": " json string",
	"UniqueIdentifier": "11"
}

Windows Phone - WNS

Push Messages through Windows Push Notification Service for Windows (WNS) to Windows applications on Windows devices

API ENDPOINT
https://api2.morengage.com/pushwindows
REQUEST BODY

{
	"AccountId": "111",
	"ApiKey": "yourapikey",
	"UriIds": ["URi1", "URi2"],
	"MessageXML": " xml string",
	"UniqueIdentifier": "11"
}

Reports Download

Using this Endpoint you can download reports based on unique identifier

Download Delivered Report

API ENDPOINT
https://api2.morengage.com/Delivered
REQUEST BODY

{
	"AccountId": "11",
	"ApiKey": "yourapikey",
	"UniqueIdentifier": "11"
}


Download Sent Report

API ENDPOINT
https://api2.morengage.com/Send
REQUEST BODY

{
	"AccountId": "11",
	"ApiKey": "yourapikey",
	"UniqueIdentifier": "11"
}


Download Delivered Report Based on Date Range

API ENDPOINT
https://api2.morengage.com/DeliveredBetween
REQUEST BODY

{
	"AccountId": "111",
	"ApiKey": "yourapikey",
	"FromDate": "16-5-2016",
	"ToDate": "16-5-2016"
}


Download Sent Report Based on Date Range

API ENDPOINT
https://api2.morengage.com/SendBetween
REQUEST BODY

{
	"AccountId": "111",
	"ApiKey": "yourapikey",
	"FromDate": "16-5-2016",
	"ToDate": "16-5-2016"
}

Logs

Download Error Logs

API ENDPOINT
https://api2.morengage.com//Log
REQUEST BODY

{
	"AccountId": "111",
	"ApiKey": "yourapikey",
	"UniqueIdentifier": "11"
}


Download Error Log Based on Date range

API ENDPOINT
https://api2.morengage.com/LogBetween
REQUEST BODY

{
	"AccountId": "111",
	"ApiKey": "yourapikey",
	"FromDate": "16-5-2016",
	"ToDate": "16-5-2016"
}


App Analytics APIs

Obtain your App key

Register with https://app.morengage.com/ to obtain your APP Key

Android SDK Integration

Download .aar

The plugin is available for download at https://app.morengage.com/downloads/AndroidSdkV2.1.7.zip downloads/AndroidSdkV2.1.7.zip

Integrate the SDK with the project

Android Studio
  • Step 1 : Select File → New →New Module
  • Step 2 : Select " Import .JAR or .AAR Package under More Modules.
  • Step 3 : Select the P5Analytics.jar by clicking on the File chooser.
  • Step 4 : Select Finish.
  • Step 5 : Right click on app folder → Open Module Settings.
  • Step 6 : Select Dependency at the top right corner.
  • Step 7 : Select '+' symbol and choose 'Module Dependency' and It will list down the existing jar files.
  • Step 8 : Select sdk-release.aar
Eclipse
  • Step 1 : Add sdk-release.aar to your project's libs folder.
  • Step 2 : Right-click the JAR file and select Build Path → Add to Build Path.
Code Integration

AndroidManifest.xml

Give Access to Internet (The SDK will send the collected data to the PushBox Server)


     < uses - permission android: name = "android.permission.INTERNET" />
	 < uses - permission android: name = "android.permission.ACCESS_NETWORK_STATE" />
	 < uses - permission android: name = "android.permission.RECEIVE_BOOT_COMPLETED" />
	 < permission android: name = "permission.C2D_MESSAGE" android: protectionLevel = "signature" />
	 < uses - permission android: name = " permission.C2D_MESSAGE" />
	 < !--This app has permission to register and receive data message.-- >
	 < uses - permission android: name = "com.google.android.c2dm.permission.RECEIVE" />
	 < !--Network State Permissions to detect Internet status-- >
	< uses - permission android: name = "android.permission.WAKE_LOCK" />

Add Dependencies


android {
    defaultConfig {
        ...
        minSdkVersion 14 
        targetSdkVersion 26
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.1'
  compile 'com.android.support:appcompat-v7:25.3.1'
  compile 'com.google.android.gms:play-services:10.0.1'
  compile 'com.google.code.gson:gson:2.4'
}

Configuration APIs and Start Session

Pass the APP KEY to Init method to start tracking the user actions .

PIXDYN_APP_KEY:- AppKey

PixDyn_MESSAGING_PROJECT_ID:- SenderId

import pix.dyn.android.sdk.*;

Launcher Activity:-

Dynamics.onCreate(this);

Dynamics.sharedInstance().setLoggingEnabled(true);

Dynamics.sharedInstance().enableCrashReporting();

Dynamics.sharedInstance().setHttpPostForced(true);

Dynamics.sharedInstance().init(this, PIXDYN_APP_KEY, MainActivity.class, PixDyn_MESSAGING_PROJECT_ID, Dynamics.PixDynMessagingMode.PRODUCTION, this);

Dynamics.sharedInstance().setViewTracking(true);//to track all pages

onStart() and onStop() function of Activity

Dynamics.sharedInstance().onStop();

Dynamics.sharedInstance().onStart(this);

AddtoCart Event

Event must be thrown when a product is added to cart


String ProductId = "002";  //Productid
String ProductName = "GoldBangle";//Name of product
int Count = 2;//quantity
Dynamics.sharedInstance().AddtoCartEvent(ProductId, ProductName, Count);

Purchase Event

Event must be thrown when a product is purchased


String ProductId="002"; //Product of id
String ProductName="GoldBangle";// Name of product
int Count=2;//Quantity
Dynamics.sharedInstance().PurchaseEvent(ProductId,ProductName,Count);

Purchase Event

Event must be thrown when a product is viewed


String ProductId = "002";  //Id of product
String ProductName = "GoldBangle"; //Name Of Product
Dynamics.sharedInstance().ProductViewEvent(ProductId, ProductName);

Contact Event

Event must be thrown when a person clicks on Contact


String ProductId = "002";  //Id of Product for which the person has contacted
String ProductName = "GoldBangle";//Name of product for which the person has Dynamics.sharedInstance().ContactUsEvent(ProductId, ProductName);

Enquiry Event

Event must be thrown when a person clicks on Enquiry


String ProductId="002";
String ProductName="GoldBangle";
Dynamics.sharedInstance().EnquiryEvent(ProductId,ProductName);

Custom Event

Can be used for any custom events


String Id = "002";
String Name = "GoldBangle";
String Type = "CUSTOMTYPE";
int Quantity = 2;
Dynamics.sharedInstance().CustomEvent(Id, Name, Type, Quantity);


User Details Record


Dynamics.userData.name="xx";
Dynamics.userData.username="xx";
Dynamics.userData.email="xx@gmail.com";
Dynamics.userData.org="xx Pvt Ltd.";
Dynamics.userData.phone="";
Dynamics.userData.gender="M";
Dynamics.userData.byear=1983;
Dynamics.userData.city=" ";
Dynamics.userData.country=" ";
Dynamics.userData.address=" ";
Dynamics.sharedInstance().UserDetails(Dynamics.userData);



Logging Location

Pass latitude,longitude value


Dynamics.sharedInstance().setLocation(10.0159, 76.3419);

Crash Log


Dynamics.sharedInstance().addCrashLog("Crash log 8");
Dynamics.sharedInstance().logException(new Exception("A logged exception"));


IOS SDK Integration

The document details steps required to integrate Morengage SDK into your application for iOS devices.

Getting Started

Before you can begin working with PushBox SDK on iOS, you need to download the PushBox SDK for iOS and ensure that you have an APP key.

Step1 : Get the latest version of Xcode

To build a project using PushBox SDK for iOS, you need Xcode version 8.3.2 or later

Step2: Obtain the APP Key

Register with https://app.morengage.com to obtain your APP Key. If you have been provided with an APP key, you can use that instead. Please write to support for any help. The iOS Framework is available for download at https://app.morengage.com/P5-IOS-sdk.zip

Step 3: Download “PushBoxSDK.framework”

  • Unpack the source files.
  • Launch Xcode and either open an existing project, or create a new project. If you're new to iOS, create a Single View Application, and disable Use Storyboards and enable Use Automatic Reference Counting.
  • Drag and drop the “PushBoxSDK.framework” in to your xcode project, When prompted, ensure Copy items into destination group's folder is selected.
  • Now Select the project file.
  • Add PushBoxSDK.framework under Embedded Binaries.
  • Select your project from the Project Navigator, and choose your Deployment target
  • Open the Build Phases tab, and within Link Binary with Libraries, add the following frameworks: PushBoxSDK.framework
  • Select Target, go to general and add PushBoxSDK.framework into embedded binaries

Step 4:

Your project shall have podfile, if you don’t have go to the following url to setup the pod project

If you don't already have the CocoaPods tool, install it on macOS by running the following command from the terminal. For details, see the : www.guides.cocoapods.org/using/getting-started.html

Execute the following command on the terminal in project directory


cd  Project Directory and hit enter.
Pod  init
Now go to the project folder.
Find the pod file under the created project
Add the following lines into your podfile above of target ‘Your project Name’ do
pod 'Alamofire', '~> 4.2.0'
pod 'ReachabilitySwift'
pod 'SugarRecord/CoreData'
pod 'SugarRecord/CoreData+iCloud'
Save the pod file.
Open a terminal and go to the directory containing the pod file cd < Project Path >


Execute the “Pod install” command. This will install the APIs specified in the podfile, along with any dependencies they may have $ pod install

Step 5:

Add the following lines in your info.plist file


 NSLocationAlwaysUsageDescription
 App needs Location
 NSLocationWhenInUseUsageDescription
 NSLocationAlwaysUsageDescription
Privacy - Location always usage description    String    App needs Location
Privacy - Location When in Use Usage Description    String    App needs Location


It will prompt the user requesting permission to access current location.

Step 6:

Add the PushBox SDK in your project

1. Add the following lines in to your appdelegate file


“didFinishLaunchingWithOptions” method
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?)-> 
Bool { let appKey = "p5m1a2i3sdk3610"
let version = "1.00"
P5SDKManager.initP5SDK(key: appKey, version: version) return true }



Declaration public class func initP5SDK(key: String, version: String)
Description This method will kick start the PushBox SDK Manager analytics session
@param key, version
@return void
Parameters Key      String value
version      String value
Declared in P5SDKManager.swift


2. It is required to pass the following user information to uniquely identify the user. The user information is tagged against the device id, enabling real time analytics and engagement. P5SDKManager.registerUser(name: "name", email: "userid@gmail.com", phoneNumber: "987654321", extraParam: "extra")


Declaration public class func registerUser(name: String, email: String, phoneNumber: String, extraParam: String)
Description User registration, this method will push user information along with the device id
@param name,email,phoneNumber,extraParam
@return void
Parameters name String value
email String value with valid email
phoneNumber String value with valid phoneNumber
extraParam String value
Declared in P5SDKManager.swift