1. Go to this page and download the library: Download cis-bv/netbox-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cis-bv / netbox-client example snippets
use Cis\NetBox\NetBoxApi;
// direct passing
$netBoxApi = new NetBoxApi('https://demo.netbox.dev', '3d7d31797de934a99a527a620514130980937b4c');
// using the Environment-Variables (OS or set)
putenv(NETBOX_API_URL, 'https://demo.netbox.dev');
putenv(NETBOX_TOKEN, '3d7d31797de934a99a527a620514130980937b4c');
$netBoxApi = new NetBoxApi();
use Cis\NetBox\NetBoxApi;
$netBoxApi = new NetBoxApi();
// Getting all Console-Ports
$consolePorts = $netBoxApi->dcim()->consolePorts();
// Getting all Console-Ports for a specific device
$consolePorts = $netBoxApi->dcim()->consolePorts(['device_id' => 12]);
// Creating a new Console Port
$consolePorts = $netBoxApi->dcim()->consolePortsCreate([
'device' => 245,
'name' => 'con'
]);
use Cis\NetBox\NetBoxApi;
$netBoxApi = new NetBoxApi();
//Get a specific Interface:
$netBoxApi->dcim()->interfacesById(12);
//Delete a specific Console Port:
$netBoxApi->dcim()->consolePortsByIdDelete(234);
use Cis\NetBox\NetBoxApi;
use Cis\GqlBuilder\Query;
$netBoxApi = new NetBoxApi();
$query = Query::create('device_list', selectionSet: ['id', 'name']);
$allDevices = $netBoxApi->graphQl($query);
use Cis\NetBox\NetBoxApi;
$netBoxApi = new NetBoxApi();
$consolePorts = $netBoxApi->dcim()->consolePorts();
//Retrieve the status code of the request
$statusCode = $consolePorts->getStatusCode();
//Retrieve the plain Body
$body = $consolePorts->getBody();
//Retrieve the Result(s) always as array:
$results = $consolePorts->getResults();
//Use Result as Array
foreach ($consolePorts as $consolePort) {
echo $consolePort->id . PHP_EOL;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.