Introduction

Hybrid apps are built using web-based languages (usually HTML and JavaScript) and packaged for mobile using a service such as PhoneGap. The Cloud App Licenser API lets you integrate a licensing and in-app credits system without having to use native code and, if you don't need to integrate any other proprietary systems (such as in-app payments), using our API has the added advantage that you don't need to maintain different code bases for every platform (e.g. Apple iOS, Android etc).

Accessing The API

Your apps can communicate with our API via asynchronous JavaScript (AJAX). Here's a simple example using jQuery.ajax() (Note that AJAX requests must be sent using the POST HTTP method, which can be specified as the value for the "type" option below:


	$.ajax(
	{
	url: "http://api.cloudapplicenser.com/v1/license_get",
	data: "token=54321&appuniqueid=12345&licensekey=&deviceid=2fa572bc96cd99g",
	dataType: "json",
	cache: "false",
	type: "POST"

		success: function(data)
		{

//DO SOMETHING IF REQUEST WAS SUCCESSFUL

		},

		error: function(jqXHR,exception)
		{

//ERROR HANDLER

		}
	});

Cordova "Whitelist" Plugin

You will need to set up your app with permission to access our API and this can be achieved by using the Cordova "whitelist" plugin in your app's config file:


<gap:plugin name="cordova-plugin-whitelist" source="npm"/>

You can then specify that your app has permission to access our API, also in your app's config file:


<access origin="http://cloudapplicenser.com" subdomains="true" />

AJAX Request Repitition

It is good practice to attempt each API request several times in case of intermittent connection problems. This can be achieved with JavaScript by using a simple counter. In the code below, jQuery.ajax() is used to perform the AJAX request, and the function housing the AJAX request is repeated several times if the AJAX request fails:


var attempts;

function DoStuff()
{
attempts = 0;
DoStuffAJAX();
}

function DoStuffAJAX()
{
attempts += 1;

	if(attempts < 4)
	{

//PERFORM AJAX REQUEST

		success: function(data)
		{

//DO SOMETHING IF REQUEST WAS SUCCESSFUL

		},

		error: function(jqXHR,exception)
		{
		DoStuffAJAX();
		}
	}
	else
	{

//IF MORE THAN FOUR ATTEMPTS HAVE BEEN MADE RETURN ERROR

	}