Craftnet API PHP Wrapper
A PHP library which implements the functionality of the Craftnet API. See the Craftnet API documentation for all available settings., (*1)
Installation
Add the library to your project via composer:, (*2)
``` php
{
"require": {
"barrelstrength/craftnet-php": "{version}"
}
}, (*3)
Require the library in your project:
``` php
require __DIR__ . '/vendor/autoload.php';
Authentication
To authenticate with Craftnet set your username
and apiKey
values when instantiating a new CraftnetClient
class., (*4)
``` php
use barrelstrength\craftnetphp\CraftnetClient;, (*5)
$username = 'USERNAME';
$apiKey = 'API_KEY;, (*6)
$client = new CraftnetClient($username, $apiKey);, (*7)
## Get all plugin licenses for the authenticated Craft ID user
``` php
$response = $client->pluginLicenses->get();
$pluginLicenses = $response->getBody()->getContents();
$results = json_decode($pluginLicenses);
Get a secondary page of plugin licenses for the authenticated Craft ID user
``` php
$response = $client->pluginLicenses->get([
'page' => 2
]);, (*8)
$pluginLicenses = $response->getBody()->getContents();, (*9)
$results = json_decode($pluginLicenses);, (*10)
## Get a specific plugin license for the authenticated Craft ID user
``` php
<?php
$response = $client->pluginLicenses->get([
'key' => 'P8GQRVQO5MK9Q673U0IJZ2I3'
]);
$pluginLicense = $response->getBody()->getContents();
$result = json_decode($pluginLicense)
Create a new license for a given Craft ID user
``` php
$response = $client->pluginLicenses->create([
'edition' => 'standard',
'plugin' => 'sprout-forms',
'email' => 'sprout@barrelstrengthdesign.com'
]);, (*11)
$pluginLicense = $response->getBody()->getContents();, (*12)
$result = json_decode($pluginLicense)
```, (*13)