License API - Create License - All Parameters

Overview
This option to create a license is more advanced. Rather than using a product in Maian Guardian, you pass ALL parameters manually. Note that all parameters have the same restriction as for creating a license in your admin control panel. For example, constant keys must be alphanumeric etc

Invalid data will result in the command line tool failing. This has the following options:

apiKey = API Key as defined in your settings (Validates genuine post)
timezone = Optional timezone as supported by PHP. A different timezone may be useful for time based restrictions. If not set, defaults to settings timezone.
license = License options. See below.
restrictions = Full encoder string and other server options. See below.
text = Custom text information. Optional. See below.
constants = License constants. Key / value pairs. Optional. See below.
Example
Data must be sent in JSON format as a HTTP POST. The following example shows how to use this option. NOTE that you MUST append the 'remote=yes' query string to the guardian url?

<?php
$data = array(
  'apiKey' => 'AO2CN4UJGW3PR08YIVKB',
  'timezone' => '',
  'license' => array(
    'prodkey' => 'key34567',
    'prodid' => 'id34567'
    'expire_in' => '2',
    'expire_on' => '',
    'timeservers' => 'pool.ntp.org' (Optional, comma delimit multiple)
  ),
  'restrictions' => array(
    'encpref' => '--domain example.com'
  ),
  'text' => array(
    'block 1',
    'block 2'
  ),
  'constants' => array(
    array(
      'key' => 'keyone',
      'value' => 'value one'
    ),
    array(
      'key' => 'keytwo',
      'value' => 'value two'
    )
  )
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/guardian/index.php?remote=yes');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
$r = curl_exec($ch);
curl_close($ch);

echo $r;
?>
More Detail
The license array contains 5 keys:

prodkey = Your unique product key. Required.
prodid = Your unique product ID. Required.
expire_in = Numeric value. Optional.
expire_on = Expiry date. US format, eg: 2018-04-13. Optional.

The restrictions array contains 2 keys:

encpref = Full Source Guardian server encoding preference. Can contain domain, IP and/or mac info. Required.

The text array contains multiple custom text lines if applicable. Optional.

The constants array is a multi-dimensional array containing arrays with 4 keys. Optional'. You can set as many as you need or leave it blank (see below). Each array must contain the following keys:

key = Alphanumeric constant key. Required.
value = Constant value. Required.

Any yes/no values omitted default to 'no'.

For more info, see the Source Guardian docs or the product add page info.
Minimal Example
Here, no custom text or constants are set.

<?php
$data = array(
  'apiKey' => 'AO2CN4UJGW3PR08YIVKB',
  'license' => array(
    'prodkey' => 'key34567',
    'prodid' => 'id34567'
  ),
  'restrictions' => array(
    'encpref' => '--domain example.com'
  ),
  'text' => array(),
  'constants' => array()
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/guardian/index.php?remote=yes');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
$r = curl_exec($ch);
curl_close($ch);

echo $r;
?>
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
License data...

or

HTTP/1.0 403 Forbidden
For JSON, the response will be a JSON array with a key called 'status' and a key called 'license' if successful. Status has one of two values, either 'OK' or 'ERR'. Example:

{
"status" : "OK"
"license" : "License data..."
}

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-lic-triggers.php

Jump to Creating License Using Existing Product