Standard API - Easy Setup

Overview
In it's simplest form, Maian Guardian expects only 5 POST fields. These are:

name = Users Name
email = Users Email
prodID = Product ID (Numeric value ONLY)
licAmount = Amount of licenses purchased (0 for unlimited, Numeric value ONLY)
apiKey = API Key as defined in your settings (Validates genuine post)

If any of these parameters are missing, the account creation for Maian Guardian fails. Any failures will be written to your "logs" folder for debugging. This will help determine issues.
Curl
Curl is used for these examples, but Maian Guardian will support any routine that can send a HTTP POST.
Generate Account at Maian Guardian
Lets say Joe Bloggs has just purchased 2 licenses of one of your products. The data would be sent as follows:

<?php

$fields = 'name=Joe Bloggs';
$fields .= '&email=joe@example.com';
$fields .= '&prodID=1';
$fields .= '&licAmount=2';
$fields .= '&apiKey=AO2CN4UJGW3PR08YIVKB';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://www.example.com/guardian/index.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_exec($ch);
curl_close($ch);

?>
Explanation in More Detail
Lets look at the following in more detail:

<?php

$fields = 'name=Joe Bloggs';
$fields .= '&email=joe@example.com';
$fields .= '&prodID=1';
$fields .= '&licAmount=2';
$fields .= '&apiKey=AO2CN4UJGW3PR08YIVKB';

?>
The following may seem more familiar and be better to understand:

<?php

$fields = 'name=Joe Bloggs&email=joe@example.com&prodID=1&licAmount=2&apiKey=AO2CN4UJGW3PR08YIVKB';

?>
Both are exactly the same. The .= simply means the data is concatenated (ie, joined together). This string is called a 'Query String' with key/value pairs separated by an ampersand (&). The keys (name,email etc) as detailed at the top of the page should NOT under any circumstances be renamed.

The API Key MUST match the key in your settings. This validates a genuine post. If the API Key does not match the system fails and an entry is logged.

The prodID value MUST be a valid ID from a product in your Maian Guardian installation. On the product page the ID is shown next to the product. If the product code does not match the system fails and an entry is logged.

In the curl part of the code, you must include the full url to your Maian Guardian index file and the concatenated string of values:

<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://www.example.com/guardian/index.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_exec($ch);
curl_close($ch);

?>
Obviously when sending the data, you would replace the users name/email with the dynamic values from your system. So, lets say you are using Paypal for your payments and you have verified a successful payment. Your license routine would possibly be:

<?php

$fields = 'name='.$_POST['first_name'].' '.$_POST['last_name'];
$fields .= '&email='.$_POST['payer_email'];
$fields .= '&prodID=1';
$fields .= '&licAmount=2';
$fields .= '&apiKey=AO2CN4UJGW3PR08YIVKB';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://www.example.com/guardian/index.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_exec($ch);
curl_close($ch);

?>
This should be at the very end of your payment routine. You could also use:

<?php

$fields = 'name='.$_POST['first_name'].' '.$_POST['last_name'].'&email='.$_POST['payer_email'].'&prodID=1&licAmount=2&apiKey=AO2CN4UJGW3PR08YIVKB';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://www.example.com/guardian/index.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_exec($ch);
curl_close($ch);

?>
Product ID and license amount would also be dynamic depending on your system.
Return Response - HTTP or JSON
If the API has accepted the request it will return a HTTP header (default) or JSON response, depending on your preference in the 'control/options.php' file. If a failure occurs check the API log entry in the 'logs' folder if enabled.

HTTP HEADER example:

HTTP/1.0 200 OK

or

HTTP/1.0 403 Forbidden
For JSON, the response will be a JSON array with a single key called 'status'. This will have one of two values, either 'OK' or 'ERR'. Example:

{
"status" : "OK"
}

or

{
"status" : "ERR"
}
SSL
If you are transmitting to a secure site, you may need other options in your curl code.
Log File
If you are having issues, check your log file for information. If nothing is in the log file, check your servers error log.
Additional Triggers
If you want to create other operations after the license creation has run, add your custom code to the following file:

control/api/api-triggers.php

Jump to Advanced Setup Options