License API - Create License - All Parameters

Overview
This option to create a license is more advanced. Rather than using a product in Maian Cube, 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, property keys must be alphanumeric etc

Invalid data will result in the command line tool failing. This option 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.
headers = Header block information. Optional. See below.
properties = License properties. 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 cube url?

<?php
$data = array(
  'apiKey' => 'AO2CN4UJGW3PR08YIVKB',
  'timezone' => '',
  'license' => array(
    'passphrase' => 'abc34567',
    'expire_in' => '2',
    'duration' => 'd',
    'expire_on' => '',
    'expose' => 'no'
  ),
  'restrictions' => array(
    'encoder_string' => '*.example.com,www.example.com,example.com@',
    'expose' => 'no'
  ),
  'headers' => array(
    'block 1',
    'block 2'
  ),
  'properties' => array(
    array(
      'key' => 'keyone',
      'value' => 'value one',
      'expose' => 'no',
      'enforce' => 'no'
    ),
    array(
      'key' => 'keytwo',
      'value' => 'value two',
      'expose' => 'yes',
      'enforce' => 'yes'
    )
  )
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/cube/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:

passphrase = Your unique passphrase. Required.
expire_in = Numeric value. Optional.
duration = If 'expire_in' is set, specify duration. s, m, h or D ONLY (seconds, minutes, hours or days). Optional.
expire_on = Expiry date. US format, eg: 2018-04-13. Optional.
expose = yes or no. Optional.

The restrictions array contains 2 keys:

encoder_string = Full ionCube encoder value. Can contain domain, IP and/or mac info. Required.
expose = yes or no. Optional.

The header array contains multiple header lines if applicable. Optional.

The properties 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 property key. Required.
value = Property value. Required.
expose = yes or no. Optional.
enforce = yes or no. Optional.

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

For more info, see the ioncube docs or the product add page info.
Minimal Example
Here, no header or property keys are set.

<?php
$data = array(
  'apiKey' => 'AO2CN4UJGW3PR08YIVKB',
  'restrictions' => array(
    'encoder_string' => '*.example.com,www.example.com,example.com@',
    'expose' => 'no'
  ),
  'headers' => array(),
  'properties' => array()
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/cube/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